This project uses the slang package for internationalization (i18n).
Translation Access API#
Project Standard: context.i10n#
// โ
CORRECT: Import from package:core (standard)
import 'package:core/core.dart'; // Includes BuildContextExt
final translations = context.i10n.console.sample_book;
Text(context.i10n.common.save)
// โ WRONG: Do not import directly from package:i10n
import 'package:i10n/i10n.dart'; // Causes extension conflict!
// โ WRONG: Do not use context.translations
final translations = context.translations.console.sample_book; // Do not use
Statistics: context.i10n 389 occurrences vs context.translations
1 occurrence (legacy)
โ ๏ธ Extension Conflict Warning (ambiguous_extension_member_access)#
The context.i10n extension is provided only from package:core.
| Package | Extension | Usage |
|---|---|---|
package:core/core.dart |
BuildContextExt.i10n |
โ Standard |
package:i10n/i10n.dart | - | โ No extension |
Import Rules:
// โ
CORRECT: Import only core
import 'package:core/core.dart';
// โ
CORRECT: When only the extension is needed
import 'package:core/core.dart' show BuildContextExt;
// โ ๏ธ Note: i10n package does not provide an extension
// It only exports slang translation files and LocalizationsDelegate
import 'package:i10n/i10n.dart';
Note: The duplicate extension from
package:i10nwas removed in PR #2079. Previously, both packages providedcontext.i10n, causingambiguous_extension_member_accesserrors.
Available APIs#
| API | Status | Description |
|---|---|---|
context.i10n |
โ Standard | Used across the entire project |
context.translations | โ Do not use | Exists only in legacy code |
JSON Key Naming Conventions#
Use snake_case (Required)#
// โ
CORRECT: Use snake_case
{
" console " : {
" sample_book " : {
" user_status " : {
" active " : " ํ์ฑ " ,
" inactive " : " ๋นํ์ฑ "
}
}
}
}
// โ WRONG: Do not use camelCase
{
" console " : {
" sampleBook " : { // Incorrect!
" userStatus " : { // Incorrect!
" active " : " ํ์ฑ "
}
}
}
}
Key Naming Patterns#
| Pattern | Example | Description |
|---|---|---|
| Feature name | sample_book, sales_analysis |
Feature module name |
| Action | create, update, delete |
CRUD actions |
| State | loading, error, success |
State messages |
| Error | invalid_date_range, not_found |
Error messages |
JSON File Structure#
File Locations#
shared/i10n/lib/src/json/
โโโ ko.i18n.json # Korean (base)
โโโ 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
Hierarchy#
{
" common " : {
" save " : " ์ ์ฅ " ,
" cancel " : " ์ทจ์ " ,
" confirm " : " ํ์ธ "
},
" console " : {
" sample_book " : { ... },
" sales_analysis " : {
" period " : {
" all " : " ์ ์ฒด " ,
" today " : " ์ค๋ " ,
" yesterday " : " ์ด์ " ,
" last7_days " : " ์ต๊ทผ 7์ผ " ,
" this_week " : " ์ด๋ฒ ์ฃผ " ,
" this_month " : " ์ด๋ฒ ๋ฌ " ,
" last_month " : " ์ง๋ ๋ฌ " ,
" custom " : " ๊ธฐ๊ฐ ์ ํ " ,
" invalid_date_range " : " ์ข
๋ฃ์ผ์ ์์์ผ ์ดํ์ฌ์ผ ํฉ๋๋ค "
}
}
},
" main " : { ... }
}
Translation Code Generation#
After Modifying Translation Files#
# Regenerate translation code
cd shared/i10n & & dart run slang
# Or use melos command
melos run generate:locale
Generated Files#
shared/i10n/lib/src/translations/
โโโ translations.g.dart # Base interface
โโโ translations_ko.g.dart # Korean
โโโ translations_en.g.dart # English
โโโ ... (files for each language)
Usage Examples#
Simple Text#
Text(context.i10n.common.save)
Text(context.i10n.console.sales_analysis.period.all)
Parameterized Translations#
// JSON definition (using $ format)
// "greeting": "์๋
ํ์ธ์, $name๋!"
// Dart usage
Text(context.i10n.common.greeting(name: user.name))
Pluralization#
// JSON definition (using $ format)
// "items": {
// "one": "$count๊ฐ ํญ๋ชฉ",
// "other": "$count๊ฐ ํญ๋ชฉ๋ค"
// }
// Dart usage
Text(context.i10n.common.items(count: items.length))
Important Notes#
- When adding new keys: Must add to all language JSON files
- Key naming: Always use snake_case
- Code generation: Run
dart run slangafter modifying JSON files - API selection: Use only
context.i10n(translations is prohibited) -
Parameter format: Use
$paramformat (curly braces{param}are prohibited)- โ
"greeting": "์๋ ํ์ธ์, $name๋!" - โ
"greeting": "์๋ ํ์ธ์, {name}๋!"(causes errors)
- โ
-
Parameter name consistency: Use the same parameter names across all language files
- Example:
$maxSizeMB(must be identical in all languages)
- Example:
Related Documentation#
- CLAUDE.md - Overall project guide
- Slang Official Documentation