Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 1.55 KB

i18n.md

File metadata and controls

52 lines (35 loc) · 1.55 KB

Internationalization

The web3 front-end is set-up for internationalization allowing us to translate the app into any number of languages.

Development

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.

Example

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) ] ]

Translation script

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 your strings.en.json file and automatically translate and rebuild Translations.elm for you..