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:10:09 +0200 |
commit | 31e655dd36156eea9039cf210c0a0f67f5f3fc87 (patch) | |
tree | c1dc169256706cae6f8bd28eaca6f379075f392a | |
parent | 1a2934fda55d9ed46fb9d63305bf15e0dd0d54e2 (diff) | |
download | qutebrowser-31e655dd36156eea9039cf210c0a0f67f5f3fc87.tar.gz qutebrowser-31e655dd36156eea9039cf210c0a0f67f5f3fc87.zip |
flatpak: Get correct path to QtWebEngine locales
-rw-r--r-- | qutebrowser/config/qtargs.py | 14 | ||||
-rw-r--r-- | tests/unit/config/test_qtargs_locale_workaround.py | 17 |
2 files changed, 24 insertions, 7 deletions
diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py index d9564556a..cb17a0ced 100644 --- a/qutebrowser/config/qtargs.py +++ b/qutebrowser/config/qtargs.py @@ -192,6 +192,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 @@ -207,8 +218,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..cbb657902 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,16 @@ 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(fake_flatpak): + expected = pathlib.Path('/app/translations/qtwebengine_locales') + assert qtargs._webengine_locales_path() == expected |