i18n_extension_core
Dart 전용 번역 및 국제화(i18n) 패키지, Dart 확장 기능 포함. 대규모 및 소규모 프로젝트 모두 사용하기 쉬움.
i18n_extension 패키지용 핵심 Dart 전용 패키지입니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
This is the core Dart-only package for the i18n_extension package.
Do NOT include this core package directly.
Instead, go to the i18n_extension package
which already exports this core code, plus provides Flutter related code like the I18n
widget that you must use to wrap your widget tree.
If you are working on a Dart server-side application (backend) using frameworks such as Serverpod, Dart Frog, or Shelf, or developing a Dart-only package that does not rely on Flutter, you can use this package directly.:
import 'package:i18n_extension_core/i18n_extension_core.dart';
extension Localization on String {
static var t = Translations.byText("en_us") + {"en_us":"Hello", "pt_br":"Hola"};
String get i18n => localize(this, t);
}
DefaultLocale.set("es_ES");
expect("Hello".i18n, "Hola");
Note: One key use case is translating exception messages from the backend to the frontend. For example, if the backend throws an exception like:
MyException('The password you typed is invalid'.i18n)it will automatically appear on the frontend as:MyException('La contraseña que ingresaste no es válida')if the user's device language is set to Spanish.
Go to i18n_extension to read the docs.
There are only 2 differences when using this package directly:
Here you don't have access to the I18n widget, which is a Flutter widget.
The way to set the default locale is different. Instead of using the I18n widget, you
must use the DefaultLocale.set() static method, like in the example above.
glasberg.dev
github.com/marcglasberg
linkedin.com/in/marcglasberg/
twitter.com/glasbergmarcelo
stackoverflow.com/users/3411681/marcg
medium.com/@marcglasberg
My article in the official Flutter documentation:
The Flutter packages I've authored:
My Medium Articles: