Loading...
Loading...
Configures a Flutter app to support multiple languages and regions. Use when preparing an application for international markets and diverse user locales.
npx skill4agent add flutter/skills flutter-localizing-appspubspec.yamldependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: any
flutter:
generate: true # Required for l10n code generationl10n.yamlgen-l10narb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
# Optional: Set to false to generate files into lib/ instead of the synthetic package
# synthetic-package: false .arbarb-dirlib/l10n/app_en.arb{
"helloWorld": "Hello World!",
"@helloWorld": {
"description": "The conventional newborn programmer greeting"
}
}lib/l10n/app_es.arb{
"helloWorld": "¡Hola Mundo!"
}LocalizationsMaterialAppCupertinoAppimport 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; // Adjust import if synthetic-package is false
return MaterialApp(
title: 'Localized App',
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en'), // English
Locale('es'), // Spanish
],
home: const MyHomePage(),
);AppLocalizationsText(AppLocalizations.of(context)!.helloWorld)WidgetsAppMaterialAppGlobalMaterialLocalizations.delegate@key"hello": "Hello {userName}",
"@hello": {
"description": "A message with a single parameter",
"placeholders": {
"userName": {
"type": "String",
"example": "Bob"
}
}
}"nWombats": "{count, plural, =0{no wombats} =1{1 wombat} other{{count} wombats}}",
"@nWombats": {
"placeholders": {
"count": {
"type": "num",
"format": "compact"
}
}
}"pronoun": "{gender, select, male{he} female{she} other{they}}",
"@pronoun": {
"placeholders": {
"gender": {
"type": "String"
}
}
}formatoptionalParametersintl"dateMessage": "Date: {date}",
"@dateMessage": {
"placeholders": {
"date": {
"type": "DateTime",
"format": "yMd"
}
}
}.arbarb-dirapp_fr.arb.arbLocalesupportedLocalesMaterialAppflutter gen-l10nAppLocalizationsios/Runner.xcodeprojRunnerInfo+project.pbxprojTextFieldCupertinoTabBarLocalizationsMaterialLocalizationsCupertinoLocalizationsNo MaterialLocalizations found.CupertinoTabBar requires a Localizations parent...MaterialAppCupertinoAppWidgetsAppLocalizationsLocalizations(
locale: const Locale('en', 'US'),
delegates: const [
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate, // Required for TextField
DefaultCupertinoLocalizations.delegate, // Required for CupertinoTabBar
],
child: child,
)Locale.fromSubtagsscriptCodecountryCodesupportedLocales: const [
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN'),
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'),
]