How does language mapping work?

Locales in web extensions for Firefox can be specified using only a language code, like fr or en , or they may be further qualified with a region code, like en_US or en_GB , which describes a regional variant of the same basic language.

In my web extension, I use 2 letters for the language code except for Chinese where I use zh_cn for simplified Chinese and zh_tw for traditional Chinese.

My source file is located in /_locales/en/messages.json and all the translations are located in /_locales/%two_letters_code%/messages.json except for the 2 Chinese variants.

Unfortunately, the previous translation path will only result in having 1 Chinese variant saved in /_locales/zh/messages.json.

I’ve tried playing with language mapping, but the documentation isn’t clear in explaining how to use it and I haven’t been able to address this use case.

Hi there,

Looks like we have already managed to resolve this case in your direct ticket to support@crowdin.com. Just in case, the solution is the following, probably it will be useful for other users:

For your case, language mapping can be set up on the Project Settings > Languages > Add custom language code as follows:

  • Chinese Simplified - two-letters-code - zh_cn
  • Chinese Traditional - two-letters-code -zh_tw

See screenshot below:

Here is also the guide on the matter: Language Settings | Crowdin Docs

Your web extension currently faces an issue with how Firefox handles Chinese language translations. Firefox’s default behavior lumps both Simplified and Traditional Chinese translations into a single file, typically located at /locales/zh/messages.json. This becomes problematic when you need to manage distinct translations for Simplified Chinese (zh_cn) and Traditional Chinese (zh_tw). To resolve this, you need to structure your extension to handle these variants separately. This involves creating dedicated folders named /locales/zh_cn/ for Simplified Chinese and /locales/zh_tw/ for Traditional Chinese, with their respective messages.json translation files inside. Furthermore, you might need to adjust your extension’s manifest file to explicitly define the language mappings for zh_cn and zh_tw. This ensures that Firefox correctly loads and saves the appropriate translations for each Chinese variant, keeping them distinct and preventing conflicts.

Hi @mathewjacob

When using the two_letters_code the system will utilize the same language code for both Chinese variants - zh. So we advise either changing the path with the locale code to export Chinese into two separate folders or set up the language mapping for the two_letters_code as my colleague already advised above
It is a one-time language configuration and letter codes will be picked up automatically. This how it currently works with Chinese Simplified and Chinese Traditional, hope for your understanding