diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-30 15:51:09 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-03-31 13:29:54 +0200 |
commit | bdf84abf75362f96d38b8441e2c0a41a1cf54472 (patch) | |
tree | 266970cd11b70efb8a704d23c1a9390539a92fed | |
parent | 8546f48bb7291b1de621e9356ab8e399663258e2 (diff) | |
download | qutebrowser-bdf84abf75362f96d38b8441e2c0a41a1cf54472.tar.gz qutebrowser-bdf84abf75362f96d38b8441e2c0a41a1cf54472.zip |
flatpak: Get correct path to QtWebEngine locales
(cherry picked from commit 31e655dd36156eea9039cf210c0a0f67f5f3fc87)
-rw-r--r-- | qutebrowser/config/qtargs.py | 14 | ||||
-rw-r--r-- | tests/unit/config/test_qtargs_locale_workaround.py | 18 |
2 files changed, 25 insertions, 7 deletions
diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py index 407ccb37e..6fec6b49c 100644 --- a/qutebrowser/config/qtargs.py +++ b/qutebrowser/config/qtargs.py @@ -189,6 +189,17 @@ def _get_pak_name(locale_name: str) -> str: return locale_name.split('-')[0] +def _webengine_locales_path() -> pathlib.Path: + """Get the path of the QtWebEngine locales.""" + if version.is_flatpak(): + # TranslationsPath is /usr/translations on Flatpak, i.e. the path for qtbase, + # not QtWebEngine. + base = pathlib.Path('/app/translations') + else: + base = pathlib.Path(QLibraryInfo.location(QLibraryInfo.TranslationsPath)) + return base / 'qtwebengine_locales' + + def _get_lang_override( webengine_version: utils.VersionNumber, locale_name: str @@ -204,8 +215,7 @@ def _get_lang_override( if webengine_version != utils.VersionNumber(5, 15, 3) or not utils.is_linux: return None - locales_path = pathlib.Path( - QLibraryInfo.location(QLibraryInfo.TranslationsPath)) / 'qtwebengine_locales' + locales_path = _webengine_locales_path() if not locales_path.exists(): log.init.debug(f"{locales_path} not found, skipping workaround!") return None diff --git a/tests/unit/config/test_qtargs_locale_workaround.py b/tests/unit/config/test_qtargs_locale_workaround.py index 7e313377b..6a8f2b8e1 100644 --- a/tests/unit/config/test_qtargs_locale_workaround.py +++ b/tests/unit/config/test_qtargs_locale_workaround.py @@ -20,7 +20,7 @@ import os import pathlib import pytest -from PyQt5.QtCore import QLocale, QLibraryInfo +from PyQt5.QtCore import QLocale from qutebrowser.utils import utils from qutebrowser.config import qtargs @@ -414,10 +414,9 @@ def test_lang_workaround_all_locales(lang, expected, qtwe_version): locale_name=locale_name, ) - locales_path = pathlib.Path( - QLibraryInfo.location(QLibraryInfo.TranslationsPath)) / 'qtwebengine_locales' - + locales_path = qtargs._webengine_locales_path() original_path = qtargs._get_locale_pak_path(locales_path, locale_name) + if override is None: assert original_path.exists() else: @@ -450,8 +449,17 @@ def test_disabled(qtwe_version, config_stub): @pytest.mark.fake_os('linux') def test_no_locales_available(qtwe_version, monkeypatch, caplog): - monkeypatch.setattr(qtargs.QLibraryInfo, 'location', lambda _path: '/doesnotexist') + path = pathlib.Path('/doesnotexist/qtwebengine_locales') + assert not path.exists() + monkeypatch.setattr(qtargs, '_webengine_locales_path', lambda: path) + assert qtargs._get_lang_override(qtwe_version, "de-CH") is None assert caplog.messages == [ f"{os.sep}doesnotexist{os.sep}qtwebengine_locales not found, skipping " "workaround!"] + + +def test_flatpak_locales_path(monkeypatch): + monkeypatch.setenv('FLATPAK_ID', 'org.qutebrowser.qutebrowser') + expected = pathlib.Path('/app/translations/qtwebengine_locales') + assert qtargs._webengine_locales_path() == expected |