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
This commit is contained in:
Marek Marczykowski-Górecki 2017-01-22 04:43:13 +01:00
parent cbd8afd2c3
commit cf8b99c763
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
6 changed files with 88 additions and 1 deletions

View File

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

21
README.md Normal file
View File

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

1
i18n/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.qm

47
qubesmanager.pro Normal file
View File

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

View File

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

View File

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