language_excel_localization 0.0.4
language_excel_localization: ^0.0.4 copied to clipboard
A code-generation Flutter localization package that reads an Excel sheet and instantly generates Dart translation files and a reactive UI controller.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:language_excel_localization/language_excel_localization.dart';
// Note: In a real project, you would import the generated localization files.
// Since this is a template example, we provide a mock initialization.
/// Entry point of the example application.
void main() {
// Initialize with some mock translations for the example.
// In your app, use: AppTranslations.translations from the generated folder.
LocalizationController.instance.init({
'english': {
'title': 'Hello World',
'change_lang': 'Change to Spanish',
},
'spanish': {
'title': 'Hola Mundo',
'change_lang': 'Cambiar a Inglés',
},
});
runApp(const MyApp());
}
/// The root widget of the example application.
class MyApp extends StatelessWidget {
/// Creates a [MyApp] instance.
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Excel Localization Example',
home: HomeScreen(),
);
}
}
/// The home screen widget of the example application.
class HomeScreen extends StatelessWidget {
/// Creates a [HomeScreen] instance.
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Excel Localization Example'),
),
body: Center(
child: ValueListenableBuilder<String>(
valueListenable: LocalizationController.instance,
builder: (context, lang, child) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Current Language: $lang',
style: const TextStyle(fontSize: 18),
),
const SizedBox(height: 20),
Text(
'title'.tr(),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (lang == 'english') {
LocalizationController.instance.changeLanguage('spanish');
} else {
LocalizationController.instance.changeLanguage('english');
}
},
child: Text('change_lang'.tr()),
),
],
);
},
),
),
);
}
}