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

パッケージ詳細v0.2.0

gettext_parser

Dartでgettextのpoファイルおよびmoファイルを解析・コンパイルする、プラットフォーム非依存のライブラリ

AndroidiOSLinuxmacOSWebWindows
30日間ダウンロード
4.7万
いいね数
4
Pub ポイント
130

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

flutter pub add gettext_parser

パッケージ概要

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

プラットフォームに依存しないDartライブラリで、gettextの.poおよび.moファイルを解析・コンパイルする機能を提供し、Flutterやその他のDartアプリケーションにおける堅牢なローカライゼーションと国際化を可能にします。翻訳カタログの読み込み、メッセージの抽出、コンパイル済みバイナリファイル(.mo)の生成をサポートしています。Android、iOS、Linux、macOS、Web、Windowsなど、さまざまなプラットフォーム間で多言語コンテンツを管理する開発者にとって理想的です。最小限の依存関係と直感的なAPIにより、既存のワークフローにスムーズに統合できます。外部ツールに頼らず、翻訳ファイルの取り扱いを正確に制御したいプロジェクトに特に適しています。

用途

  • .po ファイルの解析による翻訳抽出
  • .po ファイルを .mo バイナリにコンパイルする
  • Flutterアプリとの統合による多言語対応
  • CI/CDパイプラインでの翻訳の管理
  • デスクトップおよびWebのローカライズをサポート

主な機能

  • .po および .mo ファイル形式をサポートしています
  • クロスプラットフォーム互換性
  • 解析およびコンパイル用の簡単な API
  • 外部の依存関係なし
  • 効率的なメッセージの抽出とエンコード

適している対象

  • i18nが必要なFlutter開発者
  • 翻訳に gettext を使用するチーム
  • 複数のプラットフォームをターゲットにするプロジェクト
  • 翻訳ファイルを含むビルドの自動化
  • 開発者は実行時翻訳ライブラリを避ける

注意事項

  • 翻訳の読み込みを手動で処理する必要があります
  • 完全なi18nフレームワークではない
  • ファイルの解析/コンパイルに限定
  • 組み込みのフォールバックやロケール切り替えなし
  • カスタム i18n レイヤーと併用するのが最適です

元の README

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

Dart gettext mo/po parser

Parse and compile gettext po and mo files with dart. Ported gettext-parser npm package to dartlang.

Usage

Add dependency to pubspec.yaml

dependencies:
    gettext_parser: any

Import library:

import 'package:gettext_parser/gettext_parser.dart' as gettextParser;
Parse .po files:
Map translateTable = gettextParser.po.parse(
    file.readAsStringSync(),
);
Parse .mo files:
Map translateTable = gettextParser.mo.parse(
    file.readAsBytesSync(),
);
Compile .po files:
String data = gettextParser.po.compile(
    translateTable,
);
Compile .mo files:
UInt8List data = gettextParser.mo.compile(
    translateTable,
);

Encoding

gettext_parser use Encoding interface for encoding and decoding charsets from dart:convert package with utf8, base64, latin1 built-in encoders. If you need other encoding you could implement Encoding interface by your own.

Example:

gettextParser.mo.parse(buffer, encoding: latin1);
gettextParser.po.parse(buffer, encoding: latin1);

Data structure of parsed mo/po files

Character set

Parsed data is always in unicode but the original charset of the file can be found from the charset property.

Headers

Headers can be found from the headers object, all keys are lowercase and the value for a key is a string. This value will also be used when compiling.

Translations

Translations can be found from the translations object which in turn holds context objects for msgctxt. Default context can be found from translations[""].

Context objects include all the translations, where msgid value is the key. The value is an object with the following possible properties:

  • msgctxt context for this translation, if not present the default context applies
  • msgid string to be translated
  • msgid_plural the plural form of the original string (might not be present)
  • msgstr an array of translations
  • comments an object with the following properties: translator, reference, extracted, flag, previous.

Example

{
  "charset": "iso-8859-1",

  "headers": {
    "content-type": "text/plain; charset=iso-8859-1",
    "plural-forms": "nplurals=2; plural=(n!=1);"
  },

  "translations": {
    "": {
      "": {
        "msgid": "",
        "msgstr": ["Content-Type: text/plain; charset=iso-8859-1\n..."]
      }
    },
    "another context": {
      "%s example": {
        "msgctxt": "another context",
        "msgid": "%s example",
        "msgid_plural": "%s examples",
        "msgstr": ["% näide", "%s näidet"],
        "comments": {
          "translator": "This is regular comment",
          "reference": "/path/to/file:123"
        }
      }
    }
  }
}

Notice that the structure has both a headers object and a "" translation with the header string. When compiling the structure to a mo or a po file, the headers object is used to define the header. Header string in the "" translation is just for reference (includes the original unmodified data) but will not be used when compiling. So if you need to add or alter header values, use only the headers object.

License

MIT

カテゴリー

ソースリポジトリ

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

ランキング