パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリguidezpl/flutter-localized-locales

flutter-localized-locales

563 のロケール用のロケールコードから名前へのマッピングを提供する Flutter パッケージ

flutter-localized-locales のプロジェクト画像
スター
18
フォーク
13
最終プッシュ(UTC)
2023/09/21
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

flutter_localized_locales

pub package

flutter_localized_locales is a Flutter package which enables obtaining localized locale names from locale codes (ISO 639‑1) 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. Specify localizationsDelegates for your MaterialApp, CupertinoApp, or WidgetsApp.

import 'package:flutter_localized_locales/flutter_localized_locales.dart';

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

Usage

Locale name

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

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

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

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

// On a device whose locale isn't supported, an attempt is made to find a supported one
// 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)

// On a device whose selected locale isn't supported, and no supported locale can be found,
// fallback to English (en) names. 
// You can specify a different fallback locale
// e.g. to fallback to Afrikaans (af) names instead of English
LocaleNamesLocalizationsDelegate(fallbackLocale: 'af')

Supported locales are listed in lib/locales.dart.

All locale names, sorted

LocaleNames.sortedByCode()

LocaleNames.sortedByName()

Respective locale names

LocaleNamesLocalizationsDelegate.nativeLocaleNames

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

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

Known Bugs

pierre GitHub avatar
GitHub 作者

pierre ↗

@google
言語DartShellSwiftHTMLKotlinObjective-C

カテゴリー

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 4 件

  • flutter{"sdk":"flutter"}
  • intlany
  • flutter_test開発用{"sdk":"flutter"}
  • path開発用^1.8.0

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗