string_extractor_intl
एक फ्लटर पैकेज जो कठोर तारांकित स्ट्रिंग्स को निकालता है और डार्ट फ़ाइलों या lib निर्देशिका से .arb फ़ाइलों का उत्पादन करता है, जिसका उपयोग अंतरराष्ट्रीयकरण (i18n) में किया जा सकता है।
intl और flutter अंतर्राष्ट्रीयकरण पैकेज के साथ उपयोग करने के लिए एक पैकेज, जो प्रोजेक्ट में हार्डकोडेड स्ट्रिंग्स से arb फ़ाइल बनाता है
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
🌍 A powerful command-line tool that automatically extracts hardcoded strings from your Flutter project and generates ARB files for internationalization (i18n) and localization (l10n).
Add this package as a dev dependency in your pubspec.yaml:
dev_dependencies:
string_extractor_intl: ^1.0.3
Then run:
flutter pub get
Your Flutter project must have these dependencies in pubspec.yaml:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.19.0
The following section is specific to Flutter packages. for future generation
flutter:
uses-material-design: true
generate: true
Extract strings and generate ARB files without modifying your source code:
dart pub run string_extractor_intl:extract_strings
Extract and replace in files:
dart pub run string_extractor_intl:extract_strings --replace
Custom configuration:
dart pub run string_extractor_intl:extract_strings \
--input lib/presentation \
--output assets/l10n \
--template-arb strings_en.arb \
--class-name MyLocalizations \
--replace
Show help:
dart pub run string_extractor_intl:extract_strings --help
| Option | Short | Default | Description |
|---|---|---|---|
--input |
-i |
lib/presentation |
Input directory to scan |
--output |
-o |
lib/l10n |
Output directory for localization files |
--template-arb |
app_en.arb |
Template ARB file name | |
--class-name |
-c |
AppLocalizations |
Name of the localization class |
--replace |
-r |
false |
Replace hardcoded strings with localization calls |
--check-deps |
true |
Check for required dependencies | |
--help |
-h |
Show usage information |
dart pub run string_extractor_intl:extract_strings \ --input lib/presentation \
READ THIS CAREFULLY BEFORE USING THE --replace OPTION:
--replaceAfter running with --replace, you MUST run these commands:
# Install/update dependencies
flutter pub get
# Generate localization files
flutter gen-l10n
The tool scans your Dart files and identifies hardcoded strings, excluding:
Automatically detects variables in strings:
"Hello $_name" → S.of(context).hello('$_name')"Count: ${count}" → S.of(context).count('$count')Creates structured ARB files with:
When using --replace:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
home: Scaffold(
appBar: AppBar(title: Text('Welcome')),
body: Text('Hello $_username!'),
),
);
}
}
import 'l10n/generated/app_localizations.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: S.localizationsDelegates,
supportedLocales: S.supportedLocales,
title: S.of(context).myApp,
home: Scaffold(
appBar: AppBar(title: Text(S.of(context).welcome)),
body: Text(S.of(context).hello('$_username')),
),
);
}
}
{
"@@locale": "en",
"hello": "Hello {username}!",
"@hello": {
"description": "Localized string with parameters: username",
"placeholders": {
"username": {
"type": "String",
"example": "John"
}
}
},
"myApp": "My App",
"@myApp": {
"description": "Localized string"
},
"welcome": "Welcome",
"@welcome": {
"description": "Localized string"
}
}
The tool creates several files:
lib/l10n/app_en.arb) - Contains extracted strings--replace)Add additional language ARB files:
lib/l10n/app_es.arb (Spanish)
lib/l10n/app_fr.arb (French)
lib/l10n/app_de.arb (German)
Run Flutter's localization generator:
flutter gen-l10n
Import and use in your app:
import 'l10n/generated/app_localizations.dart';
// In your MaterialApp
MaterialApp(
localizationsDelegates: S.localizationsDelegates,
supportedLocales: S.supportedLocales,
// ...
)
For more details, read this article.
"pubspec.yaml not found"
"Missing required dependencies"
intl and flutter_localizations to your pubspec.yamlflutter pub getGenerated strings not accessible
flutter gen-l10n after generating ARB filesl10n.yaml exists in your project rootCompilation errors after replacement
flutter pub get and flutter gen-l10n--replace) to review stringsContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
Happy Localizing! 🌍