i18next는 i18next 표준을 기반으로 한 로컬라이제이션 포맷팅을 제공하는 플러터/다트 패키지입니다. 국제화의 포맷팅 측면에 초점을 맞추어 자리표시자와 복수형을 포함한 구조화된 번역 처리를 가능하게 합니다. 완전한 기능을 갖춘 i18n 솔루션이 아니지만, 다양한 플랫폼 간 일관된 텍스트 포맷팅을 지원합니다. 표준화된 로컬라이제이션 패턴이 필요한 개발자를 위한 것으로, 기존 워크플로우와 잘 통합됩니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux와 호환됩니다.
사용 사례
플레이스홀더를 사용하여 번역된 문자열 형식 지정
번역에서 복수 형태 다루기
다국어 앱 콘텐츠 지원
i18next 기반 백엔드 시스템과의 통합
동적 메시지 렌더링 간소화
주요 기능
i18next 표준 준수
플레이스홀더 및 복수형 지원
크로스 플랫폼 호환성
경량 포맷팅 엔진
기존 번역 파일과의 간편한 통합
적합한 대상
구조화된 로컬라이제이션을 필요로 하는 앱
i18next에 익숙한 개발자
외부 번역 관리 사용 프로젝트
다양한 플랫폼 간에 일관된 형식을 유지해야 하는 팀
프론트엔드 중심의 국제화
고려 사항
완전한 i18n 도구를 포함하지 않습니다
외부 번역 파일 관리가 필요합니다
포맷팅에만 제한됨, 로케일 로드 또는 전환은 포함되지 않음
복잡한 i18n 워크플로우에 적합하지 않습니다
번역 리소스의 올바른 설정에 달려 있음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
i18next
This is an adaptation of i18next standard for Dart with support for Flutter localization techniques. This package is still a work in progress.
Mind that this is still a pre-1.0.0 so breaking changes may occur frequently.
[x] Support for variables
[x] Support for namespaces
[x] Support for context
[x] Support for simple plural forms (one or plural)
[x] Support for multiple plural forms (one, few, many, plural, ...)
[x] Plural and context fallbacks
[x] Locale and namespace fallbacks
[x] Get string or object tree
[x] Support for nesting
[x] Flutter's LocalizationsDelegate support
[x] Asset bundle localizations data source (retrieves from pubspec.yaml). See the example for more details.
[ ] Sprintf support
[ ] Resource caching
[ ] Custom post-processing
[ ] ~Retrieve resource files from server~ (won't do, see https://github.com/williamhjcho/i18next/issues/27)
Usage
Simples way to add the latest version is to run flutter pub add i18next
Or you can declare it directly into your pubspec.yaml file:
dependencies:i18next:^0.9.0# (or the latest version available)
To use it with flutter's LocalizationsDelegate you first create I18NextLocalizationDelegate and register it in your WidgetsApp (MaterialApp or CupertinoApp).
I18NextLocalizationDelegate(
locales: widget.locales,
// this data source is from where the delegate will retrieve the localizations from (namespaces Map)
dataSource: ...,
// optional extra options can be added here
options: I18NextOptions(...),
),
Then to access and use it, simply call
Widgetbuild(BuildContext context) {
// It finds the i18next instance on the widgets tree via `Localizations.of`I18Next.of(context).t(...);
...
}
But if you want to handle it yourself, then simply instantiate it:
I18Next(
locale,
// This store is from where i18next will attempt to retrieve the localizations from.
resourceStore: ...,
// Optional extra options can be added here
options: I18NextOptions(...)
);
{"key1":"{{text, uppercase}} just uppercased","key2":"The current date is {{now, datetime(format:dd/MM/yyyy)}}","key3":"Right now we are in {{now, datetime(format:MMM), uppercase}}."}
i18next.t('key1', arguments: { 'text': 'my text' }); // 'MY TEXT just uppercased'
i18next.t('key2', arguments: { 'now': DateTime.now() }); // 'The current date is 21/01/2020'
i18next.t('key3', arguments: { 'now': DateTime.now() }); // 'Right now we are in JAN.'
There are other usages and possibilities as well, this is just an example of what is defined by this format.
Namespaces: A namespace can be thought of as logical groupings of different sets of translations. In a given namespace you could have a set of languages, each with their own set of keys. They can also be understood as separate files.
For example:
common.json: Things that are reused everywhere, eg. Button labels 'save', 'cancel'
validation.json: All validation texts
glossary.json: Words we want to be reused consistently inside texts
// common.json{"myKey":"This key is in common"}// feature.json{"myKey":"This key is in my feature"}
i18next.t('common:myKey'); // 'This key is in common'
i18next.t('feature:myKey'); // 'This key is in my feature'
i18next.t('friend'); // 'A friend'
i18next.t('friend', count: 1); // 'A friend'// It fallbacks to `friend` since `friend_plural` is not present
i18next.t('friend', count: 2); // 'A friend'
i18next.t('friend', context: 'female'); // 'A girlfriend'// It fallbacks to `friend` since `friend_male` is not present
i18next.t('friend', context: 'male'); // 'A friend'
There is a way to also set the default namespace or a order of namespaces so a key knows where to start looking for the translation.