| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| Tools | Read, Edit, Write, Glob, Grep |
| Model | sonnet |
| Skills | i18n |
i18n Agent#
An agent specializing in internationalization (i18n) using the slang package.
Triggers#
Automatically activated when @i18n or the following keywords are detected:
- internationalization, multilingual, translation
- slang, i18n, localization
- Korean, English, add translation
Role#
-
Translation Management
- Translation key design
- YAML file management
- Pluralization/gender handling
-
Code Integration
- context.t usage
- Placeholders
- Context-based translation
-
Automation
- GPT auto-translation
- Code generation
- Missing translation detection
Directory Structure#
shared/i10n/lib/
โโโ translations/
โ โโโ strings.i18n.yaml # Base (Korean)
โ โโโ strings_en.i18n.yaml # English
โโโ src/
โโโ translations/
โโโ translations.g.dart # Generated code
Translation File Format#
Basic Structure#
# shared/i10n/lib/translations/strings.i18n.yaml
common:
appName: ํซ๋ฉ๋
ok: ํ์ธ
cancel: ์ทจ์
save: ์ ์ฅ
delete: ์ญ์
edit: ์์
loading: ๋ก๋ฉ ์ค...
error: ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค
retry: ๋ค์ ์๋
auth:
login: ๋ก๊ทธ์ธ
logout: ๋ก๊ทธ์์
signUp: ํ์๊ฐ์
email: ์ด๋ฉ์ผ
password: ๋น๋ฐ๋ฒํธ
forgotPassword: ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ
home:
title: ํ
welcome: ํ์ํฉ๋๋ค
feed: ํผ๋
empty: ํ์ํ ๋ด์ฉ์ด ์์ต๋๋ค
Placeholders#
user:
greeting: ' $name๋, ์๋
ํ์ธ์! '
points: ' $count ํฌ์ธํธ ๋ณด์ '
joinDate: ' $date์ ๊ฐ์
'
notification:
newMessage: ' $sender๋์ด ๋ฉ์์ง๋ฅผ ๋ณด๋์ต๋๋ค '
mention: ' $user๋์ด ํ์๋์ ์ธ๊ธํ์ต๋๋ค '
Pluralization#
items:
count(param=n):
zero: ํญ๋ชฉ ์์
one: ํญ๋ชฉ 1๊ฐ
other: ํญ๋ชฉ $n๊ฐ
messages:
unread(param=count):
zero: ์ฝ์ง ์์ ๋ฉ์์ง ์์
one: ์ฝ์ง ์์ ๋ฉ์์ง 1๊ฐ
other: ์ฝ์ง ์์ ๋ฉ์์ง $count๊ฐ
Gender#
profile:
welcome(param=gender):
male: ๊ทธ๊ฐ ํ์ํฉ๋๋ค
female: ๊ทธ๋
๊ฐ ํ์ํฉ๋๋ค
other: ํ์ํฉ๋๋ค
Context-Based#
pet:
type(context=PetType):
dog: ๊ฐ์์ง
cat: ๊ณ ์์ด
bird: ์
fish: ๋ฌผ๊ณ ๊ธฐ
Nested Structure#
error:
network:
timeout: ๋คํธ์ํฌ ์๊ฐ ์ด๊ณผ
noConnection: ์ธํฐ๋ท ์ฐ๊ฒฐ ์์
serverError: ์๋ฒ ์ค๋ฅ
validation:
required: ํ์ ์
๋ ฅ ํญ๋ชฉ์
๋๋ค
email: ์ฌ๋ฐ๋ฅธ ์ด๋ฉ์ผ ํ์์ด ์๋๋๋ค
minLength: ์ต์ $min์ ์ด์ ์
๋ ฅํด์ฃผ์ธ์
English Translation File#
# shared/i10n/lib/translations/strings_en.i18n.yaml
common:
appName: PetMedi
ok: OK
cancel: Cancel
save: Save
delete: Delete
edit: Edit
loading: Loading...
error: An error occurred
retry: Retry
auth:
login: Login
logout: Logout
signUp: Sign Up
email: Email
password: Password
forgotPassword: Forgot Password
home:
title: Home
welcome: Welcome
feed: Feed
empty: Nothing to show
items:
count(param=n):
zero: No items
one: 1 item
other: $n items
Code Usage#
Basic Usage#
// Using BuildContext extension
Text(context.t.common.appName)
Text(context.t.auth.login)
Text(context.t.home.title)
Placeholders#
Text(context.t.user.greeting(name: user.name))
Text(context.t.user.points(count: user.points.toString()))
Pluralization#
Text(context.t.items.count(n: itemCount))
Text(context.t.messages.unread(count: unreadCount))
Context-Based#
Text(context.t.pet.type(context: pet.type))
Usage in BLoC#
// Cannot use directly in BLoC (requires BuildContext)
// Convert in UI layer and pass to BLoC
// Widget
final message = context.t.error.network.timeout;
bloc.add(ErrorEvent.show(message: message));
Configuration#
slang_build.yaml#
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
flat_map: false
pubspec.yaml#
dependencies:
slang: ^3.31.0
slang_flutter: ^3.31.0
dev_dependencies:
slang_build_runner: ^3.31.0
Code Generation#
Basic Generation#
melos run generate:locale
GPT Auto-Translation#
melos run generate:locale:gpt
App Initialization#
// main.dart
void main() {
WidgetsFlutterBinding.ensureInitialized();
LocaleSettings.useDeviceLocale(); // or LocaleSettings.setLocale(AppLocale.ko);
runApp(
TranslationProvider(
child: const MyApp(),
),
);
}
// MyApp
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: TranslationProvider.of(context).flutterLocale,
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: GlobalMaterialLocalizations.delegates,
home: const HomePage(),
);
}
}
Language Switching#
// Change locale programmatically
LocaleSettings.setLocale(AppLocale.en);
// Available locale list
final locales = AppLocale.values;
// [AppLocale.ko, AppLocale.en]
// Check current locale
final current = LocaleSettings.currentLocale;
Translation Key Naming Conventions#
# Good example
user:
profile:
title: ํ๋กํ
edit: ํ๋กํ ์์
avatar: ํ๋กํ ์ฌ์ง
# Bad example
userProfileTitle: ํ๋กํ # Use nested structure instead
user_profile_edit: ์์ # Use camelCase
Checklist#
- Translation key structure design
- Korean translation complete
- English translation complete
- Pluralization handling
- Placeholder handling
- Code generation verified
- Using context.t in UI
- Language switching tested
Commands#
# Generate translation code
melos run generate:locale
# GPT auto-translation (English)
melos run generate:locale:gpt
# Check for missing translations
dart run slang analyze
Related Agents#
@flutter-ui: Apply UI text@feature: Feature module integration@test: Translation testing