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

패키지 상세v1.1.2

i18n_localizations

국제화를 위한 간단한 플러터 패키지로, Angular TranslateService 사용자는 이 패키지를 좋아할 것입니다.

30일 다운로드
17
좋아요
5
Pub 점수
40

패키지 설치

flutter pub add i18n_localizations

패키지 개요

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

국제화를 위한 가벼운 플러터 패키지로, 앱 내 번역을 간단하고 직관적으로 관리할 수 있는 방법을 제공합니다. Angular의 TranslateService에서 영감을 받아 언어 간 전환 및 로컬라이즈된 문자열을 가져오는 사용하기 쉬운 API를 제공합니다. 복잡한 설정 없이 간단한 해결책을 원하는 개발자에게 이상적입니다. 동적 언어 변경을 지원하며 플러터 프로젝트에 원활하게 통합됩니다. 특히 Angular의 번역 패턴에 익숙한 개발자에게 매력적입니다.

사용 사례

  • 다국어 앱 지원
  • 동적 언어 전환
  • 간단한 번역 관리
  • 웹 및 모바일 로컬라이제이션
  • 기존 번역 파일과의 통합

주요 기능

  • Angular TranslateService에서 영감을 받은 API
  • 언어 전환 쉽게
  • JSON 번역 파일을 지원합니다
  • 최소한의 보일러플레이트
  • 깨끗하고 읽기 쉬운 구문

적합한 대상

  • 플러터 초보자
  • Angular에서 이전하는 개발자
  • 기본 i18n이 필요한 앱
  • 작은에서 중간 규모의 번역 필요성이 있는 프로젝트
  • JSON 기반 번역 워크플로를 사용하는 팀

고려 사항

  • 완전한 i18n 프레임워크와 비교하여 고급 기능이 제한적입니다
  • 내장 번역 파일 생성 없음
  • 누락된 키 수동 처리
  • 대규모 기업용 앱에는 적합하지 않습니다
  • 외부 JSON 파일 관리에 의존

원본 README

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

i18n_localizations

A flutter package for internationalization, it allows you to simply add the translation of the application according to the language of the device, it uses json files as angular. You only need to configure it properly to be able to translate your entire app.

Getting Started

Follow the next step for use i18n_localizations

Configuration

To use this library, you will need json file you can put there where you want, but don't forget to add them to your pubspec.yaml

assets:
  - {translateDir}/en.json
  - {translateDir}/fr.json
  - {translateDir}/{languageCode}.json
    or
  - {translateDir}/en_US.json
  - {translateDir}/fr_FR.json
  - {translateDir}/{languageCode}_${countryCode}.json

You need to initialize a I18nLocalizationsDelegate white a list of supportedLocales and a pathFile where the json file are store.

final I18nLocalizationsDelegate i18n = I18nLocalizationsDelegate(
      supportedLocales: [Locale('en'), Locale('fr')],
      pathFile: '{translateDir}'
  );
or
final I18nLocalizationsDelegate i18n = I18nLocalizationsDelegate(
      supportedLocales: [Locale('en', 'US'), Locale('fr', 'FR')],
      pathFile: '{translateDir}',
      haveCountryCode: true
  );

Then you need to configure the supportedLocales, localizationsDelegates and localeResolutionCallback of your MaterialApp or CupertinoApp

  supportedLocales: i18n.supportedLocales,
  localizationsDelegates: [
   i18n,
   GlobalMaterialLocalizations.delegate,
   GlobalWidgetsLocalizations.delegate
  ],
  localeResolutionCallback: (Locale locale, supportedLocales) {
    return i18n.localeResolutionCallback(locale);
  },

Result

// construct the i18nLocalisationsDelegate
final I18nLocalizationsDelegate i18n = I18nLocalizationsDelegate(
      supportedLocales: [Locale('en', 'US'), Locale('fr', 'FR')],
      pathFile: '{translateDir}'
  );
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'MyApp',
        onGenerateRoute: router.generateRoute,
        debugShowCheckedModeBanner: false,
        initialRoute: HomePageRoute,
        // set the supportedLocales for the app
        supportedLocales: i18n.supportedLocales,
        localizationsDelegates: [
         // don't forget to put the delegate
          i18n,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate
        ],
        localeResolutionCallback: (Locale locale, supportedLocales) {
           // get the default local when the device language is not supported, use the first one
          // from the list (English, in this case).
          return i18n.localeResolutionCallback(locale);
        },
    );
  }

Use

To use I18nLocalizations, just call :

I18nLocalizations.translate(context,"keySimple")
I18nLocalizations.translate(context,"key.child_one")
I18nLocalizations.translate(context,"key.child_two.grandchild")

I18nLocalizations.translate(context,"keyParams", params:{"key": "value"})

I18nLocalizations.translatePlural(context,"keyPlural", params:{"key":"6"})
I18nLocalizations.translatePlural(context,"keyPlural", params:{"key":"1"})
I18nLocalizations.translatePlural(context,"keyPlural", params:{"key":"not a number"})

And the json file will look like:

{
  "keySimple": "key simple",
  "key": {
    "child_one": "child 1",
    "child_two": {
      "grandchild": "grandchild of key"
    }
  },
  "keyParams": "keyParams have a params or a {key}",
  "keyPlural": {
    "none": "there are none key here",
    "one": "the value of our key is {key}",
    "many": "we have {key} keys"
  }
}

Note: there should be no space between the key and the parameter hooks

⚠️ Note on iOS

For translation to work on iOS you need to add supported locales to ios/Runner/Info.plist as described here.

Example:

<key>CFBundleLocalizations</key>
<array>
	<string>en</string>
	<string>fr</string>
</array>

카테고리

소스 저장소

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

아직 데이터가 없습니다.