flutter_localized_locales 1.0.0 copy "flutter_localized_locales: ^1.0.0" to clipboard
flutter_localized_locales: ^1.0.0 copied to clipboard

outdated

Locale code to name mappings for several languages

flutter_localized_locales #

Locale code to name mappings for 563 locales.

This package is based from the flutter-localized-countries package.

Data is taken from https://github.com/umpirsky/locale-list.

This package bundles required assets and provides a LocalizationsDelegate for loading them.

Usage #

Loading #

import 'package:flutter_localized_locales/flutter_localized_locales.dart';

void main() {
  runApp(MaterialApp(
    localizationsDelegates: [
      LocaleNamesLocalizationsDelegate(), // Loads relevant assets
      // ... more localization delegates
    ],
    ...
  );

Getting a locale name #

LocaleNames.of(context).nameOf(String locale)

Example: On a device whose locale is English (en)

print(LocaleNames.of(context).nameOf('en_GB'));   // English (United Kingdom)

// If the locale isn't supported
print(LocaleNames.of(context).nameOf('zzzz'));     // English

// If the locale is invalid, but a match can be found
print(LocaleNames.of(context).nameOf('es_ZZZ'));  // Spanish

Example: On a device whose locale is French (fr)

print(LocaleNames.of(context).nameOf('en_GB'));   // anglais (Royaume-Uni)

// If the device locale isn't supported
print(LocaleNames.of(context).nameOf('zzzz'));     // français

// If the locale is invalid, but a match can be found
print(LocaleNames.of(context).nameOf('es_ZZZ'));  // espagnol

Note: If a device's locale isn't supported, English (en) names are used.

Getting locale names, sorted #

LocaleNames.sortedByCode()

LocaleNames.sortedByName()

Getting all native locale names #

LocaleNames.allNativeNames()

For convenience, this package provides a map of locale codes to native locale names. This always returns the same data, irrespective of the device locale.

print(LocaleNames.allNativeNames());      // { ... af_ZA: Afrikaans (Suid-Afrika), ... ar: ال العربية السعودية) ...  as: অসমীয়া ... fr: Français ... en: English ... }

Known Bugs #