translations_center 0.1.0 copy "translations_center: ^0.1.0" to clipboard
translations_center: ^0.1.0 copied to clipboard

Offline-first OTA localization SDK for Flutter apps. Stale-While-Revalidate caching with ETag support.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:translations_center/translations_center.dart';
import 'app_strings.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await TranslationsCenter.init(
    serverUrl: 'https://api.translations-center.com',
    apiKey: 'sample-api-key',
    defaultLocale: const Locale('en'),
    fallbackAssetsPath: 'assets/i18n',
  );
  
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});
  
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isHebrew = false;
  
  Future<void> _toggleLanguage() async {
    _isHebrew = !_isHebrew;
    final newLocale = _isHebrew ? const Locale('he') : const Locale('en');
    await TranslationsCenter.instance.setLocale(newLocale);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Translations Center Example',
      home: Scaffold(
        appBar: AppBar(title: const Text('Translations Center')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(AppStrings.exit.get(), style: const TextStyle(fontSize: 18)),
              const SizedBox(height: 8),
              Text(AppStrings.welcome.get('Eyal', 'My App'), style: const TextStyle(fontSize: 18)),
              const SizedBox(height: 8),
              Text(AppStrings.greetingWithName.get('Eyal'), style: const TextStyle(fontSize: 18)),
              const SizedBox(height: 8),
              ElevatedButton(
                onPressed: () {},
                child: Text(AppStrings.loginButton.get()),
              ),
              const SizedBox(height: 24),
              ElevatedButton(
                onPressed: _toggleLanguage,
                child: const Text('Change Language'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
88
downloads

Documentation

API reference

Publisher

verified publisher3p-cups.com

Weekly Downloads

Offline-first OTA localization SDK for Flutter apps. Stale-While-Revalidate caching with ETag support.

License

MIT (license)

Dependencies

flutter, http, path_provider, shared_preferences

More

Packages that depend on translations_center