Skip to content

Commit

Permalink
l10n update
Browse files Browse the repository at this point in the history
  • Loading branch information
laiiihz committed Mar 1, 2022
1 parent 4c7ce81 commit 464ed00
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 38 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "devtoys",
"request": "launch",
"type": "dart"
},
{
"name": "devtoys (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
}
]
}
3 changes: 3 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: s.dart
8 changes: 6 additions & 2 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:devtoys/l10n/l10n.dart';
import 'package:devtoys/models/tool_items.dart';
import 'package:devtoys/views/settings_view.dart';
import 'package:devtoys/widgets/window_tool_widget.dart';
import 'package:fluent_ui/fluent_ui.dart';

Expand All @@ -16,7 +18,7 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
Widget child = NavigationView(
appBar: NavigationAppBar(
title: const Text('DevToys'),
title: Text(S.of(context).appName),
automaticallyImplyLeading: true,
leading: Image.asset('assets/logo/256x256.webp'),
),
Expand All @@ -43,7 +45,9 @@ class _HomePageState extends State<HomePage> {
if (index < naviUtil.realItems.length) {
return naviUtil.realItems[index].page;
}
return const SizedBox.shrink();

// return const SizedBox.shrink();
return const SettingsView();
},
),
);
Expand Down
13 changes: 13 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"appName": "DevToys",
"@appName": {
"description": "name of app"
},
"configuration": "configuration",
"conversion": "Conversion",
"selectConversion": "Select whitch conversion mode you want to use",
"encode": "Encode",
"decode": "Decode",
"input": "input",
"output": "output"
}
10 changes: 10 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appName": "DevToys",
"configuration": "配置",
"conversion": "转换",
"selectConversion": "选择您想使用的转换格式",
"encode": "编码",
"decode": "解码",
"input": "输入",
"output": "输出"
}
115 changes: 115 additions & 0 deletions lib/l10n/fluent_localization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';

class ZhFluentLocalization implements FluentLocalizations {
const ZhFluentLocalization();

@override
String get backButtonTooltip => 'Back';

@override
String get closeButtonLabel => 'Close';

@override
String get searchLabel => 'Search';

@override
String get closeNavigationTooltip => 'Close Navigation';

@override
String get openNavigationTooltip => 'Open Navigation';

@override
String get clickToSearch => 'Click to search';

@override
String get modalBarrierDismissLabel => 'Dismiss';

@override
String get minimizeWindowTooltip => 'Minimze';

@override
String get restoreWindowTooltip => 'Restore';

@override
String get closeWindowTooltip => 'Close';

@override
String get dialogLabel => 'Dialog';

@override
String get cutButtonLabel => 'Cut';

@override
String get copyButtonLabel => 'Copy';

@override
String get pasteButtonLabel => 'Paste';

@override
String get selectAllButtonLabel => 'Select all';

@override
String get newTabLabel => 'Add new tab';

@override
String get closeTabLabel => 'Close tab (Ctrl+F4)';

@override
String get scrollTabBackwardLabel => 'Scroll tab list backward';

@override
String get scrollTabForwardLabel => 'Scroll tab list forward';

@override
String get noResultsFoundLabel => '找不到结果';

/// Creates an object that provides US English resource values for the material
/// library widgets.
///
/// The [locale] parameter is ignored.
///
/// This method is typically used to create a [LocalizationsDelegate].
/// The [MaterialApp] does so by default.
static Future<FluentLocalizations> load(Locale locale) {
return SynchronousFuture(lookupAppLocalizations(locale));
}

static const LocalizationsDelegate<FluentLocalizations> delegate =
_CustomFluentLocalizationsDelegate();

static FluentLocalizations lookupAppLocalizations(Locale locale) {
// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'en':
return const DefaultFluentLocalizations();
case 'zh':
return const ZhFluentLocalization();
}

throw FlutterError(
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
}
}

class _CustomFluentLocalizationsDelegate
extends LocalizationsDelegate<FluentLocalizations> {
const _CustomFluentLocalizationsDelegate();

@override
bool isSupported(Locale locale) =>
locale.languageCode == 'en' || locale.languageCode == 'zh';

@override
Future<FluentLocalizations> load(Locale locale) =>
ZhFluentLocalization.load(locale);

@override
bool shouldReload(_CustomFluentLocalizationsDelegate old) => false;

@override
String toString() => 'DefaultFluentLocalizations.delegate(en_US)';
}
17 changes: 17 additions & 0 deletions lib/l10n/l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/s.dart';

class S {
static AppLocalizations of(BuildContext context) {
return AppLocalizations.of(context) ??
lookupAppLocalizations(const Locale('zh'));
}

static List<LocalizationsDelegate> get localizationsDelegates =>
AppLocalizations.localizationsDelegates;

static List<Locale> get supportedLocales => AppLocalizations.supportedLocales;

static LocalizationsDelegate<AppLocalizations> get delegate =>
AppLocalizations.delegate;
}
12 changes: 10 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:devtoys/home_page.dart';
import 'package:devtoys/l10n/fluent_localization.dart';
import 'package:devtoys/l10n/l10n.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
Expand All @@ -15,16 +18,21 @@ void main() async {
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return FluentApp(
title: 'DevToys',
onGenerateTitle: (context) => S.of(context).appName,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: const HomePage(),
debugShowCheckedModeBanner: false,
localizationsDelegates: [
S.delegate,
ZhFluentLocalization.delegate,
GlobalMaterialLocalizations.delegate,
],
supportedLocales: S.supportedLocales,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:devtoys/l10n/l10n.dart';
import 'package:devtoys/tools/encoders_decoders/base_64_encoder_decoder/base_64_provider.dart';
import 'package:devtoys/widgets/app_title.dart';
import 'package:devtoys/widgets/tool_view.dart';
Expand Down Expand Up @@ -37,17 +38,16 @@ class _Base64EncoderDecoderViewState extends State<Base64EncoderDecoderView> {
return ToolView.scrollVertical(
title: const Text('Base 64 Encoder/Decoder'),
children: [
const AppTitle(title: 'Config'),
AppTitle(title: S.of(context).configuration),
ToolViewConfig(
leading: const Icon(FluentIcons.switch_widget),
title: const Text('Conversion'),
subtitle:
const Text('Select whitch conversion mode you want to use'),
title: Text(S.of(context).conversion),
subtitle: Text(S.of(context).selectConversion),
trailing: Row(
children: [
_provider.isEncode
? const Text('Encode')
: const Text('Decode'),
? Text(S.of(context).encode)
: Text(S.of(context).decode),
ToggleSwitch(
checked: _provider.isEncode,
onChanged: (state) {
Expand All @@ -57,14 +57,20 @@ class _Base64EncoderDecoderViewState extends State<Base64EncoderDecoderView> {
],
)),
AppTitleWrapper(
title: 'input',
title: S.of(context).input,
actions: [
Button(
child: const Icon(FluentIcons.paste),
onPressed: () {
_provider.paste();
},
),
Button(
child: const Icon(FluentIcons.clear),
onPressed: () {
_provider.clear();
},
),
],
child: TextBox(
minLines: 10,
Expand All @@ -76,20 +82,14 @@ class _Base64EncoderDecoderViewState extends State<Base64EncoderDecoderView> {
),
),
AppTitleWrapper(
title: 'output',
title: S.of(context).output,
actions: [
Button(
child: const Icon(FluentIcons.copy),
onPressed: () {
_provider.paste();
},
),
Button(
child: const Icon(FluentIcons.clear),
onPressed: () {
_provider.clear();
},
),
],
child: TextBox(
minLines: 10,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:devtoys/l10n/l10n.dart';
import 'package:devtoys/tools/encoders_decoders/uri_encoder_decoder/uri_provider.dart';
import 'package:devtoys/widgets/app_title.dart';
import 'package:devtoys/widgets/tool_view.dart';
Expand Down Expand Up @@ -35,11 +36,11 @@ class _UriEncoderDecoderViewState extends State<UriEncoderDecoderView> {
return ToolView.scrollVertical(
title: const Text('Uri Encoder/Decoder'),
children: [
const AppTitle(title: 'Config'),
AppTitle(title: S.of(context).configuration),
ToolViewConfig(
leading: const Icon(FluentIcons.switch_widget),
title: const Text('Conversion'),
subtitle: const Text('Select whitch conversion mode you want to use'),
title: Text(S.of(context).conversion),
subtitle: Text(S.of(context).selectConversion),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -54,7 +55,7 @@ class _UriEncoderDecoderViewState extends State<UriEncoderDecoderView> {
),
),
AppTitleWrapper(
title: 'input',
title: S.of(context).input,
actions: [
Button(
child: const Icon(FluentIcons.paste),
Expand All @@ -75,7 +76,7 @@ class _UriEncoderDecoderViewState extends State<UriEncoderDecoderView> {
),
),
AppTitleWrapper(
title: 'output',
title: S.of(context).output,
actions: [
Button(
child: const Icon(FluentIcons.copy),
Expand Down
10 changes: 6 additions & 4 deletions lib/tools/formatters/abstract/formatter_base_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class _FormatterBaseViewState extends State<FormatterBaseView> {
onChanged: (text) {
try {
widget.base.convertIt();
} catch (e) {}
} catch (e) {
print(e);
}
},
),
outputWidget: TextBox(
Expand All @@ -51,22 +53,22 @@ class _FormatterBaseViewState extends State<FormatterBaseView> {
),
inputActions: [
Button(
child: const Text('paste'),
child: const Icon(FluentIcons.paste),
onPressed: () async {
final rawText = await Clipboard.getData('text/plain');
widget.base.inputController.text = rawText?.text ?? '';
},
),
Button(
child: const Text('clear'),
child: const Icon(FluentIcons.clear),
onPressed: () {
widget.base.clearAll();
},
),
],
outputActions: [
Button(
child: const Text('copy'),
child: const Icon(FluentIcons.copy),
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: widget.base.outputController.text),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _JsonFormtterViewState extends State<JsonFormtterView> {
@override
void dispose() {
provider.removeListener(update);
provider.dispose();
super.dispose();
}

Expand Down
Loading

0 comments on commit 464ed00

Please sign in to comment.