Setup Multi-Language
en.json -> English file
  1. 1.
    Add json for new language into folder /i18n. Ex: en.json
  2. 2.
    Open lib/main.dart
    1
    supportedLocales: [Locale('en', 'US')],
    Copied!
    Add Locale of new language here.
  3. 3.
    Open lib/localization/Localized.dart
    1
    @override
    2
    bool isSupported(Locale locale) {
    3
    return ['en'].contains(locale.languageCode);
    4
    }
    Copied!
    Add your language code in to this array. Ex: ["en", "vn", "fr"]
  4. 4.
    Open lib/localization/LocalizedKey.dart
    1
    class LocalizedKey {
    2
    LocalizedKey._();
    3
    4
    static const String exploreTheWorld = "Explore the world";
    5
    static const String enterACityOrLocation = "Enter a city or location";
    6
    static const String popularCities = "Popular cities";
    7
    static const String viewAll = "View All";
    8
    static const String travelInspiration = "Travel Inspiration";
    9
    static const String viewMore = "View More";
    10
    static const String allCities = "All Cities";
    11
    static const String home = "Home";
    12
    static const String readMore = "Read more";
    13
    static const String cityInfomation = "City Infomations";
    14
    static const String filter = "Filter";
    15
    16
    }
    Copied!
    Add key here.
  5. 5.
    How to use?
    1
    Localized.of(context).trans(LocalizedKey.exploreTheWorld)
    Copied!
    In Text component:
    1
    Text(
    2
    Localized.of(context).trans(LocalizedKey.exploreTheWorld) ?? "",
    3
    style: TextStyle(
    4
    fontFamily: GoloFont,
    5
    fontWeight: FontWeight.w600,
    6
    fontSize: 32),
    7
    )
    Copied!
Last modified 1yr ago
Copy link