Native Localization (nat_l10n)

This plugin helps to make use of localization utilities provided by the native platforms.

Platform Support

AndroidiOSMacOSWebLinuxWindows
✔️✔️➖️➖️➖️➖️

Features

Receive localized

  • time zone entries
  • locale entries
  • currency entries

Usage

General

// Import package
import 'package:nat_l10n/nat_l10n.dart';

// Instantiate it
final NatL10n natL10n = NatL10n();

Localize Time Zones

// Required: Target Locale, Time Zone Ids (List), Optional: Formatting Style
List<TimeZoneInfo> localizedTimeZones = await natL10n.localizedTimeZones(
      Locale('en', 'US'), ['America/Denver', 'Europe/Berlin'], style: TimeZoneStyle.long);
});

// Returns:
// 1. {id: America/Denver, translation: Mountain Standard Time, offset: -25200}
// 2. {id: Europe/Berlin, translation: Central European Standard Time, offset: 3600}

Localize Locales

// Required: Target Locale, Locales to localize (List)
List<LocaleInfo> localizedLocales = await natL10n.localizedLocales(
      Locale('en', 'US'), [ Locale('de', 'DE'),  Locale('ko', 'KR')]);
});

// Returns:
// 1. {localeTag: de-DE, translatedLocale: German (Germany), translatedLanguage: German, translatedRegion: Germany}
// 2. {localeTag: ko-KR, translatedLocale: Korean (South Korea), translatedLanguage: Korean, translatedRegion: South Korea}

Respectively localize Locales

// Required: Locales to localize (List) into each locale respectively
List<LocaleInfo> localizedLocales = await natL10n.respectivelyLocalizedLocales(
      [ Locale('de', 'DE'),  Locale('ko', 'KR')]);
});
// Returns:
// 1. {localeTag: de-DE, translatedLocale: Deutsch (Deutschland), translatedLanguage: Deutsch, translatedRegion: Deutschland}
// 2. {localeTag: ko-KR, translatedLocale: 한국어 (대한민국), translatedLanguage: 한국어, translatedRegion: 대한민국}

Localize Currencies

// Required: Target Locale, Currency codes to localize
List<CurrencyInfo> localizedCurrencies = await natL10n.localizedCurrencies(
    Locale('en', 'US'), [ 'USD', 'EUR']);
});
// Returns:
// 1. {currencyCode: USD, translated: US Dollar, symbol: $}
// 2. {currencyCode: EUR, translated: Euro, symbol: €}

Additional information

1. Help Utils

The example app includes a list of:

a) Android/Kotlin

All supported Identifiers, Locales, Currency Codes

Show Code
import java.util.*

fun main() {
    printTimeZones()
    printLocales()
    printCurrencies()
}

private fun printTimeZones() {
    val timeZones = TimeZone.getAvailableIDs()
    timeZones.forEach {
       println("$it") 
    }
}

private fun printLocales() {
    val locales = Locale.getAvailableLocales()
    locales.forEach {
       println("$it") 
    }
}

private fun printCurrencies() {
    val currencies = Currency.getAvailableCurrencies()
    currencies.forEach {
       println("$it") 
    }
}

b) iOS/Swift

All supported Identifiers, Locales, Currency Codes

Show Code
import Foundation

printTimeZones()
printLocales()
printCurrencies()

private func printTimeZones() {
  let timeZones = TimeZone.knownTimeZoneIdentifiers
  timeZones.forEach {
    print("\($0 as String?)")
  }
}

private func printLocales() {
  let locales = Locale.availableIdentifiers
  locales.forEach {
    print("\($0 as String?)")
  }
}

private func printCurrencies() {
  let currencies = Locale.isoCurrencyCodes
  // let currencies = Locale.commonISOCurrencyCodes
  currencies.forEach {
    print("\($0 as String?)")
  }
}

2. Regarding Time Zone Ids

Which time zone ids are supported, depends on the underlying platform.
The 'Area/Location' name format for time zone Ids is preferred (Reference).

3. Regarding Locales

4. Regarding Currencies

5. Regarding Localization Results

The results can vary on the different platforms. No guarantee is given that the results are correct.

Libraries

nat_l10n