Aus öffentlichen Paketdaten erstellte Orientierung.
Eine Sammlung von Hilfsprogrammen, die darauf ausgelegt sind, die Arbeit mit .arb-Dateien in Flutter-Anwendungen zu vereinfachen und eine effiziente Verwaltung von Internationalisierung und Lokalisierung zu ermöglichen. Es unterstützt das Parsen, Validieren und Konvertieren von Arb-Dateien, wodurch die Pflege von Übersetzungen in mehreren Sprachen erleichtert wird. Das Paket integriert sich nahtlos in den Dart-i18n-Arbeitsablauf und steigert die Produktivität von Entwicklern durch Automatisierung wiederholter Aufgaben im Zusammenhang mit Übersetzungsdateien. Besonders nützlich für Teams, die große multilinguale Anwendungen verwalten.
Anwendungsfälle
Verwaltung von Übersetzungsdateien in Flutter-Apps
Konvertieren zwischen ARB und anderen Formaten
Überprüfung von Übersetzungs-Schlüsseln
Automatisierung von Lokalisierungsarbeitsabläufen
Code aus ARB-Dateien generieren
Hauptmerkmale
Unterstützt die Analyse und Überprüfung von ARB-Dateien
Konvertiert ARB in JSON und andere Formate
Integration mit Flutter's i18n-System
Befehlszeilen-Schnittstelle für Automatisierung
Stellt eine konsistente Schlüsselbenennung und Struktur sicher
Geeignet für
Flutter-Entwickler, die ARB für die Lokalisierung verwenden
Teams, die mehrsprachige Übersetzungen verwalten
CI/CD-Pipelines für i18n
Projekte, die automatisierte Übersetzungsverarbeitung erfordern
Hinweise
Erfahrung mit dem ARB-Dateiformat erforderlich
Beschränkt auf ARB-basierte Workflows
Möglicherweise sind zusätzliche Einstellungen für die CI-Integration erforderlich
Kein vollständiger i18n-Framework, sondern ein Toolset
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
arb_utils
Common actions to perform over .arb formatted strings
Usage
A simple usage example:
import'package:arb_utils/arb_utils.dart';
main() {
print('Generating .arb for translators...');
var chkout = 'latestTranslationsProcessedBranch'; // or a49630b726c or HEAD^3 etcProcess.runSync('git', 'checkout $chkout'.split(' '));
var mainARBOld = File('lib/l10n/intl_en.arb').readAsStringSync();
Process.runSync('git', 'checkout master'.split(' '));
var mainARBNew = File('lib/l10n/intl_en.arb').readAsStringSync();
File('lib/l10n/new_translations/intl_en.arb')
.writeAsStringSync(sortARB(processNewKeys(mainARBNew, mainARBOld)));
print('lib/l10n/new_translations/intl_en.arb generated');
}
Features
Manual language switching helpers
Normally there's the need of providing a way of manually changing the locale on runtime. Here is a super easy way of doing so depending on the state manager you use:
The solution handles the persistance of the user selection for app restarts and so.
Provider/BLoC
Given that BLoC relies on Provider for working this solution will work easily for both state managers:
//make sure this line is written, your IDE may not add it automaticallyimport'package:provider/provider.dart';
import'package:arb_utils/state_managers/l10n_provider.dart';
//prefix your MaterialApp(//... with the following:ChangeNotifierProvider(
create: (_) => ProviderL10n(),
child: Builder(builder: (context) {
returnMaterialApp(
locale: context.watch<ProviderL10n>().locale,
supportedLocales: AppLocalizations.supportedLocales,
//now add this widget wherever you want:import'package:arb_utils/arb_utils_flutter.dart';
LanguageSelectorDropdown(
supportedLocales: AppLocalizations.supportedLocales,
provider: context.read<ProviderL10n>(),
)
MobX/GetX/GetIt/Riverpod/Binder/Redux/etc
Pull Requests are always welcome :-D!
ArbClient
A way of getting your ARB translations dynamically, not hardcoded like S.of(context).key / AppLocalizations.of(context).key. It has been made with the pretension of supporting a way of getting the .arb files from the backend, on demand, but if it suits your use case, it just works. (PR are always welcome)
Compares an .arb formatted string with a previous version of itself and outputs a new .arb formatted string with the new keys found there (also the edited ones)
to enable arb_utils as an executable command on your system.
Sort
To easily sort an arb and update original file, use
arb_utils sort <INPUT FILE>
where <INPUT FILE> is a path to the input file.
Also, there are 3 flags for different sorting:
Case insensitive (--case-insensitive / -i): Whether to distinguish between lowercase and uppercase while ordering the keys.
Natural ordering (--natural-ordering / -n): Whether to take numbers as a single character and order them according to their numeric value (instead of ASCII one).
Descending (--descending / -d): Sort in descending order.
For example, to sort with case insensitive and in descending order, use:
arb_utils sort -i -d <INPUT FILE>
Add Entries
To programmatically add new entries to one or more arb files in one go, use
The command will recursively find all .arb files in the current directory and its subdirectories by default. To specify specific files, use the --files (or -f) flag.
New entries are added to the tail of the files by default. Use the --sort (or -s) flag to sort the files after adding.
Note: The command will fail if values for all locales present in the .arb files are not provided.
List Keys
To list keys matching a regexp, use
arb_utils keys <regexp>
This will search in all .arb files found recursively by default. You can also specify files with --files flag.
Add Missing Default Metadata
To easily add missing metadata to an arb and update original file, use