signals_translator 1.0.0
signals_translator: ^1.0.0 copied to clipboard
Translate your project 100% using signals
1.0.0 #
BREAKING #
- Removed
tlpandtlpm(deprecated since 0.1.0). Usetlv/tlvmwith inline ICU plural blocks instead. - Removed support for the nested
zero/one/otherJSON format. A translation value that is an object is no longer read:tl,tlvandtlvmreturn the key. Convert each nested object to an ICU string, e.g.{"zero": "No apples", "one": "1 apple", "other": "{0} apples"}becomes"{0, plural, =0 {No apples} one {# apple} other {# apples}}". See "Migrating from tlp/tlpm" in the README. - Hyphen-named asset files are no longer loaded.
en-gb.jsonmust be renamed to the canonicalen_GB.json(andzh-hans.jsontozh_Hans.json). Before,loadLocale('en-gb')also probed the rawen-gb.json; now only canonical names are tried, and a missing file falls back to the bare language and thenfallbackLocale. - The persisted locale is now saved in canonical form (
en_GB, not the rawen-gborEN_gBpassed toloadLocale). A raw value stored by an older version is still honoured and is rewritten to the canonical form on the next start, so users keep their chosen language. - Removed
assetLocationString. It showed the requested asset path before fallback, which could name a file that doesn't exist. UseactiveAssetPath(the file that was actually loaded); it is reactive insideSignalBuilderand effects. prefsis no longer public. It threwLateInitializationErrorbeforereadyor when SharedPreferences failed, and writing the'locale'key directly bypassed the translator. UseloadLocaleto change the locale andreadyto wait for the stored one.- Requires signals ^7.1.0 (signals 6.x is no longer supported). README
and example use
SignalBuilderinstead of the deprecatedWatch.
Other changes #
- The system locale is now loaded at startup when no locale is stored.
Before,
tlreturned keys untilloadLocalewas called, even thoughcurrentLocalewas'sys'. The system locale is not persisted, and it is also loaded when SharedPreferences fails to load. - Internals moved to the new
signals_translator_corepackage. - New sibling packages with the same API:
alien_signals_translatorandsolidart_translator. - New
translationsPathsetting to load translation files from another directory, such as a shared package's assets (packages/<name>/assets/translations). - Requires Flutter 3.41+ / Dart 3.11 (via
shared_preferences2.5.6).intlstays at>=0.20.2so apps usingflutter_localizationson Flutter 3.41–3.44 still resolve.
0.1.0 #
ICU message format support. tl, tlv and tlvm now resolve
ICU plural, selectordinal and select arguments inline in any
translation string.
{N, plural, ...}with=Nexact matches, CLDR plural categories for the active locale (zero/one/two/few/many/other, viapackage:intl),offset:, and#for the count ('#'for a literal#).{N, selectordinal, ...}with English ordinal rules; other languages selectother.{N, select, ...}for gender and category choices.- Placeholders are substituted at every occurrence, and substituted values are never re-read as placeholders.
- Malformed ICU renders verbatim instead of throwing; malformed blocks and missing ICU variables print a debug-mode warning.
tlpandtlpmare deprecated in favour of ICU strings withtlv/tlvm.tlv/tlvmalso read the nested zero/one/other format, so call sites can migrate before every locale file does.- New
SignalTranslator().ready: completes once SharedPreferences has loaded and the stored locale is applied. It completes with an error (instead of hanging) when SharedPreferences fails; translation keeps working without persistence. - New dependency:
intl(>=0.19.0 <0.21.0).
0.0.7 #
Hotfix for 0.0.6: currentLocale now defaults to the 'sys' sentinel
instead of the device's regional locale string. The 0.0.6 default
(composeDeviceLocale(), e.g. 'en_US') silently broke any caller
binding a dropdown's value: to currentLocale against bare-language
items — 'en_US' doesn't match 'en', so the dropdown asserted and
the page failed to render.
_chosenLocaleinitialises to'sys'until a concrete locale is chosen vialoadLocaleor rehydrated from storage. Regional asset auto-pickup still works through the'sys'path (resolvedLocalereturns the regional code from_deviceLocale).- Stored locale preferences from earlier versions continue to load unchanged.
- Apps that want the previous "pick the device's regional locale at
startup" behaviour can call
await loadLocale('sys')(or any explicit locale) during initialisation.
0.0.1 #
0.0.1+1 #
0.0.1+2 #
- edited and clarified the documentation
0.0.2 #
- remove the reset function
0.0.3 #
- add support for (basic) pluralization
0.0.5 #
-
loadLocaleno longer throws when the resolved translation asset is missing or malformed. It now falls back tofallbackLocale(defaults to'en', configurable viaSignalTranslator().fallbackLocale). -
The user's chosen locale (including
'sys') is persisted even when its asset cannot be loaded, so the preference survives across restarts. -
Missing/malformed asset errors are now logged via
debugPrintinstead of silently swallowed. -
Added
SignalTranslator.debugReset()static method for test isolation (replaces the oldresetForTesting()instance method). -
Removed unused
decodedJsoncomputed field. -
Wire up automated publishing from GitHub Actions: explicitly request a pub.dev OIDC token and configure pub credentials so the workflow no longer falls back to interactive OAuth.
Note: 0.0.4 was tagged but never successfully published to pub.dev (the GA workflow's auth handshake failed), so 0.0.5 is the first release with these changes.
0.0.6 #
Region- and script-aware locales — without losing the simple flow. Ship
en_GB, en_US, or zh_Hans_CN translation files and they're picked
up automatically. Skip them and the existing single-language usage keeps
working exactly as before; no migration, no API churn.
- Translation files at
assets/translations/<lang>[_<Script>][_<REGION>].jsonare now discovered. Common shapes:en.json,en_GB.json,zh_Hans_CN.json. loadLocaleaccepts any case or separator —en_GB,en-gb,EN_gB,zh-hans-cnall normalize to canonical form. Non-canonical input logs a one-linedebugPrintwarning so misnamed files surface quickly.'sys'mode now readsscriptCodeandcountryCodefrom the device locale, resolving to the most specific file the app ships. OS locale changes are tracked reactively viaWidgetsBindingObserver.didChangeLocales— anyWatchreading translations rebuilds automatically.- Fallback chain: a missing regional asset falls through to its bare
language before reaching
fallbackLocale(e.g.en_GB → en → fallback), deduplicated. - New
resolvedLocalegetter returns a concrete locale string suitable forintl/DateFormatand other APIs that don't understand the'sys'sentinel. - Missing-asset
debugPrintnow mentions the canonical filename form to help diagnose misnamed regional files. - Concurrent reloads are serialized via a monotonic token, so an OS
locale change racing with an explicit
loadLocalecan't let a slow stale asset overwrite a newer one. WidgetsBindingObserverregistration is retried lazily on eachloadLocalecall — aSignalTranslatorconstructed beforeWidgetsFlutterBinding.ensureInitialized()self-heals on the next call.- Malformed translation assets (root not a JSON object,
translationsnot a map) degrade to the next fallback candidate instead of throwing. - Fully backwards compatible: bare-language usage (
en,nl,es) works unchanged, and apps that shipped legacy hyphen-separated assets (e.g.en-gb.json) keep loading them — the raw input is probed as a fallback candidate before the bare-language fallback, and stored prefs preserve the caller's original form so cross-restart lookups don't drift.