i18n Reference Guide#
Detailed API and syntax reference for slang-based internationalization.
YAML Syntax Reference#
Basic Strings#
common:
appName: ํซ๋ฉ๋
ok: ํ์ธ
cancel: ์ทจ์
save: ์ ์ฅ
loading: ๋ก๋ฉ ์ค...
Nested Structure#
auth:
login:
title: ๋ก๊ทธ์ธ
button: ๋ก๊ทธ์ธํ๊ธฐ
error: ๋ก๊ทธ์ธ์ ์คํจํ์ต๋๋ค
signup:
title: ํ์๊ฐ์
button: ๊ฐ์
ํ๊ธฐ
Parameters (Placeholders)#
user:
greeting: ' $name๋, ์๋
ํ์ธ์! '
points: ' $count ํฌ์ธํธ ๋ณด์ '
joinDate: ' $date์ ๊ฐ์
'
Dart Usage:
context.t.user.greeting(name: 'John')
context.t.user.points(count: '100')
Pluralization#
items:
count(param=n):
zero: ํญ๋ชฉ ์์
one: ํญ๋ชฉ 1๊ฐ
other: ํญ๋ชฉ $n๊ฐ
cart:
itemCount(param=count):
zero: ์ฅ๋ฐ๊ตฌ๋๊ฐ ๋น์ด์์ต๋๋ค
one: ์ฅ๋ฐ๊ตฌ๋์ ์ํ 1๊ฐ
other: ์ฅ๋ฐ๊ตฌ๋์ ์ํ $count๊ฐ
Dart Usage:
context.t.items.count(n: 0) // "ํญ๋ชฉ ์์"
context.t.items.count(n: 1) // "ํญ๋ชฉ 1๊ฐ"
context.t.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.t.pet.type(context: PetType.dog) // "๊ฐ์์ง"
Rich Text#
terms:
agreement: ' ์ด์ฉ์ฝ๊ด์ ๋์ํฉ๋๋ค. < link > ์์ธํ ๋ณด๊ธฐ < /link > '
Dart Usage:
context.t.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/
โ โโโ translations/
โ โ โโโ strings.i18n.yaml # Base (Korean)
โ โ โโโ strings_en.i18n.yaml # English
โ โโโ src/
โ โโโ translations/
โ โโโ translations.g.dart
โ
โโโ i10n_web/ # Web translations (separate)
โโโ lib/
โโโ translations/
โ โโโ strings.i18n.yaml
โ โโโ strings_en.i18n.yaml
โโโ src/
โโโ translations/
โโโ translations.g.dart
slang.yaml Configuration#
base_locale: ko
fallback_strategy: base_locale
input_directory: lib/translations
input_file_pattern: .i18n.yaml
output_directory: lib/src/translations
output_file_name: translations.g.dart
output_format: single_file
key_case: camel
key_map_case: camel
param_case: camel
string_interpolation: dart
flat_map: false
timestamp: true
statistics: true
Code Usage Reference#
Basic Access#
import 'package:i10n/i10n.dart';
// BuildContext extension
Text(context.t.common.appName)
// Direct access (without context)
final appName = AppLocale.ko.translations.common.appName;
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();
Web Translations (Separate)#
import 'package:i10n_web/i10n_web.dart';
// Web-specific translations
Text(context.wt.common.title)
Command Reference#
Code Generation#
# Generate translation code
melos run generate:locale
# Force regeneration
cd shared/i10n & & dart run slang
GPT Auto-Translation#
# English auto-translation (API key required)
melos run generate:locale:gpt
# 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 strings_en.i18n.yaml |
| Pluralization not working | Syntax error | Verify param=n format |
Code Generation Errors#
| Symptom | Cause | Solution |
|---|---|---|
| YAML parsing error | Indentation error | Standardize to 2 spaces |
| Duplicate key error | Same key exists | Rename the key |
| Parameter error | Missing $ | Use $name 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
user:
profile:
editButton: ํ๋กํ ์์
saveButton: ์ ์ฅ
# โ Bad example
editProfileBtn: ํ๋กํ ์์ # Not using nested structure
user_profile_save: ์ ์ฅ # Using snake_case
Pluralization Handling#
# โ
Handle all cases
notifications:
count(param=n):
zero: ์๋ฆผ ์์
one: ์๋ฆผ 1๊ฐ
other: ์๋ฆผ $n๊ฐ
# โ Incomplete handling
notifications:
count: ' ์๋ฆผ $n๊ฐ ' # 0 and 1 cases not handled
Parameter Documentation#
# โ
Document parameters with comments
user:
# name: User ' s name
greeting: ' $name๋, ์๋
ํ์ธ์! '
# count: Number of points held
points: ' $count ํฌ์ธํธ '