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

パッケージ詳細v2.8.0

toml_localizations

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

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

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

flutter pub add toml_localizations

パッケージ概要

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

TOML(Tomの明白で最小限の言語)ファイルを使用してアプリの翻訳を管理する軽量なFlutterパッケージです。FlutterのLocalizationsDelegateに基づいており、TOMLファイルからキーと値のペアを読み込むことで、ローカライズされた文字列を簡単に統合できます。複数のロケールをサポートし、クリーンで人間が読みやすい形式により、翻訳ワークフローを簡素化します。JSONやYAMLの代替として最小限かつ構造的な選択肢を探している開発者に最適です。Android、iOS、Web、macOS、Windows、Linuxなど、すべての主要なFlutterプラットフォームで動作します。

用途

  • マルチリンガルアプリコンテンツの管理
  • TOML ファイルから翻訳を読み込み中
  • Flutterアプリにおけるローカリゼーション設定の簡素化
  • 動的言語切り替えのサポート
  • 翻訳用の構造化テキストファイルの統合

主な機能

  • TOMLベースの翻訳ファイル
  • 最小限の依存関係フットプリント
  • LocalizationsDelegate に基づいて構築
  • クロスプラットフォーム対応
  • 読みやすい設定形式
  • 自動ロケール検出

適している対象

  • JSON/YAMLよりもTOMLを好む開発者
  • 軽量なローカリゼーションを必要とするプロジェクト
  • 構造化テキスト形式を使用するチーム
  • 複数の言語をターゲットにするアプリ
  • 簡単な翻訳管理が必要なFlutterアプリ

注意事項

  • TOML ファイルの手動設定が必要です
  • 基本的な文字列翻訳に限定
  • 組み込みの翻訳編集ツールなし
  • TOML の解析は JSON よりもなじみが少ないかもしれません
  • 複雑なローカライゼーション構造には適していません

元の README

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

toml_localizations

A minimal TOML localization package for Flutter.

TOML is a minimal, easy to read, configuration file format, which allows you to represent strings (and other types) as key/value pairs.

Install

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

dependencies:
  flutter_localizations:
    sdk: flutter
  toml_localizations: <last-version>
Add assets

Add a TOML file per language to a asset path and define it in your pubspec.yaml.

flutter:
  assets:
    - assets/toml_translations

The TOML 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.toml file.

Add localization delegate and supported locales

Add TomlLocalizationsDelegate to MaterialApp and set supportedLocales to supported language/country codes.

MaterialApp(
  localizationsDelegates: [
    // delegate from flutter_localization
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    // toml localizations delegate
    TomlLocalizationsDelegate(path: 'assets/toml_translations')
  ],
  supportedLocales: [
    Locale('en', 'GB'),
    Locale('en', 'US'),
    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</string>
	<string>en-GB</string>
	<string>en-US</string>
	<string>nb</string>
</array>

Format

Example TOML file:

str = "The quick brown fox jumps over the lazy dog."

literal_str = 'C:\Users\nodejs\templates'

multiline_str = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""

literal_multiline_str = '''
The first newline is
trimmed in raw strings.
   All other whitespace
   is preserved.
'''

list = [ 'one', 'two', 'three' ]

Tip: Toml supports several ways of expressing strings. See Toml documentation for more info.

API

Translate strings or other types using:

TomlLocalizations.of(context)!.value(this);

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

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

Se you could translate strings like this:

'Hi'.tr(context)

Example

See example

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

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