-
Notifications
You must be signed in to change notification settings - Fork 194
Home
There are two parts to localizing a new repository, extracting the source strings to be translated and syncing them with transifex, and pulling translations from transifex to be incorporated into the component.
Strings in the source are localized by using the FormattedMessage
jsx component or calling formatMessage
, and they can also be defined with defineMessages
.
Note that these instructions are often followed after following those at https://github.com/LLK/scratch-gui/wiki/Localization-notes .
This can only be run by someone with developer credentials on Transifex.
For the time being, we are not pulling everything that scratch-l10n is configured to request -- we just want the editor project's translations.
Sync editor translations (with -f
to force update)
> tx pull -r 'scratch-editor.*' -f
If there are new languages, pull those resources:
> tx pull -r 'scratch-editor.*' -l <locale>
You will need to run the command above for each new language being added.
For the most part Scratch avoids having languages with locales. If you do add a language with locale you will need to edit the .tx/config
file. In Transifex locale codes are of the form lang_LOC
, for example pt_BR
. Browsers expect the locale codes to be of the form lang-loc
, with a dash instead of underscore. In the tx/config file there is a mapping from the transifex code to the one that we want for the browser. Currently the line looks like:
lang_map = zh_CN:zh-cn, zh_TW:zh-tw, pt_BR:pt-br, es_419:es-419, aa_DJ:aa-dj
If you add a new language with locale, add it to this line to define the new filename.
Confirm language addition by examining the contents of editor/<blocks, or another project>/<locale>.json
.
When a language reaches 100% translated, it can be added to the menu.
- Edit
src/supported-locales.js
, to add a line to thelocales
const.
Note: always use the name of the language **as written in the language itself, using the language's most common scrip**. Example: Amharic is written 'አማርኛ'. We may need to contact the translators for this; Wikipedia is also useful. (If it's a language that has been translated on www, the name should be in the wwwLocales
object already.)Omniglot language names is also helpful._
- Edit
src/index.js
, to add - an 'import' line, and
- an entry in the
localeData
array
Note: check that the react-intl library includes your locale. If it doesn't define a new custom locale, using a locale that is in react-intl as the parent locale. Include the parent locale in the localeData array if it isn't already there.
Test that the updated translations have no issues with json formatting by running npm test
.
Use git to commit these changes and push them to your fork on a branch named something like translations-<readable date>
, such as translations-sep-18-2018
.
Then create a pull request and request review. Note that the PR should be set to merge to the master
branch.
When the PR looks good, merge it. Greenkeeper will automatically initiate updates to the packages that depend on scratch-l10n
.
Assuming that source strings have been extracted and sync'd to Transifex, here are the steps to add a new translation 'resource' -- a category of translations for a particular project.
- Add the new resource to
.tx/config
- for example, adding the pen extension strings:
[experimental-scratch.pen]
file_filter = pen/<lang>.json
source_file = pen/en.json
source_lang = en
type = CHROME
- Run
tx pull -a -s
to pull down all translations and the source file. [Note: this will also update other resources that have new translations. If you only want to update the new resource add-r 'experimental-scratch.pen'
(i.e. the resource slug) to the command] - Add the new component to the list of components in
build-data.js
The script assumes that the name of the component is the name of the folder that contains the translations.