sheets_i18n 0.0.1+3
sheets_i18n: ^0.0.1+3 copied to clipboard
A flutter tool to synchronize i18n (internationalization) arb files with google sheets.
example/lib/main.dart
import 'package:example/l10n/messages_all.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() {
runApp(const MyApp());
}
class MyAppLocalizations {
final String localeName;
MyAppLocalizations(this.localeName);
String get logistics => Intl.message(
'Logistics',
name: 'logistics',
locale: localeName,
);
String get gates => Intl.message(
'Gates',
name: 'gates',
locale: localeName,
);
String get warehouse => Intl.message(
'Warehouse',
name: 'warehouse',
locale: localeName,
);
static Future<MyAppLocalizations> load(Locale locale) {
final String name = locale.countryCode?.isEmpty == true
? locale.languageCode
: locale.toString();
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
return MyAppLocalizations(localeName);
});
}
static MyAppLocalizations of(BuildContext context) {
return Localizations.of<MyAppLocalizations>(context, MyAppLocalizations)!;
}
}
class MyAppLocalizationsDelegate
extends LocalizationsDelegate<MyAppLocalizations> {
const MyAppLocalizationsDelegate();
@override
bool isSupported(Locale locale) =>
['en', 'de', 'cs'].contains(locale.languageCode);
@override
Future<MyAppLocalizations> load(Locale locale) =>
MyAppLocalizations.load(locale);
@override
bool shouldReload(MyAppLocalizationsDelegate old) => false;
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
MyAppLocalizationsDelegate(),
],
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}