stringlocale 0.4.0
stringlocale: ^0.4.0 copied to clipboard
Declare strings with typed params, compile to offline locale bundles with an LLM, and resolve by locale at runtime. Axis-model i18n for Dart and Flutter.
Changelog #
0.4.0 #
- LLM drafting and runtime
userAdaptedadaptation now work with any OpenAI-compatible/chat/completionsendpoint (OpenRouter, OpenAI, Groq, Together, local Ollama/LM Studio, etc.), not just OpenRouter.- New
LlmDrafter(generic) exported alongside the existingOpenRouterDrafter, which remains as a backward-compatible subclass. - New config via
STRINGLOCALE_API_KEY,STRINGLOCALE_BASE_URL, andSTRINGLOCALE_MODEL(withOPENROUTER_*kept as fallbacks). - CLI: new
--drafter llmmode and--base-urloption.
- New
0.3.0 #
Initial public release.
Core Dart API (package:stringlocale/stringlocale.dart) #
StringLocale— declare a localizable string with a source text, a stableid, and typedParamdescriptors. Instances auto-register and resolve viaStringLocale.resolve().Paramfactories covering every param kind:Param.literal()— pass-through stringParam.user()— free-text pass-through (unformatted)Param.number()— locale digit conversionParam.date()— CLDR date formatting (short/medium/long/full)Param.currency()— locale currency formatting with ISO 4217 codeParam.relative()— relative-time formatting ("3 days ago")Param.translatable()— closed enum axis; values pre-translated at compile time and substituted at runtime (fully offline)Param.plural()— CLDR plural axis (one / other / few / many / zero)Param.userAdapted()— free prose reformatted per locale by an LLM adapter at runtime; falls back to the source value offline
Bundle— runtime bundle loaded from compiled JSON; supportsresolve(sync) andresolveAsync(async, foruserAdaptedparams). Locale data can be merged incrementally viaBundle.merge().Bundle.fromDir()/Bundle.fromJsonString()— load from a compiled directory (via an injectedFileReader) or a raw JSON string.load()— convenience wrapper that reads a compiled directory withdart:ioand sets it as the active bundle.- Library-level helpers:
setLocale,getLocale,useBundle,currentBundle,getRegistry,clearRegistry. UserAdaptedMode.cached(default) caches adapter results keyed by(value, locale, context);UserAdaptedMode.realtimealways calls the adapter.- Axis model: multi-dimensional cross-product templates (e.g. gender × plural). Required axes are validated at resolve time.
- CLDR plural rules generated for all supported locales.
Flutter API (package:stringlocale/flutter.dart) #
StringLocaleScope—InheritedWidgetthat holds the active locale and bundle; rebuilds descendants on locale change.Tr— sync widget that renders aStringLocalein the scope's current locale. Accepts an optionalbuilderfor custom styling.AsyncTr— async widget backed by aFutureBuilder; required for strings withuserAdaptedparams. Re-resolves automatically on locale or args change.tr()/trAsync()— imperative helpers for use outside the widget tree (snackbars, dialogs, etc.).
CLI (stringlocale executable) #
stringlocale compile— calls an LLM (OpenRouter by default) to produce compiled locale bundles from registeredStringLocaledeclarations.stringlocale check— validates that all strings compile cleanly and that params match their declarations.stringlocale prune— removes stale string entries from existing bundle files that are no longer referenced in source.
Default OpenRouter adapter #
- On Dart VM and Flutter desktop/mobile, if
OPENROUTER_API_KEYis set in the process environment or passed via--dart-define, a built-in async adapter is wired automatically foruserAdaptedparams. - Model defaults to
google/gemini-2.5-flash; override withOPENROUTER_MODEL. - macOS apps require
com.apple.security.network.clientin entitlements to allow outbound HTTP to OpenRouter.