LogoSkills

slang-i18n Reference

Detailed API and syntax reference for slang-based internationalization.

i18n Reference Guide#

Detailed API and syntax reference for slang-based internationalization.

JSON Syntax Reference#

Translation files use the .i18n.json format with snake_case keys and {param} (braces) string interpolation. See slang.yaml below.

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#

SymptomCauseSolution
Key not found error Code not generated Run melos run generate:locale
English not displayedEnglish file missingCheck en.i18n.json
Pluralization not workingSyntax errorVerify param=n format

Code Generation Errors#

SymptomCauseSolution
JSON parsing errorInvalid JSONValidate trailing commas / quotes
Duplicate key errorSame key existsRename the key
Parameter errorWrong delimitersUse {name} (braces) 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: 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} ํฌ์ธํŠธ " 
   }
}