-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
core-featureEssential core functionality that's still missingEssential core functionality that's still missingpublic-apiThis issue shapes the public API of the libraryThis issue shapes the public API of the library
Description
Design proposal
All translations will be done through a translation function, which will receive a string key and optional placeholder values, and return formatted translation:
type TranslationFunc = (key: string, params?: {[name: string]: any}) => stringSince retrieval of translated texts is widely used, it should be as laconic as possible.
Consumption
There will be three ways to obtain the translation function:
-
Pure components connected through
connectWithShellwill get it in props, under the namet:const { t } = props return <span>{t('LangMenu_Manager_Panel_Title')}</span>
-
Directly from the
Shellobject:shell.translate('LangMenu_Manager_Panel_Title')
-
Through
ShellContext(useful in a non-connected component):<ShellContext.Consumer>{shell => <span>{shell.translate('LangMenu_Manager_Panel_Title')}</span> }</ShellContext.Consumer>
Injection
Assumptions
- single locale per page
- locale cannot be changed without reloading the page
Proposal
Translation data will be scoped per Shell (which means per Entry Point)
- Every entry point will be able to contribute a different translation data
- This allows slicing of translation data per team
If translation data is of default structure (defined below), default translation function can be used. For data of custom structure, custom translation function must be used.
- For default structure, an Entry Point has to contribute translation data:
shell.getAPI(AppHostAPI).contributeTranslations(myTranslationData)
- For custom structure, an Entry Point has to setup a custom translation function:
In the latter case translation data is not passed:
shell.getAPI(AppHostAPI).useTranslationFunction(myTranslationFunc)
myTranslationFuncmust be bound to its data
Default structure of translation data
{
"first_key": "translation 1",
"second_key": "translation with named {param-name} parameters",
"third_key": "translation with indexed {0} parameters {1}"
}Metadata
Metadata
Assignees
Labels
core-featureEssential core functionality that's still missingEssential core functionality that's still missingpublic-apiThis issue shapes the public API of the libraryThis issue shapes the public API of the library