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

パッケージ詳細v0.7.0

json_localizations

LocalizationsDelegate をベースにした最小限の JSON ローカライゼーションパッケージ。

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

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

flutter pub add json_localizations

パッケージ概要

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

Flutter の LocalizationsDelegate をベースにした軽量な JSON ベースのローカリゼーションパッケージです。JSON ファイルから翻訳を読み込むことで、複数言語と動的な言語切り替えをサポートし、ローカライズされた文字列の管理を容易にします。Flutter の国際化システムとの統合を重視したシンプルな設計により、複雑な設定なしに明確で読みやすい翻訳ファイルを維持できます。最小限のオーバーヘッドで単純な多言語対応が必要なアプリに最適です。

用途

  • マルチ言語アプリ対応
  • 動的言語切り替え
  • シンプルな翻訳ファイル管理
  • リソースに翻訳を埋め込む
  • 軽量なローカリゼーションソリューション
  • カスタマイズ可能なロケールフォールバック

主な機能

  • JSONベースの翻訳ファイル
  • LocalizationsDelegate を拡張します
  • 複数のロケールをサポートしています
  • アセットの統合が簡単
  • 最小限のボイラープレート
  • フォールバックロケール処理

適している対象

  • 小規模から中規模のアプリ
  • シンプルさを求める開発者
  • 静的翻訳付きのプロジェクト
  • ローカリゼーションにJSONを使用するチーム
  • 基本的なi18nを必要とするアプリ
  • 高速プロトタイピング

注意事項

  • 大規模な翻訳ワークフローには適していません
  • 組み込みの翻訳編集ツールなし
  • 手動JSONファイル管理
  • 複数形のサポートが限定的
  • 自動キー抽出なし
  • 手動でのロケール設定が必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

json_localizations

A minimal JSON localization package for Flutter.

Use a JSON file/object per language to represent key/value pairs for localizing your app.

Install

Add json_localizations and flutter_localizations as dependencies to your pubspec.yaml.

dependencies:
  flutter_localizations:
    sdk: flutter
  json_localizations:
Add a JSON file per language

Add a JSON file per language you support in an asset path and describe it in your pubspec.yaml

flutter:
  assets:
    - assets/json_translations/

The JSON file name must match exactly the combination of language and country code described in supportedLocales.

That is Locale('en', 'US') must have a corresponding assetPath/en-US.json file.

Add JsonLocalizationsDelegate to MaterialApp

Add JsonLocalizationsDelegate to MaterialApp and set supportedLocales using language/country codes.

MaterialApp(
  localizationsDelegates: [
    // delegate from flutter_localization
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    // delegate from json_localizations
    JsonLocalizationsDelegate('assets/json_translations'),
  ],
  supportedLocales: [
    Locale('en'),
    Locale('nb'),
  ],
}

Note on iOS

Add supported languages to ios/Runner/Info.plist as described here.

Example:

<key>CFBundleLocalizations</key>
<array>
	<string>en-GB</string>
	<string>en</string>
	<string>nb</string>
</array>

Format

Example JSON file:

{
	"hello": "hello",
	"bye": "bye",
	"items": [ "one", "two", "three" ],
	"count": 1
}

Tip: You can store any json type given a key, like a string, an array of strings, or a number

API

Get a value for the current language using:

JsonLocalizations.of(context)?.value('hello')

We keep the API simple, but you could easily add an extension method to String:

extension LocalizedString on String {
  String tr(BuildContext context) => JsonLocalizations.of(context)!.value(this);
}

So you could write:

'hello'.tr(context)

Example

See example.

カテゴリー

ソースリポジトリ

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

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