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:
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?
2
Answers
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.