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

GitHub 저장소erf/yaml_localizations

yaml_localizations

Flutter용 YAML 로컬라이제이션

yaml_localizations 프로젝트 이미지
스타
1
포크
0
최근 푸시(UTC)
2025. 7. 7.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

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

Erlend GitHub avatar
GitHub 작성자

Erlend ↗

언어C++DartCMakeHTMLPythonSwiftCKotlinObjective-C

분류

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 5 개

  • flutter{"sdk":"flutter"}
  • yaml^3.1.3
  • flutter_test개발 의존성{"sdk":"flutter"}
  • flutter_localizations개발 의존성{"sdk":"flutter"}
  • flutter_lints개발 의존성^6.0.0

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗