From fb22a0b2d12946d8ec80da2efc0418fc1380d57a Mon Sep 17 00:00:00 2001 From: Yannick Mauray Date: Sun, 14 Nov 2021 12:38:46 +0100 Subject: [PATCH] Improved i18n --- assets/i18n/de.po | 25 +-- assets/i18n/en.po | 28 +-- assets/i18n/fr.po | 28 +-- assets/i18n/quickgui.pot | 15 +- lib/src/i18n/i18n_ext.dart | 2 +- lib/src/i18n/quickgui_localizations.dart | 13 +- lib/src/pages/downloader.dart | 2 +- lib/src/pages/manager.dart | 209 +++++++++--------- lib/src/pages/version_selection.dart | 2 +- .../widgets/downloader/download_label.dart | 4 +- .../home_page/home_page_button_group.dart | 2 +- 11 files changed, 162 insertions(+), 168 deletions(-) diff --git a/assets/i18n/de.po b/assets/i18n/de.po index d21bcf5..f31ecb7 100644 --- a/assets/i18n/de.po +++ b/assets/i18n/de.po @@ -47,8 +47,8 @@ msgstr "Downloader" msgid "Downloading (no progress available)..." msgstr "Lädt herunter (Kein Fortschritt verfügbar) …" -msgid "Downloading..." -msgstr "Herunterladen …" +msgid "Downloading... {0}" +msgstr "Herunterladen … {0}" msgid "Manage existing machines" msgstr "Bestehende Maschinen verwalten" @@ -56,11 +56,11 @@ msgstr "Bestehende Maschinen verwalten" msgid "Manager" msgstr "Manager" -msgid "Mbs downloaded" -msgstr "MB heruntergeladen" +msgid "{0} Mbs downloaded" +msgstr "{0} MB heruntergeladen" -msgid "Now run" -msgstr "" +msgid "Now run {0} to start the VM" +msgstr "Now run {0} um die VM zu starten" msgid "OK" msgstr "OK" @@ -81,7 +81,7 @@ msgid "Select option" msgstr "Option auswählen" msgid "Select version for" -msgstr "Version auswählen für" +msgstr "Version auswählen für {0}" msgid "Select..." msgstr "Auswählen …" @@ -95,11 +95,8 @@ msgstr "SSH-Port" msgid "Stop The Virtual Machine?" msgstr "Die virtuelle Maschine stoppen?" -msgid "Target folder" -msgstr "Zielverzeichnis" - -msgid "to start the VM" -msgstr "um die VM zu starten" +msgid "Target folder : {0}" +msgstr "Zielverzeichnis : {0}" msgid "Use SPICE display" msgstr "SPICE-Display verwenden" @@ -113,5 +110,5 @@ msgstr "Version" msgid "Waiting for download to start" msgstr "Warten auf den Beginn des Downloads" -msgid "You are about to terminate the virtual machine" -msgstr "Sie sind dabei, die virtuelle Maschine zu beenden" +msgid "You are about to terminate the virtual machine {0}" +msgstr "Sie sind dabei, die virtuelle Maschine zu beenden {0}" diff --git a/assets/i18n/en.po b/assets/i18n/en.po index c7b643d..32fdef5 100644 --- a/assets/i18n/en.po +++ b/assets/i18n/en.po @@ -58,8 +58,8 @@ msgid "Downloading (no progress available)..." msgstr "Downloading (no progress available)..." #, fuzzy -msgid "Downloading..." -msgstr "Downloading..." +msgid "Downloading... {0}" +msgstr "Downloading... {0}" #, fuzzy msgid "Manage existing machines" @@ -70,12 +70,12 @@ msgid "Manager" msgstr "Manager" #, fuzzy -msgid "Mbs downloaded" -msgstr "Mbs downloaded" +msgid "{0} Mbs downloaded" +msgstr "{0} Mbs downloaded" #, fuzzy -msgid "Now run" -msgstr "Now run" +msgid "Now run {0} to start the VM" +msgstr "Now run {0} to start the VM" #, fuzzy msgid "OK" @@ -102,8 +102,8 @@ msgid "Select option" msgstr "Select option" #, fuzzy -msgid "Select version for" -msgstr "Select version for" +msgid "Select version for {0}" +msgstr "Select version for {0}" #, fuzzy msgid "Select..." @@ -122,12 +122,8 @@ msgid "Stop The Virtual Machine?" msgstr "Stop The Virtual Machine?" #, fuzzy -msgid "Target folder" -msgstr "Target folder" - -#, fuzzy -msgid "to start the VM" -msgstr "to start the VM" +msgid "Target folder : {0}" +msgstr "Target folder : {0}" #, fuzzy msgid "Use SPICE display" @@ -146,5 +142,5 @@ msgid "Waiting for download to start" msgstr "Waiting for download to start" #, fuzzy -msgid "You are about to terminate the virtual machine" -msgstr "You are about to terminate the virtual machine" +msgid "You are about to terminate the virtual machine {0}" +msgstr "You are about to terminate the virtual machine {0}" diff --git a/assets/i18n/fr.po b/assets/i18n/fr.po index 85389ea..0195c98 100644 --- a/assets/i18n/fr.po +++ b/assets/i18n/fr.po @@ -58,8 +58,8 @@ msgid "Downloading (no progress available)..." msgstr "Téléchargement (pas de barre de progression)..." #, fuzzy -msgid "Downloading..." -msgstr "Téléchargement..." +msgid "Downloading... {0}" +msgstr "Téléchargement... {0}" #, fuzzy msgid "Manage existing machines" @@ -70,12 +70,12 @@ msgid "Manager" msgstr "Gestionnaire" #, fuzzy -msgid "Mbs downloaded" -msgstr "Mbs téléchargés" +msgid "{0} Mbs downloaded" +msgstr "{0} Mbs téléchargés" #, fuzzy -msgid "Now run" -msgstr "Lancer" +msgid "Now run {0} to start the VM" +msgstr "Lancer {0} pour démarrer la machine virtuelle" #, fuzzy msgid "OK" @@ -102,8 +102,8 @@ msgid "Select option" msgstr "Sélectionner une option" #, fuzzy -msgid "Select version for" -msgstr "Sélectionner une version pour" +msgid "Select version for {0}" +msgstr "Sélectionner une version pour {0}" #, fuzzy msgid "Select..." @@ -122,12 +122,8 @@ msgid "Stop The Virtual Machine?" msgstr "Arrêtez la machine virtuelle ?" #, fuzzy -msgid "Target folder" -msgstr "Dossier cible" - -#, fuzzy -msgid "to start the VM" -msgstr "pour démarrer la machine virtuelle" +msgid "Target folder : {0}" +msgstr "Dossier cible : {0}" #, fuzzy msgid "Use SPICE display" @@ -146,5 +142,5 @@ msgid "Waiting for download to start" msgstr "En attente du début du téléchargement" #, fuzzy -msgid "You are about to terminate the virtual machine" -msgstr "Vous êtes sur le point d'arrêter la machine virtuelle" +msgid "You are about to terminate the virtual machine {0}" +msgstr "Vous êtes sur le point d'arrêter la machine virtuelle {0}" diff --git a/assets/i18n/quickgui.pot b/assets/i18n/quickgui.pot index 0352fe5..f8fc86f 100644 --- a/assets/i18n/quickgui.pot +++ b/assets/i18n/quickgui.pot @@ -46,7 +46,7 @@ msgstr "" msgid "Downloading (no progress available)..." msgstr "" -msgid "Downloading..." +msgid "Downloading... {0}" msgstr "" msgid "Manage existing machines" @@ -55,10 +55,10 @@ msgstr "" msgid "Manager" msgstr "" -msgid "Mbs downloaded" +msgid "{0} Mbs downloaded" msgstr "" -msgid "Now run" +msgid "Now run {0} to start the VM" msgstr "" msgid "OK" @@ -79,7 +79,7 @@ msgstr "" msgid "Select option" msgstr "" -msgid "Select version for" +msgid "Select version for {0}" msgstr "" msgid "Select..." @@ -94,10 +94,7 @@ msgstr "" msgid "Stop The Virtual Machine?" msgstr "" -msgid "Target folder" -msgstr "" - -msgid "to start the VM" +msgid "Target folder : {0}" msgstr "" msgid "Use SPICE display" @@ -112,5 +109,5 @@ msgstr "" msgid "Waiting for download to start" msgstr "" -msgid "You are about to terminate the virtual machine" +msgid "You are about to terminate the virtual machine {0}" msgstr "" diff --git a/lib/src/i18n/i18n_ext.dart b/lib/src/i18n/i18n_ext.dart index 7132ee7..41a85c6 100644 --- a/lib/src/i18n/i18n_ext.dart +++ b/lib/src/i18n/i18n_ext.dart @@ -3,5 +3,5 @@ import 'package:flutter/material.dart'; import 'quickgui_localizations.dart'; extension I18nExt on BuildContext { - t(String key) => QuickguiLocalizations.of(this).t(key); + t(String key, {List? args}) => QuickguiLocalizations.of(this).t(key, args); } diff --git a/lib/src/i18n/quickgui_localizations.dart b/lib/src/i18n/quickgui_localizations.dart index 1ed87ac..86d63f4 100644 --- a/lib/src/i18n/quickgui_localizations.dart +++ b/lib/src/i18n/quickgui_localizations.dart @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gettext/gettext.dart'; import 'package:gettext_parser/gettext_parser.dart' as gettext_parser; +import 'package:quiver/iterables.dart'; class QuickguiLocalizations { final _gt = Gettext( @@ -24,5 +25,15 @@ class QuickguiLocalizations { static QuickguiLocalizations of(BuildContext context) => Localizations.of(context, QuickguiLocalizations)!; - String t(String key) => _gt.gettext(key); + String t(String key, List? args) { + var message = _gt.gettext(key); + + if (args != null) { + for (var i in range(args.length)) { + message = message.replaceAll('{$i}', args[i.toInt()].toString()); + } + } + + return message; + } } diff --git a/lib/src/pages/downloader.dart b/lib/src/pages/downloader.dart index 086f6b6..1975ff7 100644 --- a/lib/src/pages/downloader.dart +++ b/lib/src/pages/downloader.dart @@ -130,7 +130,7 @@ class _DownloaderState extends State { ), Padding( padding: const EdgeInsets.only(top: 32), - child: Text('${context.t('Target folder')} : ${Directory.current}'), + child: Text(context.t('Target folder : {0}', args: [Directory.current])), ), ], ); diff --git a/lib/src/pages/manager.dart b/lib/src/pages/manager.dart index 734142d..fb658a6 100644 --- a/lib/src/pages/manager.dart +++ b/lib/src/pages/manager.dart @@ -226,133 +226,130 @@ class _ManagerState extends State with PreferencesMixin { color: active ? Colors.green : buttonColor, semanticLabel: active ? 'Running' : 'Run', ), - onPressed: active ? null : () async { - Map activeVms = _activeVms; - List args = ['--vm', currentVm + '.conf']; - if (_spicy) { - args.addAll(['--display', 'spice']); - } - await Process.start('quickemu', args); - VmInfo info = _parseVmInfo(currentVm); - activeVms[currentVm] = info; - setState(() { - _activeVms = activeVms; - }); - }), + onPressed: active + ? null + : () async { + Map activeVms = _activeVms; + List args = ['--vm', currentVm + '.conf']; + if (_spicy) { + args.addAll(['--display', 'spice']); + } + await Process.start('quickemu', args); + VmInfo info = _parseVmInfo(currentVm); + activeVms[currentVm] = info; + setState(() { + _activeVms = activeVms; + }); + }), IconButton( icon: Icon( active ? Icons.stop : Icons.stop_outlined, color: active ? Colors.red : null, semanticLabel: active ? 'Stop' : 'Not running', ), - onPressed: !active ? null : () { - showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - title: Text(context.t('Stop The Virtual Machine?')), - content: Text('${context.t('You are about to terminate the virtual machine')} $currentVm'), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: Text(context.t('Cancel')), - ), - TextButton( - onPressed: () => Navigator.pop(context, true), - child: Text(context.t('OK')), - ), - ], - ), - ).then((result) { - result = result ?? false; - if (result) { - Process.run('killall', [currentVm]); - setState(() { - _activeVms.remove(currentVm); - }); - } - }); - }, + onPressed: !active + ? null + : () { + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: Text(context.t('Stop The Virtual Machine?')), + content: Text(context.t('You are about to terminate the virtual machine', args: [currentVm])), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: Text(context.t('Cancel')), + ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: Text(context.t('OK')), + ), + ], + ), + ).then((result) { + result = result ?? false; + if (result) { + Process.run('killall', [currentVm]); + setState(() { + _activeVms.remove(currentVm); + }); + } + }); + }, ), ], )), if (connectInfo.isNotEmpty) ListTile( - title: Text( - connectInfo, - style: TextStyle(fontSize: 12) - ), - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ + title: Text(connectInfo, style: const TextStyle(fontSize: 12)), + trailing: Row(mainAxisSize: MainAxisSize.min, children: [ IconButton( icon: Icon( Icons.monitor, color: _spicy ? buttonColor : null, semanticLabel: 'Connect display with SPICE', ), - tooltip: _spicy? 'Connect display with SPICE' : 'SPICE client not found', - onPressed: !_spicy? null : () { - Process.start('spicy', ['-p', vmInfo.spicePort!]); - }, + tooltip: _spicy ? 'Connect display with SPICE' : 'SPICE client not found', + onPressed: !_spicy + ? null + : () { + Process.start('spicy', ['-p', vmInfo.spicePort!]); + }, ), IconButton( - icon: SvgPicture.asset( - 'assets/images/console.svg', - semanticsLabel: 'Connect with SSH', - color: sshy ? buttonColor : Colors.grey - ), + icon: SvgPicture.asset('assets/images/console.svg', semanticsLabel: 'Connect with SSH', color: sshy ? buttonColor : Colors.grey), tooltip: sshy ? 'Connect with SSH' : 'SSH server not detected on guest', - onPressed: !sshy ? null : () { - TextEditingController _usernameController = TextEditingController(); - showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - title: Text('Launch SSH connection to $currentVm'), - content: TextField( - controller: _usernameController, - decoration: const InputDecoration(hintText: "SSH username"), - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () => Navigator.pop(context, true), - child: const Text('Connect'), - ), - ], - ), - ).then((result) { - result = result ?? false; - if (result) { - List sshArgs = ['ssh', '-p', vmInfo.sshPort!, _usernameController.text + '@localhost']; - switch(_terminalEmulator) { - case 'gnome-terminal': - case 'mate-terminal': - sshArgs.insert(0, '--'); - break; - case 'xterm': - case 'konsole': - sshArgs.insert(0, '-e'); - break; - case 'terminator': - case 'xfce4-terminal': - sshArgs.insert(0, '-x'); - break; - case 'guake': - String command = sshArgs.join(' '); - sshArgs = ['-e', command]; - break; - } - Process.start(_terminalEmulator!, sshArgs); - } - }); - }, + onPressed: !sshy + ? null + : () { + TextEditingController _usernameController = TextEditingController(); + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: Text('Launch SSH connection to $currentVm'), + content: TextField( + controller: _usernameController, + decoration: const InputDecoration(hintText: "SSH username"), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: const Text('Connect'), + ), + ], + ), + ).then((result) { + result = result ?? false; + if (result) { + List sshArgs = ['ssh', '-p', vmInfo.sshPort!, _usernameController.text + '@localhost']; + switch (_terminalEmulator) { + case 'gnome-terminal': + case 'mate-terminal': + sshArgs.insert(0, '--'); + break; + case 'xterm': + case 'konsole': + sshArgs.insert(0, '-e'); + break; + case 'terminator': + case 'xfce4-terminal': + sshArgs.insert(0, '-x'); + break; + case 'guake': + String command = sshArgs.join(' '); + sshArgs = ['-e', command]; + break; + } + Process.start(_terminalEmulator!, sshArgs); + } + }); + }, ), - ] - ) - ), + ])), const Divider() ]; } diff --git a/lib/src/pages/version_selection.dart b/lib/src/pages/version_selection.dart index e7d7acb..12a6aab 100644 --- a/lib/src/pages/version_selection.dart +++ b/lib/src/pages/version_selection.dart @@ -21,7 +21,7 @@ class _VersionSelectionState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('${context.t('Select version for')} ${widget.operatingSystem.name}'), + title: Text(context.t('Select version for {0}', args: [widget.operatingSystem.name])), ), body: SingleChildScrollView( child: Column( diff --git a/lib/src/widgets/downloader/download_label.dart b/lib/src/widgets/downloader/download_label.dart index ad528a2..2e025dd 100644 --- a/lib/src/widgets/downloader/download_label.dart +++ b/lib/src/widgets/downloader/download_label.dart @@ -23,8 +23,8 @@ class DownloadLabel extends StatelessWidget { : data != null ? downloader != 'zsync' ? downloader == 'wget' - ? Text('${context.t('Downloading...')}${(data! * 100).toInt()}%') - : Text('$data ${context.t('Mbs downloaded')}') + ? Text(context.t('Downloading...{0}%', args: [(data! * 100).toInt()])) + : Text(context.t('{0} Mbs downloaded', args: [data!])) : Text(context.t("Downloading (no progress available)...")) : Text(context.t('Waiting for download to start')), ); diff --git a/lib/src/widgets/home_page/home_page_button_group.dart b/lib/src/widgets/home_page/home_page_button_group.dart index 910822b..abce3f9 100644 --- a/lib/src/widgets/home_page/home_page_button_group.dart +++ b/lib/src/widgets/home_page/home_page_button_group.dart @@ -160,7 +160,7 @@ class _HomePageButtonGroupState extends State { padding: const EdgeInsets.symmetric(vertical: 32), child: Text(context.t('Done !'), style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white)), ), - Text('${context.t('Now run')} "quickemu --vm $operatingSystem-$version" ${context.t('to start the VM')}', + Text(context.t('Now run {0} to start the VM', args: ["quickemu --vm $operatingSystem-$version"]), style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white)), Padding( padding: const EdgeInsets.symmetric(vertical: 32),