Text
The default language is English. And you can change it into different language or change it into your own texts.
Changing the texts
You can change it inside your app.
For instance, simply set the text code as following.
TextService.instance.texts['name'] = '이름';
TextService.instance.texts[Code.profileUpdate] = '프로필 수정';
To know the whole list of text code, you may open lib/src/text/text.service.dart
.
You may add your own text code and text for your app. So, you don't have to maintain another multi-lingual logic.
For instance, define your own text code for your app like below
TextService.instance.texts['appName'] = 'My App';
And use it when you need,
Text('appName').tr
If the key is not defined in texts
variable inside text.service.dart
, then it will be shown as it is.
Pre-defined texts
Some texts are predefined in src/text/texts.dart
and you can use it like below.
Text(T.setting.tr)
Note that, T.setting
is not defined in texts
. So it is used as it is.
Multilingual Support
You can display translated strings (sentences) on the screen based on the device's default language.
Here's how to set up translated strings.
Locale locale = Localizations.localeOf(context);
TextService.instance.texts = {
...TextService.instance.texts,
if (locale.languageCode == 'ko') ...{
T.save: '저장',
T.login: '로그인',
'phoneSignIn': '전화번호로 로그인',
},
if (locale.languageCode == 'en') ...{
T.save: 'Save',
T.saved: 'Saved',
'phoneSignIn': 'Sign in with phone',
},
if (locale.languageCode == 'vi') ...{
T.save: 'Lưu',
'phoneSignIn': 'Đăng nhập bằng số điện thoại',
},
if (locale.languageCode == 'th') ...{
T.save: 'บันทึก',
},
if (locale.languageCode == 'lo') ...{
T.save: 'ບັນທຶກ',
},
if (locale.languageCode == 'my') ...{
T.save: 'သိမ်းဆည်း',
}
};
Usage
'phoneSignIn'.tr