The web3 front-end is set-up for internationalization allowing us to translate the app into any number of languages.
The primary change for developers is that you will need to add any strings which may be presented to a user as keys in src/strings/strings.en.json
. Then, you can reference that given string in your code as such:
-- In imports
import Strings.Translations as Translations
-- In your code
Translations.string_key userLanguage
userLanguage
is a variable exposed from the top-level model and should be threaded through to your view function.
For example, consider the following code:
myViewFunc : Html Msg
myViewFunc =
[ div [ class "col-xs-5" ] [ label [] [ text "Asset" ] ]
This should become:
src/strings/string.en.json
{
// ...
"asset": "Asset"
}
Then:
myViewFunc : Translations.Lang -> Html Msg
myViewFunc userLanguage =
[ div [ class "col-xs-5" ] [ label [] [ text (Translations.asset userLanguage) ] ]
A translation script is used to generate the require Elm Strings.Translations module. The translate script currently allows you to specify additional strings in the strings.en.json
file and default english to the other supported languages so that you or other members of community can provide an appropriate translation for the desired language.
yarn watch-i18n
- Use this while you are developing. It will watch yourstrings.en.json
file and automatically translate and rebuildTranslations.elm
for you..