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

套件詳情v1.1.1

ez_localization

快速且輕鬆地在您的 Flutter 應用程式中設定強大的本地化系統。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
193
喜歡數
23
Pub 分數
150

安裝套件

flutter pub add ez_localization

套件介紹

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

ez_localization 是一個 Flutter 套件,可簡化強大本地化系統的設定,讓開發者能快速在應用程式中實現國際化。它支援多種語言,並提供直覺的 API,用於管理 Android、iOS、Web、macOS、Windows 和 Linux 上的翻譯。透過最少的設定,它可實現區域設定之間的無縫切換,並有效處理動態內容。此套件非常適合針對全球使用者的應用程式,減少樣板程式碼,同時保持彈性和可擴展性。

適用情境

  • 多語言應用支援
  • 輕鬆的翻譯管理
  • 動態區域設定切換
  • 跨平台國際化
  • 簡化的國際化設定
  • 面向全球用戶的App本地化

主要特色

  • 所需設定最少
  • 支援所有主要平台
  • 內建語言切換
  • 簡潔清晰的翻譯語法
  • 可擴展的翻譯檔案結構
  • 自動回退到預設語言

適合對象

  • 開發多語言應用程式的開發者
  • 管理翻譯工作流程的團隊
  • 需要快速國際化整合的項目
  • 面向國際市場的應用
  • Flutter 初學者學習本地化
  • 頻繁更新語言的項目

使用建議

  • 需要正確的翻譯檔案組織
  • 有限的內建翻譯編輯工具
  • 手動處理複雜的複數形式
  • 依賴於正確的區域設定命名慣例
  • 無內建的翻譯儲存或同步
  • 最佳配合結構化翻譯檔案使用

原始 README

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

EzLocalization

This package allows you to setup a powerful localization system with ease and in only a few minutes.

Features

Here are some features:

  • Easy, lightweight, open-source.
  • MIT licensed.
  • Easily extensible.

Getting started

It only takes a few steps in order to get EzLocalization to work !
First, add the following code to your MaterialApp definition (usually in main.dart) :

EzLocalizationDelegate ezLocalization = EzLocalizationDelegate(supportedLocales: [Locale('en'), Locale('fr')]); // The first language is your default language.

return MaterialApp(
  // ...
  localizationsDelegates: ezLocalization.localizationDelegates,
  supportedLocales: ezLocalization.supportedLocales,
  localeResolutionCallback: ezLocalization.localeResolutionCallback,
);

Then you create a folder named languages in your assets directory with the defined languages in it. An example structure could be :

assets
└── languages
    ├── en.json
    └── fr.json

Here's an example of en.json :

{
  "hello": "Hello !"
}

And a translated fr.json :

{
  "hello": "Bonjour !"
}

Don't forget to add the assets in your pubspec.yml :

flutter:
  # ...
  assets:
    - "assets/languages/"

That's it ! To get your string you only have to call EzLocalization.of(context)!.get('hello').

Advanced

Extension method

With the extension method, it's even easier to get a localized string ! The only thing you have to do is to replace EzLocalization.of(context)!.get('key') by context.getString('key').

You may have to manually import EzLocalization in your file.

Builder widget

EzLocalization provides a builder widget called EzLocalizationBuilder. You can use it as such :

const EzLocalizationBuilder(
  delegate: EzLocalizationDelegate(
    supportedLocales: [
      Locale('en'),
      Locale('fr'),
      Locale('es'),
    ],
  ),
  builder: (context, localizationDelegate) => MaterialApp(
    title: 'Beautifully localized app',
    home: MyMainWidget(),
    localizationsDelegates: localizationDelegate.localizationDelegates,
    supportedLocales: localizationDelegate.supportedLocales,
    localeResolutionCallback: localizationDelegate.localeResolutionCallback,
  ),
);

It has two advantages :

  • It helps reducing boilerplate.
  • You can dynamically change the current locale using EzLocalizationBuilder.of(context)!.changeLocale(yourLocale).
Nested strings

You can nest translation strings as such :

{
  "tabs": {
    "home": "Home"
  }
}

And it can be access using EzLocalization.of(context)!.get('tabs.home').

Format arguments

In your translation string, you may add arguments using {} :

{
  "greeting": "Hello {target}, my name is {me} !"
}

You can then fill them with EzLocalization.of(context)!.get('greeting', {'target': 'John', 'me': 'Bob'}). Also, instead of a map you can pass a list and get your arguments by their indexes.

Change the files path

You can change from the default path of assets/languages/$languageCode.json by passing getPathFunction to EzLocalizationDelegate. You will then have to provide a valid asset path according to the specified locale.

Don't forget to update your assets entry in your pubspec !

Updating the iOS app bundle

See the official flutter.dev documentation about updating the iOS app bundle.

Contributing

You have a lot of options to contribute to this project ! You can :

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。