flatpak: Get correct path to QtWebEngine locales
(cherry picked from commit 31e655dd36)
This commit is contained in:
parent
8546f48bb7
commit
bdf84abf75
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue