패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 파일 생성을 지원합니다. 안드로이드, iOS, 리눅스, 맥OS, 웹, 윈도우 플랫폼 간 다국어 콘텐츠를 관리하는 개발자에게 이상적입니다. 최소한의 종속성과 직관적인 API를 통해 기존 워크플로우에 원활하게 통합됩니다. 외부 도구에 의존하지 않고 번역 파일 처리를 정밀하게 제어해야 하는 프로젝트에 특히 유용합니다.

사용 사례

  • .po 파일 파싱을 통한 번역 추출
  • .po 파일을 .mo 바이너리로 컴파일하는 것
  • 다국어 지원을 위한 플러터 앱과의 통합
  • CI/CD 파이프라인에서 번역 관리
  • 데스크톱 및 웹 로컬라이제이션 지원

주요 기능

  • .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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

순위