csv_localizations 0.1.0 csv_localizations: ^0.1.0 copied to clipboard
Localize your app using a single CSV file for all languages.
csv_localizations #
Localize your app using a CSV file for all translations.
Usage #
See example
Install #
Add package to your pubspec.yaml
dependencies:
csv_localizations:
Add CSV asset #
Add a CSV translation file as an asset and describe it in your pubspec.yaml
Tip: Create a Spreadsheet via Google docs, then export as CSV
flutter:
assets:
- assets/lang.csv
CSV example file
default, en, nb
Hi, Hi, Hei
Cheese, Cheese, Ost
Top row show supported language codes; rows below show translations
In code #
Add CsvLocalizationsDelegate
to MaterialApp
and set supportedLocales
localizationsDelegates:[
... // global delegates
CsvLocalizationsDelegate(
CsvLocalizations(
assetPath: 'assets/lang.csv',
supportedLanguageCodes: ['en', 'nb'],
),
),
]
supportedLocales: [Locale('en'), Locale('nb')],
API #
Now translate strings using
CsvLocalizations.of(context).tr('Hi')
or use the simpler String extension method
'Hi'.tr(context)
Note on iOS #
Add supported locales to
ios/Runner/Info.plist
as described here.
Example:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb</string>
</array>