0 purchases
translations loader
Simple library for loading translations from assets folder. Library should be used with GetX or some similar framework
as it just loads files as Map<String, String>.
Two file formats of translation files are supported:
json
properties
Features #
simplified internationalization
supported json and properties files
all keys from json file are converted as object1.object2.value so that they are the same as in properties file
Getting started #
You need to configure assets folder with your translation files. For instance:
flutter:
uses-material-design: true
assets:
- assets/i18n/
copied to clipboard
Inside that folder you need to put all your translation files. Library does NOT use countryCode of the Locale, just languageCode.
For example:
en.json
{
"app": {
"name": "Test application",
"version": "1",
"bar": {
"title": "My title"
}
}
}
copied to clipboard
hr.properties
app.name=Testna aplikacija
app.version=1
app.bar.title=Moj naslov
copied to clipboard
And that is it, you just need to configure library inside main application and you'll have all your translations.
NOTE: You need to include flutter_localization in your pubspec:
#....
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.3
#....
copied to clipboard
Usage #
To get translations, you just need to use static method loadTranslations inside TranslationsLoader class. For instance: TranslationsLoader.loadTranslations("assets/i18n").
To use this library with GetX library, you need to implement Translations class:
class ApplicationTranslations extends Translations {
final Map<String, Map<String, String>> _translationKeys;
ApplicationTranslations(this._translationKeys);
@override
Map<String, Map<String, String>> get keys => _translationKeys;
}
copied to clipboard
Then you can use it when setting your GetMaterialApp:
Future<void> main() async {
// ...
runApp(GetMaterialApp(
translations: ApplicationTranslations(await TranslationsLoader.loadTranslations("assets/i18n")),
locale: Get.deviceLocale,
fallbackLocale: defaultLocale,
supportedLocales: supportedLocales,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
// .....
));
}
copied to clipboard
Additional information #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.