Skip to content

Commit 8226292

Browse files
committed
Fixed : example
1 parent a5883d9 commit 8226292

File tree

5 files changed

+57
-56
lines changed

5 files changed

+57
-56
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.0.2
2+
3+
* Fixed example
4+
5+
## 1.0.1
6+
7+
* Fixed packaging issues
8+
19
## 1.0.0
210

311
* Initial release.

example/lib/app.dart

Lines changed: 0 additions & 40 deletions
This file was deleted.

example/lib/home_page.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.

example/lib/main.dart

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
11
import 'package:flutter/material.dart';
2-
3-
import 'app.dart';
2+
import 'package:flutter_localizations/flutter_localizations.dart';
3+
import 'package:gettext_i18n/gettext_i18n.dart';
44

55
void main() {
66
runApp(const MyApp());
77
}
8+
9+
class MyApp extends StatelessWidget {
10+
const MyApp({Key? key}) : super(key: key);
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return MaterialApp(
15+
home: const HomePage(),
16+
supportedLocales: ['en', 'fr', 'fr_CH'].map((l) => Locale(l)),
17+
localizationsDelegates: [
18+
GettextLocalizationsDelegate(defaultLanguage: 'en'),
19+
GlobalMaterialLocalizations.delegate,
20+
GlobalWidgetsLocalizations.delegate,
21+
],
22+
localeListResolutionCallback: (locales, supportedLocales) {
23+
if (locales != null) {
24+
for (var locale in locales) {
25+
var supportedLocale = supportedLocales.where((element) =>
26+
element.languageCode == locale.languageCode &&
27+
element.countryCode == locale.countryCode);
28+
if (supportedLocale.isNotEmpty) {
29+
return supportedLocale.first;
30+
}
31+
supportedLocale = supportedLocales.where(
32+
(element) => element.languageCode == locale.languageCode);
33+
if (supportedLocale.isNotEmpty) {
34+
return supportedLocale.first;
35+
}
36+
}
37+
}
38+
return null;
39+
},
40+
);
41+
}
42+
}
43+
44+
class HomePage extends StatelessWidget {
45+
const HomePage({Key? key}) : super(key: key);
46+
47+
@override
48+
Widget build(BuildContext context) {
49+
return Center(
50+
child: Text(context.t('Hello, world !')),
51+
);
52+
}
53+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: gettext_i18n
22
description: This package helps internationalizing a Flutter application.
3-
version: 1.0.1
3+
version: 1.0.2
44
repository: https://github.com/frenchguych/gettext_i18n
55

66
environment:

0 commit comments

Comments
 (0)