Improved i18n

This commit is contained in:
Yannick Mauray 2021-11-14 12:38:46 +01:00
parent c9737423a9
commit fb22a0b2d1
No known key found for this signature in database
GPG Key ID: 67C4AAC5E99CB909
11 changed files with 162 additions and 168 deletions

View File

@ -47,8 +47,8 @@ msgstr "Downloader"
msgid "Downloading (no progress available)..." msgid "Downloading (no progress available)..."
msgstr "Lädt herunter (Kein Fortschritt verfügbar) …" msgstr "Lädt herunter (Kein Fortschritt verfügbar) …"
msgid "Downloading..." msgid "Downloading... {0}"
msgstr "Herunterladen …" msgstr "Herunterladen  {0}"
msgid "Manage existing machines" msgid "Manage existing machines"
msgstr "Bestehende Maschinen verwalten" msgstr "Bestehende Maschinen verwalten"
@ -56,11 +56,11 @@ msgstr "Bestehende Maschinen verwalten"
msgid "Manager" msgid "Manager"
msgstr "Manager" msgstr "Manager"
msgid "Mbs downloaded" msgid "{0} Mbs downloaded"
msgstr "MB heruntergeladen" msgstr "{0} MB heruntergeladen"
msgid "Now run" msgid "Now run {0} to start the VM"
msgstr "" msgstr "Now run {0} um die VM zu starten"
msgid "OK" msgid "OK"
msgstr "OK" msgstr "OK"
@ -81,7 +81,7 @@ msgid "Select option"
msgstr "Option auswählen" msgstr "Option auswählen"
msgid "Select version for" msgid "Select version for"
msgstr "Version auswählen für" msgstr "Version auswählen für {0}"
msgid "Select..." msgid "Select..."
msgstr "Auswählen …" msgstr "Auswählen …"
@ -95,11 +95,8 @@ msgstr "SSH-Port"
msgid "Stop The Virtual Machine?" msgid "Stop The Virtual Machine?"
msgstr "Die virtuelle Maschine stoppen?" msgstr "Die virtuelle Maschine stoppen?"
msgid "Target folder" msgid "Target folder : {0}"
msgstr "Zielverzeichnis" msgstr "Zielverzeichnis : {0}"
msgid "to start the VM"
msgstr "um die VM zu starten"
msgid "Use SPICE display" msgid "Use SPICE display"
msgstr "SPICE-Display verwenden" msgstr "SPICE-Display verwenden"
@ -113,5 +110,5 @@ msgstr "Version"
msgid "Waiting for download to start" msgid "Waiting for download to start"
msgstr "Warten auf den Beginn des Downloads" msgstr "Warten auf den Beginn des Downloads"
msgid "You are about to terminate the virtual machine" msgid "You are about to terminate the virtual machine {0}"
msgstr "Sie sind dabei, die virtuelle Maschine zu beenden" msgstr "Sie sind dabei, die virtuelle Maschine zu beenden {0}"

View File

@ -58,8 +58,8 @@ msgid "Downloading (no progress available)..."
msgstr "Downloading (no progress available)..." msgstr "Downloading (no progress available)..."
#, fuzzy #, fuzzy
msgid "Downloading..." msgid "Downloading... {0}"
msgstr "Downloading..." msgstr "Downloading... {0}"
#, fuzzy #, fuzzy
msgid "Manage existing machines" msgid "Manage existing machines"
@ -70,12 +70,12 @@ msgid "Manager"
msgstr "Manager" msgstr "Manager"
#, fuzzy #, fuzzy
msgid "Mbs downloaded" msgid "{0} Mbs downloaded"
msgstr "Mbs downloaded" msgstr "{0} Mbs downloaded"
#, fuzzy #, fuzzy
msgid "Now run" msgid "Now run {0} to start the VM"
msgstr "Now run" msgstr "Now run {0} to start the VM"
#, fuzzy #, fuzzy
msgid "OK" msgid "OK"
@ -102,8 +102,8 @@ msgid "Select option"
msgstr "Select option" msgstr "Select option"
#, fuzzy #, fuzzy
msgid "Select version for" msgid "Select version for {0}"
msgstr "Select version for" msgstr "Select version for {0}"
#, fuzzy #, fuzzy
msgid "Select..." msgid "Select..."
@ -122,12 +122,8 @@ msgid "Stop The Virtual Machine?"
msgstr "Stop The Virtual Machine?" msgstr "Stop The Virtual Machine?"
#, fuzzy #, fuzzy
msgid "Target folder" msgid "Target folder : {0}"
msgstr "Target folder" msgstr "Target folder : {0}"
#, fuzzy
msgid "to start the VM"
msgstr "to start the VM"
#, fuzzy #, fuzzy
msgid "Use SPICE display" msgid "Use SPICE display"
@ -146,5 +142,5 @@ msgid "Waiting for download to start"
msgstr "Waiting for download to start" msgstr "Waiting for download to start"
#, fuzzy #, fuzzy
msgid "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" msgstr "You are about to terminate the virtual machine {0}"

View File

@ -58,8 +58,8 @@ msgid "Downloading (no progress available)..."
msgstr "Téléchargement (pas de barre de progression)..." msgstr "Téléchargement (pas de barre de progression)..."
#, fuzzy #, fuzzy
msgid "Downloading..." msgid "Downloading... {0}"
msgstr "Téléchargement..." msgstr "Téléchargement... {0}"
#, fuzzy #, fuzzy
msgid "Manage existing machines" msgid "Manage existing machines"
@ -70,12 +70,12 @@ msgid "Manager"
msgstr "Gestionnaire" msgstr "Gestionnaire"
#, fuzzy #, fuzzy
msgid "Mbs downloaded" msgid "{0} Mbs downloaded"
msgstr "Mbs téléchargés" msgstr "{0} Mbs téléchargés"
#, fuzzy #, fuzzy
msgid "Now run" msgid "Now run {0} to start the VM"
msgstr "Lancer" msgstr "Lancer {0} pour démarrer la machine virtuelle"
#, fuzzy #, fuzzy
msgid "OK" msgid "OK"
@ -102,8 +102,8 @@ msgid "Select option"
msgstr "Sélectionner une option" msgstr "Sélectionner une option"
#, fuzzy #, fuzzy
msgid "Select version for" msgid "Select version for {0}"
msgstr "Sélectionner une version pour" msgstr "Sélectionner une version pour {0}"
#, fuzzy #, fuzzy
msgid "Select..." msgid "Select..."
@ -122,12 +122,8 @@ msgid "Stop The Virtual Machine?"
msgstr "Arrêtez la machine virtuelle ?" msgstr "Arrêtez la machine virtuelle ?"
#, fuzzy #, fuzzy
msgid "Target folder" msgid "Target folder : {0}"
msgstr "Dossier cible" msgstr "Dossier cible : {0}"
#, fuzzy
msgid "to start the VM"
msgstr "pour démarrer la machine virtuelle"
#, fuzzy #, fuzzy
msgid "Use SPICE display" msgid "Use SPICE display"
@ -146,5 +142,5 @@ msgid "Waiting for download to start"
msgstr "En attente du début du téléchargement" msgstr "En attente du début du téléchargement"
#, fuzzy #, fuzzy
msgid "You are about to terminate the virtual machine" msgid "You are about to terminate the virtual machine {0}"
msgstr "Vous êtes sur le point d'arrêter la machine virtuelle" msgstr "Vous êtes sur le point d'arrêter la machine virtuelle {0}"

View File

@ -46,7 +46,7 @@ msgstr ""
msgid "Downloading (no progress available)..." msgid "Downloading (no progress available)..."
msgstr "" msgstr ""
msgid "Downloading..." msgid "Downloading... {0}"
msgstr "" msgstr ""
msgid "Manage existing machines" msgid "Manage existing machines"
@ -55,10 +55,10 @@ msgstr ""
msgid "Manager" msgid "Manager"
msgstr "" msgstr ""
msgid "Mbs downloaded" msgid "{0} Mbs downloaded"
msgstr "" msgstr ""
msgid "Now run" msgid "Now run {0} to start the VM"
msgstr "" msgstr ""
msgid "OK" msgid "OK"
@ -79,7 +79,7 @@ msgstr ""
msgid "Select option" msgid "Select option"
msgstr "" msgstr ""
msgid "Select version for" msgid "Select version for {0}"
msgstr "" msgstr ""
msgid "Select..." msgid "Select..."
@ -94,10 +94,7 @@ msgstr ""
msgid "Stop The Virtual Machine?" msgid "Stop The Virtual Machine?"
msgstr "" msgstr ""
msgid "Target folder" msgid "Target folder : {0}"
msgstr ""
msgid "to start the VM"
msgstr "" msgstr ""
msgid "Use SPICE display" msgid "Use SPICE display"
@ -112,5 +109,5 @@ msgstr ""
msgid "Waiting for download to start" msgid "Waiting for download to start"
msgstr "" msgstr ""
msgid "You are about to terminate the virtual machine" msgid "You are about to terminate the virtual machine {0}"
msgstr "" msgstr ""

View File

@ -3,5 +3,5 @@ import 'package:flutter/material.dart';
import 'quickgui_localizations.dart'; import 'quickgui_localizations.dart';
extension I18nExt on BuildContext { extension I18nExt on BuildContext {
t(String key) => QuickguiLocalizations.of(this).t(key); t(String key, {List<Object>? args}) => QuickguiLocalizations.of(this).t(key, args);
} }

View File

@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gettext/gettext.dart'; import 'package:gettext/gettext.dart';
import 'package:gettext_parser/gettext_parser.dart' as gettext_parser; import 'package:gettext_parser/gettext_parser.dart' as gettext_parser;
import 'package:quiver/iterables.dart';
class QuickguiLocalizations { class QuickguiLocalizations {
final _gt = Gettext( final _gt = Gettext(
@ -24,5 +25,15 @@ class QuickguiLocalizations {
static QuickguiLocalizations of(BuildContext context) => Localizations.of<QuickguiLocalizations>(context, QuickguiLocalizations)!; static QuickguiLocalizations of(BuildContext context) => Localizations.of<QuickguiLocalizations>(context, QuickguiLocalizations)!;
String t(String key) => _gt.gettext(key); String t(String key, List<Object>? 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;
}
} }

View File

@ -130,7 +130,7 @@ class _DownloaderState extends State<Downloader> {
), ),
Padding( Padding(
padding: const EdgeInsets.only(top: 32), padding: const EdgeInsets.only(top: 32),
child: Text('${context.t('Target folder')} : ${Directory.current}'), child: Text(context.t('Target folder : {0}', args: [Directory.current])),
), ),
], ],
); );

View File

@ -226,133 +226,130 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
color: active ? Colors.green : buttonColor, color: active ? Colors.green : buttonColor,
semanticLabel: active ? 'Running' : 'Run', semanticLabel: active ? 'Running' : 'Run',
), ),
onPressed: active ? null : () async { onPressed: active
Map<String, VmInfo> activeVms = _activeVms; ? null
List<String> args = ['--vm', currentVm + '.conf']; : () async {
if (_spicy) { Map<String, VmInfo> activeVms = _activeVms;
args.addAll(['--display', 'spice']); List<String> args = ['--vm', currentVm + '.conf'];
} if (_spicy) {
await Process.start('quickemu', args); args.addAll(['--display', 'spice']);
VmInfo info = _parseVmInfo(currentVm); }
activeVms[currentVm] = info; await Process.start('quickemu', args);
setState(() { VmInfo info = _parseVmInfo(currentVm);
_activeVms = activeVms; activeVms[currentVm] = info;
}); setState(() {
}), _activeVms = activeVms;
});
}),
IconButton( IconButton(
icon: Icon( icon: Icon(
active ? Icons.stop : Icons.stop_outlined, active ? Icons.stop : Icons.stop_outlined,
color: active ? Colors.red : null, color: active ? Colors.red : null,
semanticLabel: active ? 'Stop' : 'Not running', semanticLabel: active ? 'Stop' : 'Not running',
), ),
onPressed: !active ? null : () { onPressed: !active
showDialog<bool>( ? null
context: context, : () {
builder: (BuildContext context) => AlertDialog( showDialog<bool>(
title: Text(context.t('Stop The Virtual Machine?')), context: context,
content: Text('${context.t('You are about to terminate the virtual machine')} $currentVm'), builder: (BuildContext context) => AlertDialog(
actions: <Widget>[ title: Text(context.t('Stop The Virtual Machine?')),
TextButton( content: Text(context.t('You are about to terminate the virtual machine', args: [currentVm])),
onPressed: () => Navigator.pop(context, false), actions: <Widget>[
child: Text(context.t('Cancel')), TextButton(
), onPressed: () => Navigator.pop(context, false),
TextButton( child: Text(context.t('Cancel')),
onPressed: () => Navigator.pop(context, true), ),
child: Text(context.t('OK')), TextButton(
), onPressed: () => Navigator.pop(context, true),
], child: Text(context.t('OK')),
), ),
).then((result) { ],
result = result ?? false; ),
if (result) { ).then((result) {
Process.run('killall', [currentVm]); result = result ?? false;
setState(() { if (result) {
_activeVms.remove(currentVm); Process.run('killall', [currentVm]);
}); setState(() {
} _activeVms.remove(currentVm);
}); });
}, }
});
},
), ),
], ],
)), )),
if (connectInfo.isNotEmpty) if (connectInfo.isNotEmpty)
ListTile( ListTile(
title: Text( title: Text(connectInfo, style: const TextStyle(fontSize: 12)),
connectInfo, trailing: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
style: TextStyle(fontSize: 12)
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(
Icons.monitor, Icons.monitor,
color: _spicy ? buttonColor : null, color: _spicy ? buttonColor : null,
semanticLabel: 'Connect display with SPICE', semanticLabel: 'Connect display with SPICE',
), ),
tooltip: _spicy? 'Connect display with SPICE' : 'SPICE client not found', tooltip: _spicy ? 'Connect display with SPICE' : 'SPICE client not found',
onPressed: !_spicy? null : () { onPressed: !_spicy
Process.start('spicy', ['-p', vmInfo.spicePort!]); ? null
}, : () {
Process.start('spicy', ['-p', vmInfo.spicePort!]);
},
), ),
IconButton( IconButton(
icon: SvgPicture.asset( icon: SvgPicture.asset('assets/images/console.svg', semanticsLabel: 'Connect with SSH', color: sshy ? buttonColor : Colors.grey),
'assets/images/console.svg',
semanticsLabel: 'Connect with SSH',
color: sshy ? buttonColor : Colors.grey
),
tooltip: sshy ? 'Connect with SSH' : 'SSH server not detected on guest', tooltip: sshy ? 'Connect with SSH' : 'SSH server not detected on guest',
onPressed: !sshy ? null : () { onPressed: !sshy
TextEditingController _usernameController = TextEditingController(); ? null
showDialog<bool>( : () {
context: context, TextEditingController _usernameController = TextEditingController();
builder: (BuildContext context) => AlertDialog( showDialog<bool>(
title: Text('Launch SSH connection to $currentVm'), context: context,
content: TextField( builder: (BuildContext context) => AlertDialog(
controller: _usernameController, title: Text('Launch SSH connection to $currentVm'),
decoration: const InputDecoration(hintText: "SSH username"), content: TextField(
), controller: _usernameController,
actions: <Widget>[ decoration: const InputDecoration(hintText: "SSH username"),
TextButton( ),
onPressed: () => Navigator.pop(context, false), actions: <Widget>[
child: const Text('Cancel'), TextButton(
), onPressed: () => Navigator.pop(context, false),
TextButton( child: const Text('Cancel'),
onPressed: () => Navigator.pop(context, true), ),
child: const Text('Connect'), TextButton(
), onPressed: () => Navigator.pop(context, true),
], child: const Text('Connect'),
), ),
).then((result) { ],
result = result ?? false; ),
if (result) { ).then((result) {
List<String> sshArgs = ['ssh', '-p', vmInfo.sshPort!, _usernameController.text + '@localhost']; result = result ?? false;
switch(_terminalEmulator) { if (result) {
case 'gnome-terminal': List<String> sshArgs = ['ssh', '-p', vmInfo.sshPort!, _usernameController.text + '@localhost'];
case 'mate-terminal': switch (_terminalEmulator) {
sshArgs.insert(0, '--'); case 'gnome-terminal':
break; case 'mate-terminal':
case 'xterm': sshArgs.insert(0, '--');
case 'konsole': break;
sshArgs.insert(0, '-e'); case 'xterm':
break; case 'konsole':
case 'terminator': sshArgs.insert(0, '-e');
case 'xfce4-terminal': break;
sshArgs.insert(0, '-x'); case 'terminator':
break; case 'xfce4-terminal':
case 'guake': sshArgs.insert(0, '-x');
String command = sshArgs.join(' '); break;
sshArgs = ['-e', command]; case 'guake':
break; String command = sshArgs.join(' ');
} sshArgs = ['-e', command];
Process.start(_terminalEmulator!, sshArgs); break;
} }
}); Process.start(_terminalEmulator!, sshArgs);
}, }
});
},
), ),
] ])),
)
),
const Divider() const Divider()
]; ];
} }

View File

@ -21,7 +21,7 @@ class _VersionSelectionState extends State<VersionSelection> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( 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( body: SingleChildScrollView(
child: Column( child: Column(

View File

@ -23,8 +23,8 @@ class DownloadLabel extends StatelessWidget {
: data != null : data != null
? downloader != 'zsync' ? downloader != 'zsync'
? downloader == 'wget' ? downloader == 'wget'
? Text('${context.t('Downloading...')}${(data! * 100).toInt()}%') ? Text(context.t('Downloading...{0}%', args: [(data! * 100).toInt()]))
: Text('$data ${context.t('Mbs downloaded')}') : Text(context.t('{0} Mbs downloaded', args: [data!]))
: Text(context.t("Downloading (no progress available)...")) : Text(context.t("Downloading (no progress available)..."))
: Text(context.t('Waiting for download to start')), : Text(context.t('Waiting for download to start')),
); );

View File

@ -160,7 +160,7 @@ class _HomePageButtonGroupState extends State<HomePageButtonGroup> {
padding: const EdgeInsets.symmetric(vertical: 32), padding: const EdgeInsets.symmetric(vertical: 32),
child: Text(context.t('Done !'), style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white)), 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)), style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white)),
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 32), padding: const EdgeInsets.symmetric(vertical: 32),