-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix useTranslate types, react warnings, core observer edge case …
…error
- Loading branch information
Showing
12 changed files
with
100 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { TranslationParamsTags } from '@tolgee/core'; | ||
import { TranslationParams } from '@tolgee/core'; | ||
import React from 'react'; | ||
|
||
export type ParamsTags = { | ||
[key: string]: | ||
| TranslationParamsTags<React.ReactNode>['a'] | ||
| TranslationParams['a'] | ||
| ((value: any) => JSX.Element | React.ReactElement | null) | ||
| React.ReactElement; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,30 @@ | ||
import { defineComponent, PropType } from 'vue'; | ||
import { Subscription } from '@tolgee/core/lib/services/Subscription'; | ||
import { TolgeeContext } from './types'; | ||
import { useTranslate } from './useTranslate'; | ||
import { TranslateFnProps } from '.'; | ||
|
||
export const T = defineComponent({ | ||
name: 'T', | ||
props: { | ||
keyName: { type: String, required: true }, | ||
parameters: Object as PropType<{ [key: string]: string }>, | ||
defaultValue: String as PropType<string>, | ||
/** @deprecated */ | ||
strategy: { | ||
type: String as PropType<'ELEMENT_WRAP' | 'NO_WRAP'>, | ||
default: 'ELEMENT_WRAP', | ||
}, | ||
noWrap: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
inject: ['tolgeeContext'], | ||
data() { | ||
const tolgeeContext = this.tolgeeContext as unknown as TolgeeContext; | ||
if (!tolgeeContext) { | ||
throw new Error('T component used outside of TolgeeProvider'); | ||
} | ||
return { | ||
translation: | ||
(this.$props.keyName && | ||
tolgeeContext.tolgee.instant({ | ||
key: this.$props.keyName || '', | ||
noWrap: this.$props.noWrap, | ||
params: this.$props.parameters, | ||
orEmpty: true, | ||
})) || | ||
('' as string), | ||
translationSubscription: null as Subscription | null, | ||
langSubscription: null as Subscription | null, | ||
}; | ||
}, | ||
methods: { | ||
translate() { | ||
const tolgeeContext = this.tolgeeContext as TolgeeContext; | ||
|
||
tolgeeContext.tolgee | ||
.translate({ | ||
key: this.$props.keyName || '', | ||
noWrap: this.$props.noWrap, | ||
params: this.$props.parameters, | ||
defaultValue: this.$props.defaultValue, | ||
}) | ||
.then((t) => { | ||
this.$data.translation = t; | ||
}); | ||
}, | ||
unsubscribe() { | ||
this.$data.translationSubscription?.unsubscribe(); | ||
this.$data.langSubscription?.unsubscribe(); | ||
}, | ||
subscribe() { | ||
const tolgeeContext = this.tolgeeContext as TolgeeContext; | ||
|
||
this.translate(); | ||
|
||
this.$data.translationSubscription = | ||
tolgeeContext.tolgee.onTranslationChange.subscribe(this.translate); | ||
|
||
this.$data.langSubscription = tolgeeContext.tolgee.onLangChange.subscribe( | ||
this.translate | ||
); | ||
}, | ||
}, | ||
created() { | ||
this.subscribe(); | ||
}, | ||
beforeUpdate() { | ||
this.unsubscribe(); | ||
this.subscribe(); | ||
}, | ||
beforeUnmount() { | ||
this.unsubscribe(); | ||
setup() { | ||
const t = useTranslate(); | ||
return { t }; | ||
}, | ||
render() { | ||
const content = this.$data.translation; | ||
const params: TranslateFnProps = { | ||
key: this.$props.keyName, | ||
parameters: this.$props.parameters, | ||
defaultValue: this.$props.defaultValue, | ||
noWrap: this.noWrap, | ||
}; | ||
const content = this.t(params); | ||
return content; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.