LogoSkills

i18n Conventions

This project uses the **slang** package for internationalization (i18n).

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.

PackageExtensionUsage
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:i10n was removed in PR #2079. Previously, both packages provided context.i10n, causing ambiguous_extension_member_access errors.

Available APIs#

APIStatusDescription
context.i10n โœ… Standard Used across the entire project
context.translationsโŒ Do not useExists 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#

PatternExampleDescription
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#

  1. When adding new keys: Must add to all language JSON files
  2. Key naming: Always use snake_case
  3. Code generation: Run dart run slang after modifying JSON files
  4. API selection: Use only context.i10n (translations is prohibited)
  5. Parameter format: Use $param format (curly braces {param} are prohibited)
    • โœ… "greeting": "์•ˆ๋…•ํ•˜์„ธ์š”, $name๋‹˜!"
    • โŒ "greeting": "์•ˆ๋…•ํ•˜์„ธ์š”, {name}๋‹˜!" (causes errors)
  6. Parameter name consistency: Use the same parameter names across all language files
    • Example: $maxSizeMB (must be identical in all languages)