LocalizationBuilder는 Flutter 패키지로, 로컬라이제이션 데이터 클래스의 생성과 관리를 간소화하기 위해 설계되었습니다. 전자 스프레드시트나 JSON 파일과 같은 로컬라이제이션 소스에서 타입 안전하고 구조화된 코드를 생성하여 반복적인 코드를 줄이고 국제화 앱에서 발생할 수 있는 오류를 최소화합니다. 빌더는 다양한 언어 간 일관성을 보장하며, 로컬라이제이션 키와 해당 값의 자동 생성을 통해 번역 워크플로우를 단순화합니다. 여러 언어 버전을 관리하는 팀에게 이상적이며, 다국어 애플리케이션의 유지보수성과 확장성을 향상시킵니다.
사용 사례
스프레드시트에서 로컬라이제이션 키 생성
번역 파일 생성 자동화
일관된 키 이름 유지
팀 기반 번역 워크플로우 지원
다국어 앱 개발 간소화
주요 기능
유형 안전한 로컬라이제이션 클래스를 자동으로 생성합니다
스프레드시트 기반 번역 소스와 통합됩니다
수동 키 관리 감소
일관된 키 구조를 보장합니다
다양한 출력 형식을 지원합니다
적합한 대상
다국어 앱을 개발하는 개발자
외부 번역 도구를 사용하는 팀
확장 가능한 현지화가 필요한 프로젝트
자주 언어가 업데이트되는 앱
코드 품질과 일관성을 우선시하는 팀
고려 사항
소스 데이터 형식 설정이 필요합니다
번역을 위해 외부 도구에 의존합니다
복잡한 구조에 대해 사용자 지정 구성이 필요할 수 있습니다
중앙 집중식 번역 관리가 필요한 프로젝트에 가장 적합
간단한 단일 언어 앱에는 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Flutter Google Sheet localizations generator
Generates a localizations delegate from an online Google Sheet file.
Extract from the link the DOCID and SHEETID values : https://docs.google.com/spreadsheets/d/<DOCID>/edit#gid=<SHEETID>) :
2. Declare a localization delegate
Declare the following AppLocalizationsDelegate class with the SheetLocalization annotation pointing to your sheet in a lib/localization.dart file :
import'package:flutter/widgets.dart';
import'package:flutter/foundation.dart';
import'package:flutter_sheet_localization/flutter_sheet_localization.dart';
part'localization.g.dart';
@SheetLocalization("DOCID", "SHEETID", 1) // <- See 1. to get DOCID and SHEETID// the `1` is the generated version. You must increment it each time you want to regenerate// a new version of the labels.classAppLocalizationsDelegateextendsLocalizationsDelegate<AppLocalizationsData> {
constAppLocalizationsDelegate();
@overrideboolisSupported(Locale locale) => localizedLabels.containsKey(locale);
@overrideFuture<AppLocalizationsData> load(Locale locale) =>
SynchronousFuture<AppLocalizationsData>(localizedLabels[locale]!);
@overrideboolshouldReload(AppLocalizationsDelegate old) => false;
}
3. Generate your localizations
Run the following command to generate a lib/localization.g.dart file :
flutter packages pub run build_runner build
4. Configure your app
Update your Flutter app with your newly created delegate :
final labels = AppLocalizations.of(context);
print(labels.dates.month.february);
print(labels.templated.hello(firstName: "World"));
print(labels.templated.contact(Gender.male, lastName: "John"));
Regeneration
Because of the caching system of the build_runner, it can't detect if there is a change on the distant sheet and it can't know if a new generation is needed.
The version parameter of the @SheetLocalization annotation solves this issue.
Each time you want to trigger a new generation, simply increment that version number and call the build runner again.
then each supported language code ("en", "fr", ...)
Following rows for labels
Column 0 : the label key (can be a hierarchy, separated by dots)
then each translation based on language code of the column
Ignoring a column
Sometimes you may need to add comments for translators. For this, simply add a column with a name between parenthesis and the column will be completely ignored by the generator.
Example :
Key
(Comments)
fr
en
example.man(Gender.male)
This is a man title on home page
homme
man
example.man(Gender.female)
This is a woman title on home page
femme
woman
Conditionals
It is pretty common to have variants of a label based on a condition (for example: Genders, Plurals, ...).
Simply duplicate your entries and end them with (<ConditionName>.<ConditionCase).
You can also add one of the compatible types (int, double, num, DateTime) to the parameter by suffixing its key with :<type>.
/// Sheet
values.price, "The price is {{price:double}}\$"/// Codeprint(labels.values.price(price: 10.5));
Formatted parameters
You can indicate how the templated value must be formatted by ending the value with a formatting rule in brackets [<rule-key>]. This can be particulary useful for typed parameters.
The available formatting rules depend on the type and generally rely on the intl package.
I find the Flutter internationalization tools not really easy to use, and I wanted a simple tool for sharing translations. Most solutions also use string based keys, and I wanted to generate pure dart code to improve permormance.