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

パッケージ詳細v1.1.1

ez_localization

Flutterアプリケーションに、迅速かつ簡単に強力なローカリゼーションシステムをセットアップします。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
193
いいね数
23
Pub ポイント
150

パッケージをインストール

flutter pub add ez_localization

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ez_localization は、堅牢なローカリゼーションシステムのセットアップを簡素化するFlutterパッケージであり、開発者がアプリケーションに国際化を迅速に実装できるようにします。複数の言語をサポートし、Android、iOS、Web、macOS、Windows、Linuxでの翻訳管理に直感的なAPIを提供します。最小限の設定で、ロケール間のスムーズな切り替えと動的コンテンツの効率的な処理が可能になります。グローバルなユーザーをターゲットとするアプリに最適で、ボイラープレートコードを削減しながらも柔軟性と拡張性を維持しています。

用途

  • マルチ言語アプリ対応
  • 簡単な翻訳管理
  • ダイナミックロケール切り替え
  • クロスプラットフォーム国際化
  • 簡素なi18nセットアップ
  • グローバルユーザー向けのアプリローカライゼーション

主な機能

  • 最小限のセットアップが必要
  • すべての主要プラットフォームをサポートしています
  • 組み込みロケール切り替え
  • 明確で読みやすい翻訳構文
  • 拡張可能な翻訳ファイル構造
  • デフォルト言語への自動フェイルバック

適している対象

  • 多言語アプリを開発する開発者
  • 翻訳ワークフローを管理するチーム
  • 高速なi18n統合を必要とするプロジェクト
  • 国際市場をターゲットにしたアプリ
  • 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 :

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。