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)..."
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}"

View File

@ -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}"

View File

@ -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}"

View File

@ -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 ""

View File

@ -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<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: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<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: 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,
semanticLabel: active ? 'Running' : 'Run',
),
onPressed: active ? null : () async {
Map<String, VmInfo> activeVms = _activeVms;
List<String> 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<String, VmInfo> activeVms = _activeVms;
List<String> 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<bool>(
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: <Widget>[
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<bool>(
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: <Widget>[
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: <Widget>[
title: Text(connectInfo, style: const TextStyle(fontSize: 12)),
trailing: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
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<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('Launch SSH connection to $currentVm'),
content: TextField(
controller: _usernameController,
decoration: const InputDecoration(hintText: "SSH username"),
),
actions: <Widget>[
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<String> 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<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('Launch SSH connection to $currentVm'),
content: TextField(
controller: _usernameController,
decoration: const InputDecoration(hintText: "SSH username"),
),
actions: <Widget>[
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<String> 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()
];
}

View File

@ -21,7 +21,7 @@ class _VersionSelectionState extends State<VersionSelection> {
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(

View File

@ -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')),
);

View File

@ -160,7 +160,7 @@ class _HomePageButtonGroupState extends State<HomePageButtonGroup> {
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),