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

패키지 상세v1.6.0

yaml_localizations

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

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
33
좋아요
2
Pub 점수
150

패키지 설치

flutter pub add yaml_localizations

패키지 개요

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

YAML 파일을 사용하여 앱 번역을 관리하는 가벼운 플러터 패키지로, 플러터의 LocalizationsDelegate 기반으로 구축되었습니다. YAML 리소스에서 로컬라이즈된 문자열을 로드함으로써 복잡한 설정 없이 간편한 국제화를 가능하게 하며, 여러 언어를 지원하는 과정을 단순화합니다. 이 패키지는 모든 주요 플랫폼의 플러터 앱에 원활하게 통합되어 최소한의 보일러플레이트로 깔끔하고 유지보수 쉬운 방식으로 로컬라이제이션을 처리할 수 있습니다. 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 개

소스 저장소

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

아직 데이터가 없습니다.