From cf8b99c763cfdd337357aa3b523de5f3177cd9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 22 Jan 2017 04:43:13 +0100 Subject: [PATCH] i18n: add basic support for translations Handle translations of GUI elements defined in .ui files. See README.md for details. Fixes QubesOS/qubes-issues#2599 --- Makefile | 6 ++++++ README.md | 21 ++++++++++++++++++++ i18n/.gitignore | 1 + qubesmanager.pro | 47 ++++++++++++++++++++++++++++++++++++++++++++ qubesmanager/main.py | 8 ++++++++ rpm_spec/qmgr.spec | 6 +++++- 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 i18n/.gitignore create mode 100644 qubesmanager.pro diff --git a/Makefile b/Makefile index 3563e89..ecfd26f 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,12 @@ res: pyuic4 -o qubesmanager/ui_about.py about.ui pyuic4 -o qubesmanager/ui_releasenotes.py releasenotes.ui +translations: + lrelease-qt4 qubesmanager.pro + +update_ts: res + pylupdate4 qubesmanager.pro + update-repo-current: ln -f $(RPMS_DIR)/x86_64/qubes-manager-*$(VERSION)*.rpm ../yum/current-release/current/dom0/rpm/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..8071c89 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +Qubes Manager +============== + +Managing translations +---------------------- + +### Adding new language + +1. Add `i18n/qubesmanager_LANGUAGECODE.ts` (replace `LANGUAGECODE` with actual code, + for example `es`) to `qubesmanager.pro` - `TRANSLATIONS` setting. +2. Run `make res update_ts` + +### Regenerating translation source files (`.ts`) + + make res update_ts + +This will keep translated strings, but will add new ones. + +### Updating translations + +Commit updated `.ts` files into `i18n` directory. diff --git a/i18n/.gitignore b/i18n/.gitignore new file mode 100644 index 0000000..8df47d5 --- /dev/null +++ b/i18n/.gitignore @@ -0,0 +1 @@ +*.qm diff --git a/qubesmanager.pro b/qubesmanager.pro new file mode 100644 index 0000000..f0d826f --- /dev/null +++ b/qubesmanager.pro @@ -0,0 +1,47 @@ +SOURCES = \ + about.ui \ + backupdlg.ui \ + globalsettingsdlg.ui \ + logdlg.ui \ + mainwindow.ui \ + multiselectwidget.ui \ + newappvmdlg.ui \ + newfwruledlg.ui \ + releasenotes.ui \ + restoredlg.ui \ + settingsdlg.ui \ + qubesmanager/about.py \ + qubesmanager/appmenu_select.py \ + qubesmanager/backup.py \ + qubesmanager/backup_utils.py \ + qubesmanager/block.py \ + qubesmanager/clipboard.py \ + qubesmanager/create_new_vm.py \ + qubesmanager/firewall.py \ + qubesmanager/global_settings.py \ + qubesmanager/log_dialog.py \ + qubesmanager/main.py \ + qubesmanager/multiselectwidget.py \ + qubesmanager/releasenotes.py \ + qubesmanager/resources_rc.py \ + qubesmanager/restore.py \ + qubesmanager/settings.py \ + qubesmanager/table_widgets.py \ + qubesmanager/thread_monitor.py \ + qubesmanager/ui_about.py \ + qubesmanager/ui_backupdlg.py \ + qubesmanager/ui_globalsettingsdlg.py \ + qubesmanager/ui_logdlg.py \ + qubesmanager/ui_mainwindow.py \ + qubesmanager/ui_multiselectwidget.py \ + qubesmanager/ui_newappvmdlg.py \ + qubesmanager/ui_newfwruledlg.py \ + qubesmanager/ui_releasenotes.py \ + qubesmanager/ui_restoredlg.py \ + qubesmanager/ui_settingsdlg.py + +TRANSLATIONS = + + +CODECFORTR = UTF-8 +CODECFORSRC = UTF-8 diff --git a/qubesmanager/main.py b/qubesmanager/main.py index 007ae07..f44e2f8 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -2114,6 +2114,14 @@ def main(): app.setWindowIcon(QIcon.fromTheme("qubes-manager")) app.setAttribute(Qt.AA_DontShowIconsInMenus, False) + qt_translator = QTranslator() + locale = QLocale.system().name() + i18n_dir = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'i18n') + qt_translator.load("qubesmanager_{!s}.qm".format(locale), i18n_dir) + app.installTranslator(qt_translator) + sys.excepthook = handle_exception global session_bus diff --git a/rpm_spec/qmgr.spec b/rpm_spec/qmgr.spec index ae64117..4784464 100644 --- a/rpm_spec/qmgr.spec +++ b/rpm_spec/qmgr.spec @@ -24,7 +24,7 @@ AutoReq: 0 The Graphical Qubes VM Manager. %build -make res +make res translations python -m compileall qubesmanager python -O -m compileall qubesmanager @@ -68,6 +68,9 @@ cp qubesmanager/ui_logdlg.py{,c,o} $RPM_BUILD_ROOT%{python_sitearch}/qubesmanage cp qubesmanager/ui_about.py{,c,o} $RPM_BUILD_ROOT%{python_sitearch}/qubesmanager cp qubesmanager/ui_releasenotes.py{,c,o} $RPM_BUILD_ROOT%{python_sitearch}/qubesmanager +mkdir -p $RPM_BUILD_ROOT%{python_sitearch}/qubesmanager/i18n +cp i18n/qubesmanager_*.qm $RPM_BUILD_ROOT%{python_sitearch}/qubesmanager/i18n/ + mkdir -p $RPM_BUILD_ROOT/usr/share/applications cp qubes-manager.desktop $RPM_BUILD_ROOT/usr/share/applications mkdir -p $RPM_BUILD_ROOT/etc/xdg/autostart/ @@ -182,6 +185,7 @@ rm -rf $RPM_BUILD_ROOT %{python_sitearch}/qubesmanager/ui_releasenotes.py %{python_sitearch}/qubesmanager/ui_releasenotes.pyc %{python_sitearch}/qubesmanager/ui_releasenotes.pyo +%{python_sitearch}/qubesmanager/i18n/qubesmanager_*.qm /usr/share/applications/qubes-manager.desktop