搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.5

flutter_localized_locales

提供 563 個區域設定的區域設定代碼到名稱映射的 Flutter 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
65.6萬
喜歡數
64
Pub 分數
150

安裝套件

flutter pub add flutter_localized_locales

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供從地區代碼到其可讀名稱的對應關係,支援 563 種地區設定。它透過讓開發者能在應用程式中顯示本地化的語言與國家名稱,簡化了本地化流程,進而提升國際使用者的體驗。此套件支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。對於需要準確且一致的地區設定名稱,又不需手動管理資料的應用程式而言,是理想的選擇。

適用情境

  • 在下拉選單中顯示本地化語言名稱
  • 支援多語言應用介面
  • 使用可讀的區域設定標籤增強使用者設定
  • 建構語言選擇畫面
  • 國際化應用元數據
  • 提供準確的國家和語言標籤

主要特色

  • 563 語言環境代碼到名稱的映射
  • 跨平台相容性
  • 簡單 API 結合
  • 無外部依賴
  • 維護且最新
  • 在 GitHub 上開源

適合對象

  • 面向全球用戶的App
  • 在地化密集型應用
  • 語言選擇組件
  • 國際化使用者介面元素
  • 尋求現成地區設定資料的開發者

使用建議

  • 不包含翻譯或字串
  • 需要額外的套件才能實現完整的國際化
  • 區域設定名稱是靜態的,無法自訂
  • 不適用於執行時翻譯
  • 僅限名稱映射

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案