Skip to content

Commit

Permalink
Merge pull request #34 from bostrot/multilanguage
Browse files Browse the repository at this point in the history
Added localization support
  • Loading branch information
bostrot authored May 17, 2022
2 parents 75af36f + c3e986d commit 9f3bfdb
Show file tree
Hide file tree
Showing 27 changed files with 606 additions and 363 deletions.
Binary file modified build/windows/runner/Release/data/app.so
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"packages/fluent_ui/assets/AcrylicNoise.png":["packages/fluent_ui/assets/AcrylicNoise.png"],"packages/fluent_ui/fonts/FluentIcons.ttf":["packages/fluent_ui/fonts/FluentIcons.ttf"]}
{"lib/i18n/de.json":["lib/i18n/de.json"],"lib/i18n/en.json":["lib/i18n/en.json"],"packages/fluent_ui/assets/AcrylicNoise.png":["packages/fluent_ui/assets/AcrylicNoise.png"],"packages/fluent_ui/fonts/FluentIcons.ttf":["packages/fluent_ui/fonts/FluentIcons.ttf"],"packages/localization/test/assets/lang/en_US.json":["packages/localization/test/assets/lang/en_US.json"],"packages/localization/test/assets/lang/pt_BR.json":["packages/localization/test/assets/lang/pt_BR.json"],"packages/localization/test/assets/lang2/en_US.json":["packages/localization/test/assets/lang2/en_US.json"],"packages/localization/test/assets/lang2/pt_BR.json":["packages/localization/test/assets/lang2/pt_BR.json"]}
Binary file modified build/windows/runner/Release/data/flutter_assets/NOTICES.Z
Binary file not shown.
Binary file modified build/windows/runner/Release/wsl2distromanager.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/components/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:convert' show Utf8Decoder, json, utf8;
import 'package:dio/dio.dart';
import 'package:localization/localization.dart';
import 'constants.dart';
import 'helpers.dart';
// import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -85,7 +86,7 @@ class WSLApi {
byteSize = file.lengthSync();
}
double size = byteSize / 1024 / 1024 / 1024; // Convert to GB
return 'Size: ' + size.toStringAsFixed(2) + ' GB';
return '${'size-text'.i18n()}: ' + size.toStringAsFixed(2) + ' GB';
} catch (e) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/constants.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Update on release
const String currentVersion = "v1.1.0";
const String currentVersion = "v1.2.1";
const String windowsStoreUrl = "https://www.microsoft.com/store/"
"productId/9NWS9K95NMJB";
const String defaultPath = 'C:\\WSL2-Distros\\';
Expand Down
12 changes: 1 addition & 11 deletions lib/components/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';

late String language;
late SharedPreferences prefs;

/// Get distro label from item
Expand All @@ -18,13 +18,3 @@ String distroLabel(String item) {
Future initPrefs() async {
prefs = await SharedPreferences.getInstance();
}

/// Launch a URL in the default browser
/// @param url: URL to launch
void launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
6 changes: 3 additions & 3 deletions lib/components/list.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:localization/localization.dart';
import 'package:wsl2distromanager/components/api.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:wsl2distromanager/dialogs/dialogs.dart';
Expand Down Expand Up @@ -60,10 +61,9 @@ FutureBuilder<Instances> distroList(WSLApi api,
List<String> running = snapshot.data?.running ?? [];
// Check if there are distros
if (list.isEmpty) {
return const Expanded(
return Expanded(
child: Center(
child: Text(
'No instances found or there is a migration process running.'),
child: Text('noinstancesfound-text'.i18n()),
),
);
}
Expand Down
27 changes: 16 additions & 11 deletions lib/components/list_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:localization/localization.dart';
import 'package:wsl2distromanager/components/api.dart';
import 'package:wsl2distromanager/components/theme.dart';

Expand Down Expand Up @@ -95,12 +96,15 @@ class _ListItemState extends State<ListItem> {
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: isRunning(widget.item, widget.running)
? (Text(distroLabel(widget.item) + ' (running)'))
? (Text(distroLabel(widget.item) +
' (' +
'running-text'.i18n() +
')'))
: Text(distroLabel(widget.item)))),
), // running here
leading: Row(children: [
Tooltip(
message: 'Start',
message: 'start-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -113,7 +117,7 @@ class _ListItemState extends State<ListItem> {
),
isRunning(widget.item, widget.running)
? Tooltip(
message: 'Stop',
message: 'stop-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand Down Expand Up @@ -148,7 +152,8 @@ class _ListItemState extends State<ListItem> {
void stopInstance() {
plausible.event(name: "wsl_stopped");
WSLApi().stop(widget.item);
widget.statusMsg('${widget.item} stopped.');
widget.statusMsg('${widget.item} ${'stopped-text'.i18n()}.',
loading: false);
}

void startInstance() {
Expand All @@ -165,7 +170,7 @@ class _ListItemState extends State<ListItem> {
startPath: startPath, startUser: startName, startCmd: startCmd);

Future.delayed(const Duration(milliseconds: 500),
widget.statusMsg('${widget.item} started.'));
widget.statusMsg('${widget.item} ${'started-text'.i18n()}.'));
}
}

Expand All @@ -188,7 +193,7 @@ class Bar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
children: [
Tooltip(
message: 'Open with File Explorer',
message: 'openwithexplorer-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -204,7 +209,7 @@ class Bar extends StatelessWidget {
),
),
Tooltip(
message: 'Open with Visual Studio Code',
message: 'openwithvscode-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -221,7 +226,7 @@ class Bar extends StatelessWidget {
),
),
Tooltip(
message: 'Copy',
message: 'copy-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -233,7 +238,7 @@ class Bar extends StatelessWidget {
),
),
Tooltip(
message: 'Rename',
message: 'rename-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -245,7 +250,7 @@ class Bar extends StatelessWidget {
),
),
Tooltip(
message: 'Delete',
message: 'delete-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand All @@ -256,7 +261,7 @@ class Bar extends StatelessWidget {
),
),
Tooltip(
message: 'Settings',
message: 'settings-text'.i18n(),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: IconButton(
Expand Down
18 changes: 10 additions & 8 deletions lib/components/sync.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:localization/localization.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';
import 'package:wsl2distromanager/components/api.dart';
Expand All @@ -20,7 +21,7 @@ class Sync {
Sync.instance(this.distroName, this.statusMsg) {
String? distroLocation = prefs.getString('Path_' + distroName);
if (distroLocation == null) {
statusMsg('Distro not found', loading: false);
statusMsg('distronotfound-text'.i18n(), loading: false);
return;
}
this.distroLocation = distroLocation.replaceAll('/', '\\');
Expand Down Expand Up @@ -60,25 +61,26 @@ class Sync {
// Get path for distro filesystem
String? syncIP = prefs.getString('SyncIP');
if (syncIP == null) {
statusMsg('Sync IP not set. Please set it in the settings.',
loading: false);
statusMsg('syncipnotset-text'.i18n(), loading: false);
return;
}
statusMsg('Shutting down WSL...', loading: true);
statusMsg('${'shuttingdownwsl-text'.i18n()}...', loading: true);
// Shutdown WSL
await WSLApi().shutdown();
statusMsg('Connecting to IP: "$syncIP"...', loading: true);
statusMsg('${'connectingtoip-text'.i18n()}: "$syncIP"...', loading: true);
Dio().download(
'http://$syncIP:59132/ext4.vhdx', distroLocation + '\\ext4.vhdx',
onReceiveProgress: (received, total) {
String rec = (received / 1024 / 1024).toStringAsFixed(2);
String tot = (total / 1024 / 1024).toStringAsFixed(2);
statusMsg('Downloading $distroName, $rec MB / $tot MB', loading: true);
statusMsg('${'downloading-text'.i18n()} $distroName, $rec MB / $tot MB',
loading: true);
if (received == total) {
statusMsg('Downloaded $distroName');
statusMsg('${'downloaded-text'.i18n()} $distroName');
}
}).catchError((e) {
statusMsg('Error downloading $distroName', loading: false);
statusMsg('${'errordownloading-text'.i18n()} $distroName',
loading: false);
});
}
}
5 changes: 3 additions & 2 deletions lib/dialogs/base_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:localization/localization.dart';
import 'package:wsl2distromanager/components/analytics.dart';

dialog({
Expand All @@ -14,7 +15,7 @@ dialog({
ButtonStyle submitStyle = const ButtonStyle(),
bool submitInput = true,
bool centerText = false,
String cancelText = 'Cancel',
String cancelText = '',
Function? onCancel,
}) {
final controller = TextEditingController();
Expand Down Expand Up @@ -59,7 +60,7 @@ dialog({
})
: Container(),
Button(
child: Text(cancelText),
child: Text(cancelText == '' ? 'cancel-text'.i18n() : cancelText),
onPressed: () {
if (onCancel != null) {
onCancel();
Expand Down
16 changes: 9 additions & 7 deletions lib/dialogs/copy_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:localization/localization.dart';
import 'package:wsl2distromanager/components/analytics.dart';
import 'package:wsl2distromanager/components/api.dart';
import 'package:wsl2distromanager/dialogs/base_dialog.dart';
Expand All @@ -17,14 +18,13 @@ copyDialog(context, item, Function(String, {bool loading}) statusMsg) {
context: context,
item: item,
statusMsg: statusMsg,
title: 'Copy \'$item\'',
body: 'Copy the WSL instance \'${distroLabel(item)}\' to a new instance'
' with this name.',
submitText: 'Copy',
title: '${'copy-text'.i18n()} \'$item\'',
body: 'copyinstance-text'.i18n([distroLabel(item)]),
submitText: 'copy-text'.i18n(),
submitStyle: const ButtonStyle(),
onSubmit: (inputText) async {
if (inputText.length > 0) {
statusMsg('Copying $item. This might take a while...', loading: true);
statusMsg('copyinginstance-text'.i18n([item]), loading: true);
await api.copy(item, inputText);
// Copy settings
String? startPath = prefs.getString('StartPath_' + item) ?? '';
Expand All @@ -33,9 +33,11 @@ copyDialog(context, item, Function(String, {bool loading}) statusMsg) {
prefs.setString('StartUser_' + inputText, startName);
// Save distro path
prefs.setString('Path_' + inputText, defaultPath + inputText);
statusMsg('DONE: Copied ${distroLabel(item)} to $inputText.');
statusMsg(
'donecopyinginstance-text'.i18n([distroLabel(item), inputText]),
loading: false);
} else {
statusMsg('ERROR: Please enter a name for the new instance.');
statusMsg('errorentername-text'.i18n(), loading: false);
}
});
}
Loading

0 comments on commit 9f3bfdb

Please sign in to comment.