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

パッケージ詳細v1.6.0

yaml_localizations

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

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

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

flutter pub add yaml_localizations

パッケージ概要

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

YAML ファイルを使用してアプリの翻訳を管理するための軽量な Flutter パッケージで、Flutter の LocalizationsDelegate をベースに構築されています。YAML リソースからローカライズされた文字列を読み込むことで、複雑なセットアップなしに簡単に国際化が可能になります。このパッケージは、すべての主要プラットフォームにおける Flutter アプリにシームレスに統合され、最小限のボイラープレートでクリーンかつ保守しやすい方法でローカリゼーションを処理します。JSON やハードコードされた翻訳システムの代替としてシンプルな選択肢を探している開発者に最適です。

用途

  • マルチ言語アプリ対応
  • シンプルな翻訳管理
  • 既存のFlutterプロジェクトとの統合
  • 軽量なローカリゼーションソリューション
  • 動的言語切り替え

主な機能

  • YAMLベースの翻訳ファイル
  • LocalizationsDelegate に基づいて構築
  • クロスプラットフォーム互換性
  • 最小構成
  • 拡張および保守が簡単

適している対象

  • 小規模から中規模のアプリ
  • JSONよりもYAMLを好む開発者
  • 迅速なi18n設定が必要なプロジェクト
  • 複雑なローカリゼーションフレームワークを避けるチーム
  • 複数のプラットフォームをターゲットにするアプリ

注意事項

  • 手動でのYAMLファイル管理が必要です
  • 組み込みの翻訳編集ツールなし
  • 文字列ベースの翻訳に限定
  • 大規模な翻訳ワークフローには適していません
  • 実行時翻訳の更新はありません

元の README

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

yaml_localizations

A minimal YAML localization package for Flutter.

YAML is a human-readable, configuration file format with a minimal syntax, which allows you to represent strings as key/value pairs in addition to other types.

YAML is the format used by Flutter's pubspec.yaml file.

Install

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

dependencies:
  flutter_localizations:
    sdk: flutter
  yaml_localizations:
Add a YAML file per language

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

flutter:
  assets:
    - assets/yaml_translations/

The YAML file name must match the language tag described in supportedLocales.

E.g. Locale('en', 'US') must have a corresponding assetPath/en-US.yaml file.

Add localizationDelegates and supportedLocales

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

MaterialApp(
  localizationsDelegates: [
    // global delegates
    ...GlobalMaterialLocalizations.delegates,
    // yaml localizations
    YamlLocalizationsDelegate(path: 'assets/yaml_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-GB</string>
	<string>en</string>
	<string>nb</string>
</array>

YAML format

Hi: Hi
Text: |
  There once was a tall man from Ealing
  Who got on a bus to Darjeeling
      It said on the door
      "Please don't sit on the floor"
  So he carefully sat on the ceiling
Long: >
  Wrapped text
  will be folded
  into a single
  paragraph

  Blank lines denote
  paragraph breaks

Tip: Yaml supports several ways of expressing strings. Use the vertical bar character to indicate that a string will span several lines. Use the greater-than character to break up long lines.

API

Translate strings using

YamlLocalizations.of(context)?.string('Hi')

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) => YamlLocalizations.of(context)!.string(this);
}

So you can use it like this:

'Hi'.tr(context)

Example

See example

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

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