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

패키지 상세v2.8.0

toml_localizations

LocalizationsDelegate 기반의 최소한의 TOML 로컬라이제이션 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
94
좋아요
3
Pub 점수
150

패키지 설치

flutter pub add toml_localizations

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

TOML(Tom의 명확하고 최소한의 언어) 파일을 사용하여 앱 번역을 관리하는 가벼운 플러터 패키지입니다. 플러터의 LocalizationsDelegate 기반으로 구축되어 TOML 파일에서 키-값 쌍을 로드함으로써 지역화된 문자열을 쉽게 통합할 수 있습니다. 여러 로케일을 지원하며 깔끔하고 인간이 읽기 쉬운 형식으로 번역 워크플로우를 단순화합니다. JSON 또는 YAML 대신 최소한이고 구조적인 대안을 원하는 개발자에게 이상적입니다. 안드로이드, iOS, 웹, macOS, 윈도우, 리눅스 등 모든 주요 플러터 플랫폼에서 작동합니다.

사용 사례

  • 다국어 앱 콘텐츠 관리
  • TOML 파일에서 번역을 로드 중
  • Flutter 앱에서 로컬라이제이션 설정 간소화
  • 동적 언어 전환 지원
  • 번역을 위한 구조화된 텍스트 파일 통합

주요 기능

  • TOML 기반 번역 파일
  • 최소 종속성 프로필
  • LocalizationsDelegate 기반으로 구축
  • 크로스 플랫폼 지원
  • 읽기 쉬운 구성 형식
  • 자동 로케일 감지

적합한 대상

  • JSON/YAML보다 TOML을 선호하는 개발자
  • 경량 로컬라이제이션을 필요로 하는 프로젝트
  • 구조화된 텍스트 형식을 사용하는 팀
  • 다중 언어를 대상으로 하는 앱
  • 간단한 번역 관리가 필요한 플러터 앱

고려 사항

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

소스 저장소

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

아직 데이터가 없습니다.