Aus öffentlichen Paketdaten erstellte Orientierung.
Best_Localization ist ein Flutter-Paket, das für eine nahtlose Lokalisierung und Internationalisierung entwickelt wurde und dynamische Übersetzungen unterstützt, wobei speziell die kurdische Sprache berücksichtigt wird. Es ermöglicht Entwicklern die effiziente Verwaltung mehrsprachiger Inhalte in ihren Apps und ist daher ideal für Projekte mit unterschiedlichen sprachlichen Zielgruppen. Das Paket integriert sich nahtlos in den Flutter-Framework und ermöglicht eine einfache Übersetzungsverwaltung über spezialisierte Dateien. Durch seinen Fokus auf Flexibilität und Zugänglichkeit verbessert Best_Localization die Benutzererfahrung weltweit. Seine Open-Source-Natur fördert Community-Beiträge und Transparenz.
Anwendungsfälle
Multisprachige App-Entwicklung
Kurdische Sprachunterstützung
Dynamische Übersetzungshandhabung
Cross-regionaler App-Deployment
Echtzeit-Sprachumschaltung
Hauptmerkmale
Unterstützt die kurdische Sprache
Dynamisches Übersetzungs-Laden
Einfache Integration mit Flutter
Open-Source und communitygetrieben
Saubere, wartbare Übersetzungsstruktur
Geeignet für
Entwickler, die kurdischsprachige Nutzer ansprechen
Apps, die mehrsprachige Unterstützung erfordern
Projekte, die Inklusivität betonen
Teams, die Flutter für internationale Apps verwenden
Anwendungen, die eine leichte Lokalisierung benötigen
Hinweise
Beschränkte Plattformspezifikation
Benötigt manuelle Einrichtung der Übersetzungsdatei
Keine integrierte Übersetzungsverwaltungsoberfläche
Am besten geeignet für statischen oder halb-dynamischen Inhalt
Abhängig von externen Tools für Übersetzungsarbeitsabläufe
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
Best Localization
Best Localization is a lightweight and flexible localization package for Flutter. It supports dynamic translations, interpolation, pluralization, remote translations, fallback locales, and custom localization for Kurdish Sorani and Kurdish Kurmanji, including widgets like Material and Cupertino.
Features
Dynamic Translations: Translate text based on locale dynamically.
Easy Translation Extensions (NEW! 🎉): Use .tr() on both Strings and Text widgets without context!
Pluralization Support (NEW! 🎉): Smart plural forms with language-specific rules (zero, one, two, few, many, other).
Gender-Specific Translations (NEW! 🎉): Support for male, female, and other gender variations.
Multiple File Format Support: Load translations from JSON, CSV, YAML, or XML files.
Remote Translations: Load translations from HTTP API with automatic caching.
Fallback Locale: Automatically fall back to a default language when translations are missing.
Translation Key Verification Tool: Command-line tool to verify translation keys across locales.
Interpolation: Insert dynamic values into translations (e.g., Hello, {name}!).
BuildContext Extensions: Easy access to translations without boilerplate code.
Custom Localization for Kurdish:
Supports Kurdish Sorani (ckb) and Kurdish Kurmanji (ku) for Material and Cupertino widgets.
Includes custom date and number formatting for each variant.
Seamless Integration:
Works with Flutter's native Localizations system.
Fully compatible with MaterialApp and CupertinoApp.
Flexible Translation Loading:
Load from assets (JSON, CSV, YAML, XML)
Load from remote API (HTTP)
Define translations directly in Dart maps
Create custom loaders for your specific needs
Getting Started
Installation
1- Add best_localization To install best_localization package, run the following commands in your terminal:
flutter pub add best_localization
or add best_localization to your pubspec.yaml:
dependencies:best_localization:^2.0.3
2- Add flutter_localizations Add the flutter_localizations package to your pubspec.yaml file:
// Load from your server with automatic cachingLoaders.remote(
url: 'https://api.example.com/translations',
cacheEnabled: true,
cacheDuration: Duration(hours: 24),
)
context.translate('key', args: {...}) - Translate with arguments
context.plural('key', count) - Translate with plural form
context.localization - Get BestLocalization instance
context.currentLocale - Get current locale
context.languageCode - Get language code ('en', 'ckb', 'ku', etc.)
context.isKurdish - Check if current language is Kurdish (Sorani or Kurmanji)
context.isSorani - Check if current language is Kurdish Sorani (ckb)
context.isKurmanji - Check if current language is Kurdish Kurmanji (ku)
context.isArabic - Check if current language is Arabic
context.isEnglish - Check if current language is English
context.isRTL - Check if current language is RTL
context.textDirection - Get text direction
4. Easy Translation with .tr() (NEW! 🎉)
Translate strings and Text widgets easily without passing context!
For Strings:
// Simple translation - no context needed!print('hello'.tr());
// With argumentsprint('welcome'.tr(args: {'name': 'John'}));
// With genderprint('greeting'.tr(gender: 'male'));
// With custom localeprint('hello'.tr(locale: Locale('en')));
// With context (optional)print('hello'.tr(context: context));
For Text Widgets:
// Simple translation - no context needed!Text('hello').tr()
// With argumentsText('welcome').tr(args: {'name': 'John'})
// With genderText('greeting').tr(gender: 'female')
// Plural formText('items').plural(5)
// Plural with argumentsText('money').plural(10, args: {'name': 'Sarah'})
// Using translate() aliasText('hello').translate() // Same as .tr()
Usage in Your Widget:
classMyWidgetextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnColumn(
children: [
// Direct translation - clean and simple!Text('welcome'.tr()),
// With stylingText('title').tr(args: {'name': 'User'}),
// Plural formText('items').plural(itemCount),
// Gender-specificText('greeting').tr(gender: userGender),
],
);
}
}
5. Pluralization (NEW! 🎉)
Handle plural forms with language-specific rules:
JSON Structure:
{"day":{"zero":"{} дней","one":"{} день","two":"{} дня","few":"{} дня","many":"{} дней","other":"{} дней"},"money":{"zero":"You have no money","one":"You have {} dollar","many":"You have {} dollars","other":"You have {} dollars"},"money_named_args":{"zero":"{name} has no money","one":"{name} has {} dollar","many":"{name} has {} dollars","other":"{name} has {} dollars"}}
Usage:
// String plural'day'.plural(0) // "0 дней"'day'.plural(1) // "1 день"'day'.plural(5) // "5 дней"// With named arguments'money_named_args'.plural(5, args: {'name': 'John'}) // "John has 5 dollars"'money_named_args'.plural(1, args: {'name': 'John'}) // "John has 1 dollar"'money_named_args'.plural(0, args: {'name': 'John'}) // "John has no money"// Text widget pluralText('day').plural(itemCount)
Text('money_named_args').plural(balance, args: {'name': userName})
// With context (optional)'day'.plural(5, context: context)
Supported Plural Forms:
zero - When count is 0
one - When count is 1
two - When count is 2
few - Language-specific (e.g., 2-4 in Russian)
many - Language-specific (e.g., 5+ in Russian)
other - Default fallback
Language-Specific Rules:
English: one (1), other (2+)
Russian/Ukrainian: Complex rules for one/few/many
Arabic: Supports zero, one, two, few, many
Polish: Similar to Russian
6. Gender-Specific Translations (NEW! 🎉)
Support for gender-specific text variations:
JSON Structure:
{"greeting":{"male":"Hi man ;) {}","female":"Hello girl :) {}","other":"Hello {}"},"welcome_user":{"male":"Welcome Mr. {name}","female":"Welcome Ms. {name}","other":"Welcome {name}"}}
Verify your translation files to find missing keys, duplicate values, and inconsistencies across locales.
In Your Code:
import'package:best_localization/best_localization.dart';
// Load your translationsfinal translations = {
'en': awaitJsonAssetLoader(path: 'assets/translations/en.json').load(),
'ckb': awaitJsonAssetLoader(path: 'assets/translations/ckb.json').load(),
'ku': awaitJsonAssetLoader(path: 'assets/translations/ku.json').load(),
'ar': awaitJsonAssetLoader(path: 'assets/translations/ar.json').load(),
};
// Verify all localesfinal report = TranslationVerifier.verify(
translations: translations,
referenceLocale: 'en', // Optional: use English as reference
);
// Print reportprint(report.generateReport());
// Get coverage percentageprint('Sorani coverage: ${report.getCoverage('ckb')}%');
print('Kurmanji coverage: ${report.getCoverage('ku')}%');
// Export as JSONfinal jsonReport = report.toJson();
Command-Line Tool:
# Activate the package globally (one-time setup)
flutter pub global activate best_localization
# Verify all translations in a directory
dart run best_localization:verify_translations verify assets/languages
# Verify with specific reference locale
dart run best_localization:verify_translations verify assets/languages --reference en
# Compare two translation files
dart run best_localization:verify_translations compare assets/languages/en.json assets/languages/ckb.json
# Find duplicate values (same translation for different keys)
dart run best_localization:verify_translations duplicates assets/languages/en.json
# Find similar keys (potential typos)
dart run best_localization:verify_translations similar assets/languages/en.json --threshold 0.8
# Output as JSON for CI/CD integration
dart run best_localization:verify_translations verify assets/languages --json
TranslationVerifier.findSimilarKeys() - Find similar key names (potential typos)
10. Set Keys to Languages Other Than English
You can define your translation keys in languages other than English. For example:
final translations = {
'en': {
'سڵاو': 'Hello, {name}!', // Translation for "سڵاو" in English'بەخێربێن': 'Welcome', // Translation for "بەخێربێن" in English
},
'ckb': {
'سڵاو': 'سڵاو، {name}!', // Translation for "سڵاو" in Kurdish Sorani'بەخێربێن': 'بەخێربێیت', // Translation for "بەخێربێن" in Kurdish Sorani
},
'ku': {
'Silav': 'Silav, {name}!', // Translation for "Silav" in Kurdish Kurmanji'Bi xêr hatî': 'Bi xêr hatî', // Translation for "Bi xêr hatî" in Kurdish Kurmanji
},
// Add more languages here...
};
About the developer
This package was developed by Dosty Pshtiwan, inspired by the flutter_kurdish_localization package created by Amin Samad. It includes Kurdish Sorani (ckb) and Kurdish Kurmanji (ku) localization support for Flutter apps and builds upon their foundational work to provide a comprehensive localization solution.
Kurdish language codes
Variant
Locale code
Script
Direction
Kurdish Sorani
ckb
Arabic
RTL
Kurdish Kurmanji
ku
Latin
LTR
Migration note: In older versions of this package, Kurdish Sorani used the ku code. Sorani is now ckb, and ku is used for Kurmanji. Update your translation files and Locale values accordingly.