icapps_translations 7.0.0 icapps_translations: ^7.0.0 copied to clipboard
Dart tool to generate flutter translations code from the icapps translations tool
flutter icapps translations #
A dart package to automaticly download translations from the icapps translation tool. The rest of the implementation is done by locale_gen https://pub.dev/packages/locale_gen
Example #
Setup #
Add dependency to pubspec #
dev-dependencies:
icapps_translations: <latest-version>
Add config to pubspec #
Add your locale folder to the assets to make use all your translations are loaded.
flutter:
assets:
- assets/locale/
Add the icapps_translations config to fetch the latest translations
icapps_translations:
api_key: 'enter-your-api-key' #For the new translations tool, this is the bearer token
project_id: 'optional project id' #To use the new translations tool, enter the project id here
default_language: 'nl'
languages: ['en', 'nl']
locale_assets_path: 'assets/locale/' #This is the location where your json files should be saved.
assets_path: 'assets/locale/' #This is the location where your json files are located in your flutter app.
nullsafety: true #Generate nullsafety compatible code. Defaults to false
alternatively set an env variable for your api_key and/or project_id
API_KEY_ICAPPS_TRANSLATIONS
PROJECT_ID_ICAPPS_TRANSLATIONS
Run package with Flutter #
flutter packages pub run icapps_translations
Run package with Dart #
pub run icapps_translations
Migration steps <7.0.0 to >=7.0.0 #
With the newest version of locale_gen the context no longer needs to be provided when accessing the translations. This means there are a couple of breaking changes.
The first one is that you can now directly get the translation from the Localization object without having to pass the context, so instead of:
Localization.of(context).translation;
you can now do
Localization.translation;
The second breaking change is how you initialize/change the locale. Before you could do this by changing the localizationDelegate that is passed to the materialApp, but now you just call the load function of the Localization object. So instead of:
localeDelegate = LocalizationDelegate(
newLocale: locale,
localizationOverrides: customLocalizationOverrides,
);
you now do:
await Localization.load(
locale: locale,
localizationOverrides: customLocalizationOverrides,
);
Arguments #
Arguments are supported as of 0.1.3
You can pass a String or a num to as an argument.
Formatting for String: %1$s Formatting for num: %1$d
The number in between % and $ indicate the index of the argument. It is possible to place an argument in 1 language first but in another second:
ex (Grammatically incorrect but it makes my point):
nl '%1$s, ik woon in %2$s. Wist je dat niet?' => KOEN, ik woon in ANTWERPEN. Wist je dat niet?
fr 'I live in %2$s. You didn't knew that %1$s?" => I live in ANTWERP. You didn't knew that KOEN?
Working on mac? #
add this to you .bash_profile
fluttertranslations(){
flutter packages get && flutter packages pub run icapps_translations
}
now you can use the icapps translations with a single command.
fluttertranslations
Example #
This repo contains an example how to use this package.
Packages used:
- flutter_localizations
- shared_preferences
- provider
- kiwi
- icapps_translations