EggJS provides the feature of i8n at project level. EggBornJS extends the feature provided by EggJS, realizing the i18n at the module level

  1. Module can specify its own i18n
  2. The i18n at project level can override the one at module level

Definition of Language Resources

The default language for CabloyJS is en-us. If support Chinese, you need to add zh-cn resource file


  1. 1module.exports = {
  2. 2 'Hello World': '世界,您好',
  3. 3};

Usage of Language Resources

Get language resources of the current locale

EggBornJS uses the method ctx.text to dynamically get the specified language resources according to the locale configuration of the client


  1. 1async echo3() {
  2. 2 const message = this.ctx.text('Hello World');
  3. 3 this.ctx.success(message);
  4. 4}

How to change the locale configuration of the client?

  • Open the home page, entry Mine->Info,update the field of Locale, and save, then refresh the page

Get language resources of the specified locale

  1. 1
  2. 2async echo3() {
  3. 3 const message = this.ctx.text.locale('zh-cn', 'Hello World');
  4. 4 this.ctx.success(message);
  5. 5}

Override Language Resources

Use project level language resources to override module level language resources, thereby changing 世界,您好 to 您好,世界


  1. 1module.exports = {
  2. 2 'Hello World': '您好,世界',
  3. 3};