i18n Reference Guide#
Detailed API and syntax reference for slang-based internationalization.
JSON Syntax Reference#
Translation files use the
.i18n.jsonformat withsnake_casekeys and{param}(braces) string interpolation. Seeslang.yamlbelow.
Basic Strings#
{
" common " : {
" app_name " : " Unibook " ,
" ok " : " ํ์ธ " ,
" cancel " : " ์ทจ์ " ,
" save " : " ์ ์ฅ " ,
" loading " : " ๋ก๋ฉ ์ค... "
}
}
Nested Structure#
{
" auth " : {
" login " : {
" title " : " ๋ก๊ทธ์ธ " ,
" button " : " ๋ก๊ทธ์ธํ๊ธฐ " ,
" error " : " ๋ก๊ทธ์ธ์ ์คํจํ์ต๋๋ค "
},
" signup " : {
" title " : " ํ์๊ฐ์
" ,
" button " : " ๊ฐ์
ํ๊ธฐ "
}
}
}
Parameters (Placeholders)#
{
" user " : {
" greeting " : " {name}๋, ์๋
ํ์ธ์! " ,
" points " : " {count} ํฌ์ธํธ ๋ณด์ " ,
" join_date " : " {date}์ ๊ฐ์
"
}
}
Dart Usage:
context.i10n.user.greeting(name: 'John')
context.i10n.user.points(count: '100')
Pluralization#
{
" items " : {
" count(param=n) " : {
" zero " : " ํญ๋ชฉ ์์ " ,
" one " : " ํญ๋ชฉ 1๊ฐ " ,
" other " : " ํญ๋ชฉ {n}๊ฐ "
}
},
" cart " : {
" item_count(param=count) " : {
" zero " : " ์ฅ๋ฐ๊ตฌ๋๊ฐ ๋น์ด์์ต๋๋ค " ,
" one " : " ์ฅ๋ฐ๊ตฌ๋์ ์ํ 1๊ฐ " ,
" other " : " ์ฅ๋ฐ๊ตฌ๋์ ์ํ {count}๊ฐ "
}
}
}
Dart Usage:
context.i10n.items.count(n: 0) // "ํญ๋ชฉ ์์"
context.i10n.items.count(n: 1) // "ํญ๋ชฉ 1๊ฐ"
context.i10n.items.count(n: 5) // "ํญ๋ชฉ 5๊ฐ"
Context-Based#
{
" pet " : {
" type(context=PetType) " : {
" dog " : " ๊ฐ์์ง " ,
" cat " : " ๊ณ ์์ด " ,
" bird " : " ์ " ,
" other " : " ๋ฐ๋ ค๋๋ฌผ "
}
},
" gender " : {
" pronoun(context=Gender) " : {
" male " : " ๊ทธ " ,
" female " : " ๊ทธ๋
" ,
" other " : " ๊ทธ๋ค "
}
}
}
Dart Usage:
context.i10n.pet.type(context: PetType.dog) // "๊ฐ์์ง"
Rich Text#
{
" terms " : {
" agreement " : " ์ด์ฉ์ฝ๊ด์ ๋์ํฉ๋๋ค. < link > ์์ธํ ๋ณด๊ธฐ < /link > "
}
}
Dart Usage:
context.i10n.terms.agreement(
link: (text) => TextSpan(
text: text,
style: TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()..onTap = () => openTerms(),
),
)
File Structure Reference#
Directory Layout#
shared/
โโโ i10n/ # App translations
โโโ lib/
โโโ src/
โโโ json/
โ โโโ ko.i18n.json # Base (Korean)
โ โโโ en.i18n.json # English
โ โโโ ja.i18n.json # Japanese
โ โโโ zh-Hans.i18n.json # Simplified Chinese
โ โโโ de.i18n.json # German
โ โโโ fr.i18n.json # French
โ โโโ es.i18n.json # Spanish
โ โโโ it.i18n.json # Italian
โ โโโ pt.i18n.json # Portuguese
โ โโโ ru.i18n.json # Russian
โ โโโ ar.i18n.json # Arabic
โโโ translations/
โโโ translations.g.dart
slang.yaml Configuration#
base_locale: ko
fallback_strategy: base_locale
input_directory: lib/src/json
input_file_pattern: .i18n.json
output_directory: lib/src/translations
output_file_name: translations.g.dart
output_format: single_file
key_case: snake
key_map_case: snake
param_case: snake
string_interpolation: braces
flat_map: false
timestamp: true
statistics: true
translate_var: translations
Code Usage Reference#
Basic Access#
// context.i10n extension is provided by package:core (not package:i10n)
import 'package:core/core.dart';
// BuildContext extension
Text(context.i10n.common.app_name)
// Direct access (without context) โ translate_var is `translations`
final appName = AppLocale.ko.translations.common.app_name;
App Configuration#
MaterialApp(
locale: TranslationProvider.of(context).flutterLocale,
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: GlobalMaterialLocalizations.delegates,
)
Locale Switching#
// Change locale
LocaleSettings.setLocale(AppLocale.en);
// Check current locale
final currentLocale = LocaleSettings.currentLocale;
// Use system locale
LocaleSettings.useDeviceLocale();
Command Reference#
Code Generation#
# Generate translation code (melos โ dart run slang)
melos run generate:locale
# Force regeneration directly
cd shared/i10n & & dart run slang
GPT Auto-Translation#
# Translate base locale โ all locales
melos run translate:slang
# Variants
melos run translate:en # English only
melos run translate:incremental # only missing keys
melos run translate:full # full re-translation
melos run translate:all # all locales
melos run translate:fix # fix/repair pass
# Direct execution
cd shared/i10n & & dart run slang_gpt
Analysis#
# Check for missing translations
dart run slang analyze
# Output statistics
dart run slang analyze --stats
Troubleshooting#
Translations Not Applied#
| Symptom | Cause | Solution |
|---|---|---|
| Key not found error | Code not generated | Run melos run generate:locale |
| English not displayed | English file missing | Check en.i18n.json |
| Pluralization not working | Syntax error | Verify param=n format |
Code Generation Errors#
| Symptom | Cause | Solution |
|---|---|---|
| JSON parsing error | Invalid JSON | Validate trailing commas / quotes |
| Duplicate key error | Same key exists | Rename the key |
| Parameter error | Wrong delimiters | Use {name} (braces) format |
GPT Translation Errors#
| Symptom | Cause | Solution |
|---|---|---|
| API error | Missing key | Set OPENAI_API_KEY environment variable |
| Low translation quality | Lack of context | Provide hints via comments |
Best Practices#
Key Naming#
// โ
Good example: nested structure + snake_case
{
" user " : {
" profile " : {
" edit_button " : " ํ๋กํ ์์ " ,
" save_button " : " ์ ์ฅ "
}
}
}
// โ Bad example
{
" editProfileBtn " : " ํ๋กํ ์์ " , // camelCase, not nested
" user_profile_save " : " ์ ์ฅ " // flat instead of nested
}
Pluralization Handling#
// โ
Handle all cases
{
" notifications " : {
" count(param=n) " : {
" zero " : " ์๋ฆผ ์์ " ,
" one " : " ์๋ฆผ 1๊ฐ " ,
" other " : " ์๋ฆผ {n}๊ฐ "
}
}
}
// โ Incomplete handling
{
" notifications " : {
" count " : " ์๋ฆผ {n}๊ฐ "
}
}
Parameter Notes#
JSON files do not support comments, so document parameters in the PR / key design notes. Parameter names must be identical across all locale files.
{
" user " : {
" greeting " : " {name}๋, ์๋
ํ์ธ์! " ,
" points " : " {count} ํฌ์ธํธ "
}
}