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

套件詳情v0.6.0

multiple_localization

支援多個 abr 與訊息本地化檔案,適用於 intl 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3.5萬
喜歡數
28
Pub 分數
160

安裝套件

flutter pub add multiple_localization

套件介紹

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

multiple_localization 套件透過支援多個地區化檔案(包含 .arb 檔案)增強了 intl 套件,讓開發者能更有效率地管理不同語言與地區設定的翻譯。它簡化了在 Flutter 應用中組織與載入地區化訊息的流程,特別適用於大規模國際化需求。此套件設計為與 Flutter 現有的國際化基礎設施無縫整合,使翻譯資源的維護與擴展更輕鬆。支援所有主要平台:Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 在單一項目中管理多個語言檔案
  • 簡化大型應用的翻譯工作流程
  • 支援動態區域設定切換
  • 按功能或模組組織翻譯
  • 與現有的基於 intl 的本地化整合
  • 啟用模組化本地化結構

主要特色

  • 支援多個 .arb 檔案
  • 與 intl 包的無縫整合
  • 靈活的檔案組織
  • 平台無關的設計
  • 透過 pub add 輕鬆設定
  • 自動訊息加載

適合對象

  • 大規模國際化Flutter應用
  • 管理多個翻譯檔案的團隊
  • 需要模組化本地化的專案
  • 使用 intl 進行國際化開發的開發者
  • 面向多樣化全球受眾的應用程式

使用建議

  • 需要熟悉 intl 包
  • 自定義檔案路徑需要額外設定
  • 可能因檔案過多而增加建構複雜性
  • 最適合已經使用 intl 的專案
  • 不相容非國際化定位方法

原始 README

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

multiple_localization

pub package Analyze & Test innim lint

Support for multiple abr and messages localization files for intl package.

Problem

If you want to have multiple arb files and register separate delegate for each one of them, then you have a problem. Intl doesn't allow multiple initializeMessages calls. Only first one will be processed and only it's messages will be used. Every calls after the first one will be ignored.

Why do we need to have multiple arb files?

In common scenario - we don't. Just put all localization string in single file and enjoy. But if you want to add intl localization with arb files to separate package, and than use it in you project with it's own localization files - that's problem.

MultipleLocalizations supports using Localizations.override(delegates: [SomeLocalizationsDelegate(), ...]) widget, too.

Exactly for that situation this package was developed.

See article on Medium for more details - Localization for Dart package.

Usage

To use this package, add multiple_localization as a dependency in your pubspec.yaml file.

Than use MultipleLocalizations.load for your delegate load function, instead of call initializeMessages explicitly.

Example
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
  const _AppLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) {
    return ['en', 'ru'].contains(locale.languageCode);
  }

  @override
  Future<AppLocalizations> load(Locale locale) {
    return MultipleLocalizations.load(
        initializeMessages, locale, (l) => AppLocalizations(l),
        setDefaultLocale: true);
  }

  @override
  bool shouldReload(LocalizationsDelegate<AppLocalizations> old) {
    return false;
  }
}
Override string from package in project

If you want to override string from package localization in project (for example to change some labels in package widgets) - you need to define string with required name in you app localization class.

Example.

If package has string messageFromPackageForOverride:

class PackageLocalizations {
  ...

  String get messageFromPackageForOverride =>
        Intl.message('Package', name: 'messageFromPackageForOverride');

Then you need to define messageFromPackageForOverride in you AppLocalizations:

class AppLocalizations {
  ...

  String get messageFromPackageForOverride =>
        Intl.message('App', name: 'messageFromPackageForOverride');

Make sure that you add the app localization delegate before the package localization delegate:

  ...
  const MaterialApp(
    localizationsDelegates: [
      AppLocalizations.delegate,
      PackageLocalizations.delegate,
      ...
    ],
    ...

Now, whenever package use messageFromPackageForOverride you will see App, not Package.

Set fallback locale

Also you can specify a fallback locale when loading application localization delegate. Use [fallbackLocale] parameter to set locale which will be used if some key not found for current locale. Only first call of [load] will set fallback locale, make sure that your app's localization delegate added as a first element of the delegates list.

Also pay attention that if you provide the [fallbackLocale], than all messages will be uploaded in memory on the start of application in addition to current locale.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。