csv_localizations 0.0.1 csv_localizations: ^0.0.1 copied to clipboard
Localize your app using a single CSV file for all languages.
csv_localizations #
Localize your app using a single CSV file for all translations.
A minimal implementation based on LocalizationsDelegate
.
Install #
Add package to your pubspec.yaml
:
dependencies:
csv_localizations:
Usage #
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
The translation file's top row describes language codes, like: en, nb.
The rows below represent words in various languages.
CSV translation example:
str, en, nb
Hi, Hi, Hei
Cheese, Cheese, Ost
Add CsvLocalizationsDelegate
to MaterialApp.localizationsDelegates
and set MaterialApp.supportedLocales
:
localizationsDelegates:[
... // global delegates
CsvLocalizationsDelegate(
CsvLocalizations(
assetPath: 'assets/lang.csv',
supportedLanguageCodes: ['en', 'nb'],
),
),
]
supportedLocales: [Locale('en'), Locale('nb')],
Now translate strings using:
CsvLocalizations.of(context).tr('Hi')
Note for iOS
Add supported locales to
ios/Runner/Info.plist
as described here.
Example:
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb</string>
</array>
Example #
See example