flutter_localized_locales 1.1.2

Flutter Android iOS web

Flutter plugin which provides locale code to name mappings for 563 locales.

flutter_localized_locales #

flutter_localized_locales is a Flutter plugin which enables obtaining localized locale names from locale codes (ISO 639‑2 and ISO 639-3) for 563 locales.

This package is based on the flutter_localized_countries package. Data is taken from https://github.com/umpirsky/locale-list.

Getting started #

Adding the localizations delegate #

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

import 'package:flutter_localized_locales/flutter_localized_locales.dart';

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

Usage #

Getting a locale's 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 returned.

Getting all locale names, sorted #

LocaleNames.sortedByCode()

LocaleNames.sortedByName()

Getting all native locale names #

LocaleNames.nativeLocaleNames

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.nativeLocaleNames);      // { ... af_ZA: Afrikaans (Suid-Afrika), ... ar: ال العربية السعودية) ...  as: অসমীয়া ... fr: Français ... en: English ... }

Known Bugs #

15
likes
110
pub points
94%
popularity

Flutter plugin which provides locale code to name mappings for 563 locales.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

plg@google.com

License

MIT (LICENSE)

Dependencies

flutter, flutter_localizations, intl

More

Packages that depend on flutter_localized_locales