decred.org/dcrdex@v1.0.5/docs/wiki/Localization-and-Translation.md (about)

     1  # Localization and Translation
     2  
     3  Bison Wallet supports translations for the browser frontend and the notification messages from the backend.
     4  
     5  To add a new locale, the translations must be defined in the following locations:
     6  
     7  1. HTML strings (client/webserver/locales)
     8  2. Notification strings (client/core/locale_ntfn.go)
     9  3. JavaScript strings (client/webserver/site/src/js/locales.ts)
    10  
    11  If you decide to do the following for a different language, please see the [Contribution Guide](https://github.com/decred/dcrdex/wiki/Contribution-Guide) for help with the github workflow.
    12  
    13  ## Step 1 - HTML
    14  
    15  To create or update the HTML translations, create or modify the appropriate dictionary
    16  in the `client/webserver/locales` directory. These dictionaries map HTML template
    17  keys to translations. New or modified entries should use the translation in the English
    18  dictionary (`var EnUS` in the file `en-us.go`) as the source text. The goal is to duplicate
    19  entries for all keys in the English dictionary.
    20  
    21  When creating a dictionary for a new language, use the BCP 47 language tag to construct
    22  the file's name. Then new language's HTML strings map must then be listed in [client/webserver/locales/locales.go](https://github.com/decred/dcrdex/blob/master/client/webserver/locales/locales.go) with an appropriate language tag.
    23  
    24  ## Step 2 - Notifications
    25  
    26  To update the notification translations, add or modify the translation in the appropriate locale dictionary map (e.g `originLocale`, `ptBR`, etc) in the [`client/core/locale_ntfn.go`](https://github.com/decred/dcrdex/blob/master/client/core/locale_ntfn.go) file. These dictionaries maps notification keys to translations. New or modified entries should use the translation in the English dictionary (`var originLocale map[Topic]*translation` in the file `locale_ntfn.go`) as the source text. The goal is to duplicate entries for all keys in the English dictionary.
    27  
    28  When creating a dictionary for a new language, use the BCP 47 language tag to construct the map name and it's translations should correspond to the English strings in the `originLocale` map in the same file.
    29  
    30  Note how in **client/core/locale_ntfn.go** there are "printf" specifiers like `%s` and `%d`.  These define the formatting for various runtime data, such as integer numbers, identifier strings, etc.  Because sentence structure varies between languages the order of those specifiers can be explicitly defined like `%[3]s` (the third argument given to printf in the code) instead of relying on the position of those specifiers in the formatting string.  This is necessary because the code that executes the printing always provides the values in a particular order, which may not be the same order in a translated string.
    31  
    32  Once the translations are added to **client/core/locale_ntfn.go**, the new map is listed in the `var locales map[string]map[Topic]*translation` at the bottom of the same file.
    33  
    34  ## Step 3 - JavaScript
    35  
    36  To update the JavaScript strings translation in [client/webserver/site/src/js/locales.ts](https://github.com/decred/dcrdex/blob/master/client/webserver/site/src/js/locales.ts), add or modify the translation in the appropriate language object.
    37  
    38  When creating a dictionary for a new language, create the language dictionary object (e.g `export const ar: Locale = { ... }`) then add strings translation corresponding to the English text in the `enUS` object at the top of the same file.  Finally, the new object should be listed in the `const localesMap` at the end of the file.
    39  
    40  When testing, remember to rebuild the site assets bundle with `npm ci && npm run build` and bump the cache with `./bust_caches.sh` in the **client/webserver/site** folder.