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

패키지 상세v0.7.0

json_localizations

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

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

패키지 설치

flutter pub add json_localizations

패키지 개요

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

Flutter의 LocalizationsDelegate를 기반으로 한 가벼운 JSON 기반 로컬라이제이션 패키지입니다. JSON 파일에서 번역을 로드하여 다국어 지원과 동적 언어 전환을 가능하게 하며, 로컬라이즈된 문자열을 쉽게 관리할 수 있습니다. Flutter의 국제화 시스템과의 간편한 통합을 위해 설계되어, 복잡한 설정 없이 깔끔하고 읽기 쉬운 번역 파일을 유지할 수 있습니다. 최소한의 오버헤드로 간단한 다국어 지원이 필요한 앱에 적합합니다.

사용 사례

  • 다국어 앱 지원
  • 동적 언어 전환
  • 간단한 번역 파일 관리
  • 리소스에 번역 포함하기
  • 경량 현지화 솔루션
  • 사용자 정의 가능한 로케일 후행

주요 기능

  • JSON 기반 번역 파일
  • LocalizationsDelegate 확장
  • 다중 로케일을 지원합니다
  • 간편한 자산 통합
  • 최소한의 보일러플레이트
  • 백업 로케일 처리

적합한 대상

  • 작은에서 중간 규모의 앱
  • 간결함을 추구하는 개발자
  • 정적 번역이 있는 프로젝트
  • 로컬라이제이션에 JSON을 사용하는 팀
  • 기본 i18n이 필요한 앱
  • 빠른 프로토타이핑

고려 사항

  • 대규모 번역 워크플로우에 적합하지 않음
  • 내장된 번역 편집 도구 없음
  • 수동 JSON 파일 관리
  • 복수 표현에 대한 제한된 지원
  • 자동 키 추출 없음
  • 수동 로케일 설정이 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

json_localizations

A minimal JSON localization package for Flutter.

Use a JSON file/object per language to represent key/value pairs for localizing your app.

Install

Add json_localizations and flutter_localizations as dependencies to your pubspec.yaml.

dependencies:
  flutter_localizations:
    sdk: flutter
  json_localizations:
Add a JSON file per language

Add a JSON file per language you support in an asset path and describe it in your pubspec.yaml

flutter:
  assets:
    - assets/json_translations/

The JSON 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.json file.

Add JsonLocalizationsDelegate to MaterialApp

Add JsonLocalizationsDelegate to MaterialApp and set supportedLocales using language/country codes.

MaterialApp(
  localizationsDelegates: [
    // delegate from flutter_localization
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
    // delegate from json_localizations
    JsonLocalizationsDelegate('assets/json_translations'),
  ],
  supportedLocales: [
    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>

Format

Example JSON file:

{
	"hello": "hello",
	"bye": "bye",
	"items": [ "one", "two", "three" ],
	"count": 1
}

Tip: You can store any json type given a key, like a string, an array of strings, or a number

API

Get a value for the current language using:

JsonLocalizations.of(context)?.value('hello')

We keep the API simple, but you could easily add an extension method to String:

extension LocalizedString on String {
  String tr(BuildContext context) => JsonLocalizations.of(context)!.value(this);
}

So you could write:

'hello'.tr(context)

Example

See example.

카테고리

소스 저장소

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

아직 데이터가 없습니다.