It assumes you already have a basic Flutter project. If you're building an app for users around the world, you may need to support several languages. This guide shows how to create language packs for a Flutter app.
Create JSON language pack files in the project root as shown below. I created two files for English and Korean. You can create the directories and files in advance.
Use language codes in the filenames. For example, create en_US.json for English and ko_KR.json for Korean. If you're using region codes, include them in the filenames, as in en_US.json for US English.
Loaders support JSON, CSV, HTTP, XML, YAML, and more. See the Easy Localization Loader documentation↗.
It also supports singular and plural forms, which looks useful.
assets/translations/en_US.json
{ "money": { "zero": "You not have money", "one": "You have {} dollar", "many": "You have {} dollars", "other": "You have {} dollars" }, "money_named_args": { // 이름 지정 "zero": "{name} has no money", "one": "{name} has {money} dollar", "many": "{name} has {money} dollars", "other": "{name} has {money} dollars" }}
The library supports nested keys. This is the feature I use most. Add a . after the parent key and append the child key. You can also reference another translation at the same level using @: in the language pack.
Note: intl is pinned to version 0.19.0 by flutter_localizations from the flutter SDK.See https://dart.dev/go/sdk-version-pinning for details.The current Dart SDK version is 3.5.4.Because easy_localization >=2.3.4-nullsafety <3.0.0-dev.0 depends on flutter_localizations from sdk and easy_localization >=3.0.0-dev.0 <3.0.0-nullsafety doesn't support null safety, easy_localization >=2.3.4-nullsafety <3.0.0-nullsafety requires flutter_localizations from sdk.And because easy_localization <2.3.4-nullsafety doesn't support null safety, easy_localization <3.0.0-nullsafety requires flutter_localizations from sdk.And because easy_localization >=3.0.0-nullsafety depends on flutter_localizations from sdk which depends on intl 0.19.0, every version of easy_localization requires intl 0.19.0.So, because nftcam_flutter depends on both intl ^0.20.1 and easy_localization any, version solving failed.The lower bound of "sdk: '>=2.0.0-dev.68.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.For details, see https://dart.dev/null-safetyThe lower bound of "sdk: '>=2.7.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.For details, see https://dart.dev/null-safety
I tried this library for an app I needed to launch globally. It offers a lot of features and is easy to use. I also found flutter_localizations_generator↗, which can manage language packs in Google Sheets.
Even if you aren't planning a global launch yet, adding language packs early can make copy changes easier. I waited until the end to add them to a fairly large project, and it took a lot of work. 😂