playx_localization 1.0.0
playx_localization: ^1.0.0 copied to clipboard
Easily manage and update app localization with a simple implementation and a lot of utilities.
Changelog #
1.0.0 #
Note: First stable release. Raises the minimum supported SDK versions (Dart 3.12, Flutter 3.44). Existing saved locales, translation files named in the old script-code order, and linked-file folders are migrated automatically; see the entries below.
- Breaking: Requires Dart
>=3.12.0and Flutter>=3.44.0. - Updated
playx_coredependency to^2.0.0and upgraded all dependencies to their latest versions. - Translations from other packages: Added
PlayxLocalization.registerTranslations/unregisterTranslationsandPlayxTranslationSource(with a.packageconstructor) so packages can ship their own translations. Supports optional keynamespace, works before or after boot, tolerates missing locales, and is always overridden by the app's own keys. - Key generator: New
dart run playx_localization:generatecommand generates a class of typed key constants from a base translation file (nested keys, linked files, plural groups,--checkfor CI). - Validator: New
dart run playx_localization:validatecommand reports missing/extra keys, placeholder mismatches, plural groups withoutother, empty values, unused keys (--src), invalid JSON and broken linked files. Exits non-zero on errors (or warnings with--strict). - Script code naming follows BCP-47 (with migration): Locales with both a script and a country code are now written
language-script-country(e.g.zh-Hant-TW) byLocale.toStringWithSeparator, matchingLocale.toLanguageTag(). Translation files are looked up aszh-Hant-TW.jsonfirst, then as the oldzh-TW-Hant.json(with a log message to rename it). Linked files are looked up in thezh-Hant-TW/folder first, then in the oldzh-TW/folder that ignored the script. Locales without a script, or without a country, are unchanged. AddedLocale.toLegacyStringWithSeparator. The command line tools understand both file name orders. - Note for custom
LinkedFileResolversubclasses:resolveLinkedFileshas a new optionalscriptCodeparameter. - Fix:
DateTime.toFormattedDate/toFormattedTimeused only the language code, sode-ATgotdemonth names. They now use the full locale tag (still overridable withlocale). PlayxLocalizationDelegateis now exported, so the callback ofcustomLocalizationDelegateBuildercan be typed. AddedPlayxLocalization.resetLocale.- Plurals follow the language's rules by default (nouns with numbers):
plural()now picksone,two,few,manyorotherwith the plural rules of the language, so Arabic (مركبة/مركبتان/٣ مركبات/١١ مركبة) and Russian work with a single entry. An exactzero/one/twoform still wins for 0, 1 and 2, and missing forms fall back toother, so existing entries keep working.ignorePluralRulesnow defaults tofalse; set it totrueto keep onlyzero,one,twoandother. - Localized digits in plurals: New
PlayxLocaleConfig.localizePluralDigitsandplural(localizeDigits: ...)show the count as٣instead of3in Arabic (and other digit systems). A customformatstill takes precedence. - Fix: Decimal counts were rounded before choosing the plural form (
1.4was treated as singular). - Validator: warns when a plural group misses forms its language uses (for example Arabic
few/many).pluralCategoriesForis used for this. - Custom asset loaders are easier:
AssetLoader'sfileLoaderandlinkedFileResolverare now optional, so a custom loader (CSV, YAML, HTTP, ...) only has to implementload.FileLoader,RootBundleFileLoaderandLinkedFileResolverare exported. - Documentation site: Guides and the API reference are published to GitHub Pages at https://playx-flutter.github.io/playx_localization/. The README is now a short overview that links to them.
- CI: New build workflow (tests on the minimum and latest Flutter, format, analyze, 90% coverage gate, command line tools check, publish dry run) and a docs workflow.
translateoption:trandplural(String,TextandBuildContextvariants) accepttranslate: falseto return the text as-is, still applyingargs/namedArgs.preloadLocales: NewPlayxLocalization.preloadLocalesloads only the locales you need sotr(locale: ...)works for them without enablingpreloadSupportedLocalesfor all locales.trwith aBuildContextnow falls back to the global instance when noLocalizationis found in the context, instead of throwing.- Locale saved by id (with migration): The selected locale is now saved by its
XLocale.idinstead of its position insupportedLocales, so reordering, inserting or removing locales in an app update no longer restores the wrong language. Existing installs migrate automatically: a saved index is read when no id exists yet, then rewritten as an id (the index is still written, so downgrades keep working). A saved locale that was removed falls back tostartLocale/ the device locale instead of a different language. The device-sync flag (-1) keeps working. - Pluggable storage: Added
PlayxLocaleConfig.storagewithPlayxLocaleStorage,PlayxPrefsLocaleStorage(default) andPlayxMemoryLocaleStorage, likeplayx_theme. Writes are queued so the last requested locale is always the last one saved. resetLocaleforgets the saved choice: it now clears the saved locale and applies the fresh-install locale (startLocale, device, fallback) without saving it. Before, it saved that result as an explicit choice.getLastSavedIndexFromPrefsis deprecated.- Fix:
config.useFallbackTranslationswas ignored; the fallback locale was always loaded. It is now respected. - Fix: A failed locale switch (for example a missing translation file) no longer wipes the loaded translations, changes the locale or saves it.
updateTo,updateById, etc. now returnfalseand keep the current locale.loadTranslationsnow returns abool. - Fix: One missing or broken locale file no longer breaks
preloadSupportedLocalesfor all locales. - Fix: Looking up a key that points to a group (e.g.
'home'whenhomeis an object) crashed; a path through a text value ('a.b.c'wherea.bis text) returned the wrong text. Both now behave like a missing key. - Fix:
namedArgswhose names contain regex characters (e.g.{a.b},{x+y}) were not replaced. - Fix:
@:keylinks are now resolved in the locale passed totr(locale: ...)instead of the current locale, and the@.capitalize:modifier no longer crashes on empty text. - Fix:
PlayxLocalization.currentLocaleToStringwas notstatic, so it could not be called.PlayxLocalization.updateByLanguageCodenow acceptsscriptCode. - Fix:
context.isCurrentLocaleRtl/isCurrentLocaleLtralways reported LTR because they analyzed the language code as text. - Fix:
Text(...).tr()and.plural()dropped the originalText.locale. - The optional base-language fallback file (e.g.
enforen-US) is now merged recursively and any load failure for it is ignored. - Fix: Linking the same translation file from multiple keys is no longer reported as a cyclic link. Only real cycles throw now.
- Added a unit test suite covering plural rules, translations, linked file resolution, translation merging, device-sync persistence,
scriptCodelocale matching, and the string, number and locale extensions. - Fixed analyzer lints.
0.4.0 #
- Enhanced Locale Config: Added
useFallbackTranslationsForEmptyResources,ignorePluralRules,extraAssetLoaders, anderrorWidgettoPlayxLocaleConfig. - Script Code Support: Added
scriptCodenatively toXLocaleand updated locale matching inPlayxLocaleControllerto properly utilize it. - Deep Translation Merging:
TranslationManagernow supports combining JSON translation maps securely from multiple asset loaders. - Device Sync Persistence:
updateToDeviceLocale()now saves a special flag in preferences (index-1). When the application boots, instead of overriding the device's current locale with a historically cached exact locale orstartLocale, the controller auto-routes strictly to whatever the currentdeviceLocaledictates. This allows developers to offer a persistent "system default" setting. - Synchronous Any-Locale Translation: Added
preloadSupportedLocalestoPlayxLocaleConfig. When enabled, it caches all dictionaries during initialization, allowing developers to query translations for any loadedLocale? localeparametrically usingtr(..., locale: ...)synchronously, completely out-of-bounds, without overriding the app environment.
0.3.1 #
- Bumping
playx_coredependency to^0.7.4. - Renaming
isRtlandisLtrgetters toisCurrentLocaleRtlandisCurrentLocaleLtrrespectively for better clarity. - Allow passing BuildContext to plural for locale-aware formatting
0.3.0 #
Enhancements #
-
Improved Delegate Configuration:
- Added
extraDelegatesto inject custom localization delegates. - Added
customLocalizationDelegateBuilderto fully customize the delegate list.
- Added
-
Logging Enhancements:
- Added
logLocaleChangestoggle inPlayxLocaleConfig. - Improved logs to show locale name, value, and index.
- Added
-
Removed
easy_localizationdependency; replaced with a custom, flexible system.
New Extensions #
BuildContext Locale Helpers
- Easily access locale info like
currentLocale,localeTag,languageCode,isRtl,fontFamily, and more.
Number Extensions
- Enhanced currency formatting with
toFormattedCurrencyNumberandtoLocalizedCurrencyNumber. - Added format options to all localized number methods.
- New
isZeroutility for floating-point comparisons.
String Localization Extensions
- Check for RTL/LTR, Arabic/English text, numbers, and diacritics.
- Convert digits between Arabic and Western formats.
- Normalize Arabic letters and clean up extra spaces.
Locale Utilities
- New extensions for
Locale,XLocale, andStringfor parsing and formatting.
0.2.2 #
- Update packages.
0.2.1 #
- Update packages.
- Add new parameter
fontFamilytoXLocaleto set the font family for the localized text for each locale. logMissingKeysparameter is now set tofalseby default.- Add new extension
toFormattedTimeonDateTimeto format time to localized time string.
0.2.0 #
Note: This release contains breaking changes.
- Migrated shared preferences to
SharedPreferencesAsyncfor improved performance and async handling. If you're upgrading, setmigratePrefsToAsyncPrefstotrueinPlayxLocaleConfigto ensure a smooth transition. - Add new
logMissingKeysparameter toPlayxLocaleConfigto enable or disable logging missing keys in the console. - Removed dependencies on GetX package.
- No need to call
await PlayXCore.bootCore();before using the localization package anymore. The package will automatically initialize the core when needed.
0.1.2 #
- Fix bug causing locale to not be saved correctly.
0.1.1 #
- enhance log messages.
0.1.0 #
Note: This release contains breaking changes.
New Features #
General Updates
- Package Updates: All packages have been updated.
intlPackage: Upgraded to version 0.19.0.
PlayxLocalizationBuilder
-
Improved Locale Management: Now uses an
InheritedWidgetto provide locale to child widgets, enhancing locale management and widget rebuilds. -
Simplified Localization Access:
- Retrieve localized text using:
'text'.tr(context: context)context.tr()Text('text').tr(context: context)
- New
BuildContextextensions:context.tr()andcontext.pluralfor easy access to localized text.
Providing context to the
trfunction ensures widgets are rebuilt correctly when the locale changes. - Retrieve localized text using:
-
For classes without context, you can still use the
trfunction without context, though note that widgets will not rebuild on locale changes when used this way, But there is an option to force app update on locale change.
PlayxLocalization
- Added a getter to retrieve the app's fallback locale.
- Added a function to get the current locale as a string with a custom separator.
- Added a function to determine if the current locale is right-to-left (RTL).
PlayxLocaleController
- Switched from
GetxControllertoValueNotifier, reducing reliance on theGetXpackage. - Updated methods (
updateTo,updateByIndex,updateById,next,updateByLanguageCode,updateToDeviceLocale) now include aforceAppUpdateparameter to allow a full app rebuild when changing the locale.
Breaking Changes #
XLocaleConfighas been renamed toPlayxLocaleConfigto align with the package name. -PlayxLocaleConfigis no longer abstract and can be instantiated directly.PlayxLocaleConfignow requires default and supported locales to be provided at instantiation.- The
trextension onStringhas been updated to a function that accepts context and additional parameters.
0.0.5 #
- Update packages.
0.0.4 #
- Update packages.
- Bump Intl version to 0.18.1.
0.0.3 #
- Update packages.
- Bump dart version to 3.0.0.
- Add number extensions for
numto format number to localized numbers String like arabic numbers. - Add
Stringextensions to check if string is rtl or is of specifc language.
0.0.2 #
- Update packages.
0.0.1 #
- Initial release.