better_i18n 0.1.0
better_i18n: ^0.1.0 copied to clipboard
Flutter SDK for better-i18n — runtime translation loading from CDN with offline fallback.
better_i18n #
Flutter SDK for better-i18n — runtime translation loading from CDN with offline fallback.
Features #
- Runtime translations from CDN (no compile-time ARB/JSON files needed)
- 3-tier fallback: Memory Cache → CDN → Persistent Storage → Static Data
context.t('namespace.key')— Flutter-idiomatic translation API- Runtime locale switching with
context.setI18nLocale('tr') - Zero external state management dependency (works with Bloc, Riverpod, etc.)
- Pluggable storage interface for offline support
Quick Start #
import 'package:better_i18n/better_i18n.dart';
// Wrap your app
MaterialApp(
home: BetterI18nProvider(
project: 'your-org/your-project',
defaultLocale: 'en',
locale: 'en',
storage: SharedPrefsStorage(),
loadingBuilder: (_) => const CircularProgressIndicator(),
child: const MyApp(),
),
);
// Use translations anywhere
Text(context.t('common.hello'))
Text(context.t('common.greeting', args: {'name': 'Osman'}))
// Switch locale
await context.setI18nLocale('tr');
// Access available languages
final languages = context.i18nLanguages;
How It Works #
Translations are fetched from the better-i18n CDN at runtime. The SDK uses a 3-tier fallback chain:
- Memory cache (TtlCache) — instant, no network
- CDN fetch — with timeout + exponential backoff retry
- Persistent storage (SharedPreferences) — offline fallback
- Static data — bundled translations as last resort
Integration with State Management #
BetterI18nProvider accepts an external locale prop, making it easy to integrate with Bloc, Riverpod, or any state management:
BlocBuilder<LocaleCubit, String>(
builder: (context, locale) => BetterI18nProvider(
project: 'your-org/your-project',
defaultLocale: 'en',
locale: locale,
child: const MyApp(),
),
);
License #
MIT