localize_and_translate
Flutter Localization In Human Way, Help with localizing your app.
Tutorial
Video
Methods
Method | Job |
---|---|
init() |
initialize things, before runApp() |
translate('word') |
word translation |
translate('word',{"key":"value"}) |
word translation with replacement arguments |
<!-- | googleTranslate('word', from: 'en', to: 'ar') |
setNewLanguage(context,newLanguage:'en',restart: true, remember: true,) |
change language |
isDirectionRTL() |
is Direction RTL check |
currentLanguage |
Active language code |
locale |
Active Locale |
locals() |
Locales list |
delegates |
Localization Delegates |
Installation
- add
.json
translation files as assets
- For example :
'assets/langs/ar.json'
|'assets/langs/en.json'
- structure should look like
- define them as assets in pubspec.yaml
Initialization
- Add imports to main.dart
- Make
main()
async
and do the following - Ensure flutter activated
WidgetsFlutterBinding.ensureInitialized()
- Define languages list
LIST_OF_LANGS
- Define assets directory
LANGS_DIR
- Initialize
await translator.init();
- Inside
runApp()
wrap entry class withLocalizedApp()
- Note : ** make sure you define it's child into different place "NOT INSIDE" **
LocalizedApp()
child example ->MaterialApp()
Usage
- use
translate("appTitle")
- use
googleTranslate("test", from: 'en', to: 'ar')
- use `setNewLanguage(context, newLanguage: 'ar', remember: true, restart: true);