Created
June 15, 2020 17:35
-
-
Save hediet/7df4e2a8842538234bac604e2a85adc4 to your computer and use it in GitHub Desktop.
Dynamic Translation
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
/** | |
* Renders a translation that cannot be extracted statically. | |
* Avoid using this component as much as possible! | |
*/ | |
export class TransMsgDynamic extends React.Component<{ | |
keyAndDefaultTranslation: string; | |
/** | |
* A static id that represents the pool of all possible keys. | |
* If this id is not used in the code base anymore, | |
* all keys associated with this id can be removed. | |
*/ | |
keyPoolId: string; | |
data?: I18nData; | |
}> { | |
render() { | |
const { keyAndDefaultTranslation, data } = this.props; | |
const doc = parseGemlMarkupString(keyAndDefaultTranslation); | |
return <>{evaluateGemlMarkupStringToReact(doc, data || {})}</>; | |
} | |
} | |
/** | |
* Translates text that cannot be extracted statically. | |
* Avoid using this component as much as possible! | |
*/ | |
export function transStrDynamic( | |
keyAndDefaultTranslation: string, | |
options: { | |
/** | |
* A static id that represents the pool of all possible keys. | |
* If this id is not used in the code base anymore, | |
* all keys associated with this id can be removed. | |
*/ | |
keyPoolId: string; | |
data?: I18nData; | |
} | |
): string { | |
const doc = parseGemlMarkupString(keyAndDefaultTranslation); | |
return evaluateGemlMarkupStringToString(doc, options.data || {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment