Code Monkey home page Code Monkey logo

flutter-localized-locales's Introduction

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)

// Invalid locale string
print(LocaleNames.of(context).nameOf('zzzzz'));    // null

// On a device whose selected locale is English (en)
print(LocaleNames.of(context).nameOf('fr_CA'));   // French (Canada)

// On a device whose selected locale is Spanish (es)
print(LocaleNames.of(context).nameOf('fr_CA'));   // francés (Canadá)

// On a device whose selected locale isn't supported, an attempt is made to find a matching locale
// e.g. for a device whose locale is German (United Kingdom), returns German (de) names
print(LocaleNames.of(context).nameOf('fr_CA'));   // Französisch (Kanada)

// Otherwise, English (en) names are returned. 
// You can specify a different fallback locale with
LocaleNamesLocalizationsDelegate(fallbackLocale: 'fr')

Supported locales are listed in lib/locales.dart.

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

flutter-localized-locales's People

Contributors

comlaterra avatar guidezpl avatar pennzht avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.