0

I'm using easy_localization in my app. I have changed the language setting from English to Chinese, but app still displays English.

This is my project directory:

enter image description here

main.dart

 runApp(EasyLocalization(
      supportedLocales: const [Locale('en', 'US'), Locale('zh-CN', 'CN')],
      path: 'assets/translations',
      child: const App(),
    )

zh-CN.json

"hello": "你好",

widget.dart

Text('hello'.tr());

Is it because the languageCode and countryCode wrong?

Hoo
  • 1,806
  • 7
  • 33
  • 66

2 Answers2

0
Create folder and add translation files like this

assets
└── translations
    ├── {languageCode}.{ext}                  //only language code
    └── {languageCode}-{countryCode}.{ext}    //or full locale code

Example:

assets
└── translations
    ├── en.json
    └── en-US.json 

Declare your assets localization directory in pubspec.yaml:

flutter:
  assets:
    - assets/translations/
Javatar
  • 131
  • 6
0

From the documentation of Locale(this._languageCode, [this._countryCode,]), the value 'zh-CN' is not supported for the parameter _languageCode.

The subtag values are case sensitive and must be one of the valid subtags according to CLDR supplemental data:
language,
region.

########## Solution #########
Try replacing:-

supportedLocales: const [Locale('en', 'US'), Locale('zh-CN', 'CN')],

with

supportedLocales: [Locale('en', 'US'), Locale('zh', 'CN')],

If this is not meeting your requirements, you can consider looking for an alternate language code which is supported from this link : language

Hope this solves your problem.

Rohit Singla
  • 112
  • 2
  • 9