Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "easy_localization",
"request": "launch",
"type": "dart"
},
{
"name": "easy_localization (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "easy_localization (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "easy_logger",
"cwd": "packages/easy_logger",
"request": "launch",
"type": "dart"
},
{
"name": "easy_logger (profile mode)",
"cwd": "packages/easy_logger",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "easy_logger (release mode)",
"cwd": "packages/easy_logger",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
90 changes: 71 additions & 19 deletions example/lib/lang_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,41 @@ class LanguageView extends StatelessWidget {
),
),
),
_SwitchListTileMenuItem(
title: 'عربي',
subtitle: 'عربي',
locale:
context.supportedLocales[1] //BuildContext extension method
_SwitchListTileMenuItem(title: 'عربي', subtitle: 'عربي', locale: context.supportedLocales[1] //BuildContext extension method
),
_Divider(),
_SwitchListTileMenuItem(
title: 'English',
subtitle: 'English',
locale: context.supportedLocales[0]),
_SwitchListTileMenuItem(title: 'English', subtitle: 'English', locale: context.supportedLocales[0]),
_Divider(),
_SwitchListTileMenuItem(
title: 'German',
subtitle: 'German',
locale: context.supportedLocales[2]),
_SwitchListTileMenuItem(title: 'German', subtitle: 'German', locale: context.supportedLocales[2]),
_Divider(),
_SwitchListTileMenuItem(
title: 'Русский',
subtitle: 'Русский',
locale: context.supportedLocales[3]),
_SwitchListTileMenuItem(title: 'Русский', subtitle: 'Русский', locale: context.supportedLocales[3]),
_Divider(),
SizedBox(
height: 250,
),
Container(
padding: EdgeInsets.only(top: 26),
margin: EdgeInsets.symmetric(
horizontal: 24,
),
child: Text(
'Choose sub language',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w700,
fontSize: 18,
),
),
),
_SwitchSubListTileMenuItem(title: 'عربي', subtitle: 'عربي', subLocale: context.supportedLocales[1] //BuildContext extension method
),
_Divider(),
_SwitchSubListTileMenuItem(title: 'English', subtitle: 'English', subLocale: context.supportedLocales[0]),
_Divider(),
_SwitchSubListTileMenuItem(title: 'German', subtitle: 'German', subLocale: context.supportedLocales[2]),
_Divider(),
_SwitchSubListTileMenuItem(title: 'Русский', subtitle: 'Русский', subLocale: context.supportedLocales[3]),
_Divider(),
],
),
Expand Down Expand Up @@ -100,8 +114,7 @@ class _SwitchListTileMenuItem extends StatelessWidget {
return Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 5),
decoration: BoxDecoration(
border:
isSelected(context) ? Border.all(color: Colors.blueAccent) : null,
border: isSelected(context) ? Border.all(color: Colors.blueAccent) : null,
),
child: ListTile(
dense: true,
Expand All @@ -120,3 +133,42 @@ class _SwitchListTileMenuItem extends StatelessWidget {
);
}
}

class _SwitchSubListTileMenuItem extends StatelessWidget {
const _SwitchSubListTileMenuItem({
Key? key,
required this.title,
required this.subtitle,
required this.subLocale,
}) : super(key: key);

final String title;
final String subtitle;
final Locale subLocale;

bool isSelected(BuildContext context) => subLocale == context.subLocale;

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 5),
decoration: BoxDecoration(
border: isSelected(context) ? Border.all(color: Colors.blueAccent) : null,
),
child: ListTile(
dense: true,
// isThreeLine: true,
title: Text(
title,
),
subtitle: Text(
subtitle,
),
onTap: () async {
log(subLocale.toString(), name: toString());
await context.setSubLocale(subLocale); //BuildContext extension method
Navigator.pop(context);
}),
);
}
}
37 changes: 10 additions & 27 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ void main() async {
await EasyLocalization.ensureInitialized();

runApp(EasyLocalization(
supportedLocales: [
Locale('en', 'US'),
Locale('ar', 'DZ'),
Locale('de', 'DE'),
Locale('ru', 'RU')
],
supportedLocales: [Locale('en', 'US'), Locale('ar', 'DZ'), Locale('de', 'DE'), Locale('ru', 'RU')],
path: 'resources/langs',
child: MyApp(),
// fallbackLocale: Locale('en', 'US'),
Expand Down Expand Up @@ -88,13 +83,12 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => LanguageView(), fullscreenDialog: true),
MaterialPageRoute(builder: (_) => LanguageView(), fullscreenDialog: true),
);
},
child: Icon(
Icons.language,
color: Colors.white,
color: Colors.black,
),
),
],
Expand All @@ -108,17 +102,11 @@ class _MyHomePageState extends State<MyHomePage> {
),
Text(
LocaleKeys.gender_with_arg,
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 19,
fontWeight: FontWeight.bold),
style: TextStyle(color: Colors.grey.shade600, fontSize: 19, fontWeight: FontWeight.bold),
).tr(args: ['aissat'], gender: _gender ? 'female' : 'male'),
Text(
tr(LocaleKeys.gender, gender: _gender ? 'female' : 'male'),
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 15,
fontWeight: FontWeight.bold),
style: TextStyle(color: Colors.grey.shade600, fontSize: 15, fontWeight: FontWeight.bold),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -132,8 +120,9 @@ class _MyHomePageState extends State<MyHomePage> {
flex: 1,
),
Text(LocaleKeys.msg).tr(args: ['aissat', 'Flutter']),
Text(LocaleKeys.msg_named)
.tr(namedArgs: {'lang': 'Dart'}, args: ['Easy localization']),
Text(LocaleKeys.msg_named).tr(namedArgs: {'lang': 'Dart'}, args: ['Easy localization']),
Text("Sub language:"),
Text(LocaleKeys.msg).trSub(args: ['aissat', 'Flutter']),
Text(LocaleKeys.clicked).plural(counter),
TextButton(
onPressed: () {
Expand All @@ -144,14 +133,8 @@ class _MyHomePageState extends State<MyHomePage> {
SizedBox(
height: 15,
),
Text(
plural(LocaleKeys.amount, counter,
format: NumberFormat.currency(
locale: Intl.defaultLocale, symbol: '€')),
style: TextStyle(
color: Colors.grey.shade900,
fontSize: 18,
fontWeight: FontWeight.bold)),
Text(plural(LocaleKeys.amount, counter, format: NumberFormat.currency(locale: Intl.defaultLocale, symbol: '€')),
style: TextStyle(color: Colors.grey.shade900, fontSize: 18, fontWeight: FontWeight.bold)),
SizedBox(
height: 20,
),
Expand Down
Loading