Internationationalization (I18n)

Internationalization allows you to define language mappings in separate js files.

To enable i18n, put an i18n folder in your package path and add a javascript file named for each language code (e.g. en.js for english).

Here's an example of defining a language mapping:

// en.js
module.exports = {
  'search': 'Search',
  'edit': 'Edit',

// zh.js
module.exports = {
  'search': '搜索',
  'edit': '编辑',

The file will be register to i18n table by the key of your package-name.

Translating your text

In javascript code, you can translate a text by Editor.T:

// NOTE: my package name is "foobar"

You can also perform language mappings in your panel template:

// NOTE: my package name is "foobar"
  template: `
    <div class="btn">${Editor.T('foobar.edit')}</div>

Used in Menu Path

You can use i18n in package.json when register menu path, just use the format i18n:${key}. We can write: i18n:MAIN_MENU.package.title/foobar/i18n:foobar.edit, Cocos Creator will help use replace the i18n text.