LogoSkills

i18n Reference

Detailed API and syntax reference for slang-based internationalization.

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#

SymptomCauseSolution
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 workingSyntax errorVerify param=n format

Code Generation Errors#

SymptomCauseSolution
YAML parsing errorIndentation errorStandardize to 2 spaces
Duplicate key errorSame key existsRename the key
Parameter errorMissing $Use $name format

GPT Translation Errors#

SymptomCauseSolution
API errorMissing keySet OPENAI_API_KEY environment variable
Low translation qualityLack of contextProvide 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 ํฌ์ธํŠธ '