Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/tagstudio/qt/controllers/edit_field_template_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# TODO: Use newer MVC style guidelines
class EditFieldTemplateModal(EditFieldTemplateModalView):
field_type_map: dict[str, str] = {
"TextFieldTemplate": Translations["field_type.text"],
"DatetimeFieldTemplate": Translations["field_type.datetime"],
"TextFieldTemplate": "field_type.text",
"DatetimeFieldTemplate": "field_type.datetime",
}
DEFAULT_TYPE_INDEX = 0

Expand All @@ -32,7 +32,7 @@ def __init__(self, field_template: BaseFieldTemplate | None = None) -> None:
self.old_field_type: str = ""

for k, v in EditFieldTemplateModal.field_type_map.items():
self._type_combobox.addItem(v, k)
self._type_combobox.addItem(Translations[v], k)

self.__connect_callbacks()
self.set_field_template(field_template)
Expand Down
13 changes: 7 additions & 6 deletions src/tagstudio/qt/controllers/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,13 @@ def rebuild_open_recent_library_menu(

# View Component
class MainWindow(QMainWindow):
# (translation key, size): the label is looked up when the combobox is filled.
THUMB_SIZES: list[tuple[str, int]] = [
(Translations["home.thumbnail_size.extra_large"], 256),
(Translations["home.thumbnail_size.large"], 192),
(Translations["home.thumbnail_size.medium"], 128),
(Translations["home.thumbnail_size.small"], 96),
(Translations["home.thumbnail_size.mini"], 76),
("home.thumbnail_size.extra_large", 256),
("home.thumbnail_size.large", 192),
("home.thumbnail_size.medium", 128),
("home.thumbnail_size.small", 96),
("home.thumbnail_size.mini", 76),
]

def __init__(self, driver: QtDriver, parent: QWidget | None = None) -> None:
Expand Down Expand Up @@ -650,7 +651,7 @@ def setup_extra_input_bar(self):
self.thumb_size_combobox.setMaximumWidth(352)
self.extra_input_layout.addWidget(self.thumb_size_combobox)
for size in MainWindow.THUMB_SIZES:
self.thumb_size_combobox.addItem(size[0], size[1])
self.thumb_size_combobox.addItem(Translations[size[0]], size[1])
self.thumb_size_combobox.setCurrentIndex(2) # Default: Medium

self.central_layout.addLayout(self.extra_input_layout, 5, 0, 1, 1)
Expand Down
42 changes: 23 additions & 19 deletions src/tagstudio/qt/mixed/settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,33 @@
class SettingsPanel(ModalContent):
driver: QtDriver

# Translation keys, looked up when the comboboxes are filled so the labels use the
# language chosen at startup rather than the one active when this module was imported.
filepath_option_map: dict[ShowFilepathOption, str] = {
ShowFilepathOption.SHOW_FULL_PATHS: Translations["settings.filepath.option.full"],
ShowFilepathOption.SHOW_RELATIVE_PATHS: Translations["settings.filepath.option.relative"],
ShowFilepathOption.SHOW_FILENAMES_ONLY: Translations["settings.filepath.option.name"],
ShowFilepathOption.SHOW_FULL_PATHS: "settings.filepath.option.full",
ShowFilepathOption.SHOW_RELATIVE_PATHS: "settings.filepath.option.relative",
ShowFilepathOption.SHOW_FILENAMES_ONLY: "settings.filepath.option.name",
}

theme_map: dict[Theme, str] = {
Theme.SYSTEM: Translations["settings.theme.system"],
Theme.DARK: Translations["settings.theme.dark"],
Theme.LIGHT: Translations["settings.theme.light"],
Theme.SYSTEM: "settings.theme.system",
Theme.DARK: "settings.theme.dark",
Theme.LIGHT: "settings.theme.light",
}

splash_map: dict[Splash, str] = {
Splash.DEFAULT: Translations["settings.splash.option.default"],
Splash.RANDOM: Translations["settings.splash.option.random"],
Splash.CLASSIC: Translations["settings.splash.option.classic"],
Splash.GOO_GEARS: Translations["settings.splash.option.goo_gears"],
Splash.NINETY_FIVE: Translations["settings.splash.option.ninety_five"],
Splash.AURORA: Translations["settings.splash.option.aurora"],
Splash.DEFAULT: "settings.splash.option.default",
Splash.RANDOM: "settings.splash.option.random",
Splash.CLASSIC: "settings.splash.option.classic",
Splash.GOO_GEARS: "settings.splash.option.goo_gears",
Splash.NINETY_FIVE: "settings.splash.option.ninety_five",
Splash.AURORA: "settings.splash.option.aurora",
}

tag_click_action_map: dict[TagClickActionOption, str] = {
TagClickActionOption.OPEN_EDIT: Translations["settings.tag_click_action.open_edit"],
TagClickActionOption.SET_SEARCH: Translations["settings.tag_click_action.set_search"],
TagClickActionOption.ADD_TO_SEARCH: Translations["settings.tag_click_action.add_to_search"],
TagClickActionOption.OPEN_EDIT: "settings.tag_click_action.open_edit",
TagClickActionOption.SET_SEARCH: "settings.tag_click_action.set_search",
TagClickActionOption.ADD_TO_SEARCH: "settings.tag_click_action.add_to_search",
}

date_format_map: dict[str, str] = {
Expand Down Expand Up @@ -194,7 +196,7 @@ def on_page_size_changed():
# Show Filepath
self.filepath_combobox = QComboBox()
for k in SettingsPanel.filepath_option_map:
self.filepath_combobox.addItem(SettingsPanel.filepath_option_map[k], k)
self.filepath_combobox.addItem(Translations[SettingsPanel.filepath_option_map[k]], k)
filepath_option: ShowFilepathOption = self.driver.settings.show_filepath
if filepath_option not in SettingsPanel.filepath_option_map:
filepath_option = ShowFilepathOption.DEFAULT
Expand All @@ -206,7 +208,9 @@ def on_page_size_changed():
# Tag Click Action
self.tag_click_action_combobox = QComboBox()
for k in SettingsPanel.tag_click_action_map:
self.tag_click_action_combobox.addItem(SettingsPanel.tag_click_action_map[k], k)
self.tag_click_action_combobox.addItem(
Translations[SettingsPanel.tag_click_action_map[k]], k
)
tag_click_action = self.driver.settings.tag_click_action
if tag_click_action not in SettingsPanel.tag_click_action_map:
tag_click_action = TagClickActionOption.DEFAULT
Expand Down Expand Up @@ -375,7 +379,7 @@ def __build_appearance_settings(self):
# Dark Mode
self.theme_combobox = QComboBox()
for k in SettingsPanel.theme_map:
self.theme_combobox.addItem(SettingsPanel.theme_map[k], k)
self.theme_combobox.addItem(Translations[SettingsPanel.theme_map[k]], k)
theme = self.driver.settings.theme
if theme not in SettingsPanel.theme_map:
theme = Theme.DEFAULT
Expand All @@ -386,7 +390,7 @@ def __build_appearance_settings(self):
# Splash Screen
self.splash_combobox = QComboBox()
for k in SettingsPanel.splash_map:
self.splash_combobox.addItem(SettingsPanel.splash_map[k], k)
self.splash_combobox.addItem(Translations[SettingsPanel.splash_map[k]], k)
splash = self.driver.settings.splash
if splash not in SettingsPanel.splash_map:
splash = Splash.DEFAULT
Expand Down
46 changes: 46 additions & 0 deletions tests/qt/test_translated_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-FileCopyrightText: (c) TagStudio Contributors
# SPDX-License-Identifier: MIT

# pyright: reportPrivateUsage=false

from collections.abc import Iterator

import pytest
from PySide6.QtWidgets import QComboBox
from pytestqt.qtbot import QtBot

from tagstudio.i18n.translations import DEFAULT_TRANSLATION, Translations
from tagstudio.qt.controllers.edit_field_template_modal import EditFieldTemplateModal
from tagstudio.qt.mixed.settings_panel import SettingsPanel
from tagstudio.qt.qt_driver import QtDriver


@pytest.fixture
def french() -> Iterator[None]:
# Like the app, switch language only after these modules have been imported.
Translations.change_language("fr")
yield
Translations.change_language(DEFAULT_TRANSLATION)


def items(combobox: QComboBox) -> list[str]:
return [combobox.itemText(i) for i in range(combobox.count())]


def test_settings_options_use_the_current_language(qtbot: QtBot, qt_driver: QtDriver, french: None):
# qt_driver applies the language from its settings, so request french after it.
panel = SettingsPanel(qt_driver)
qtbot.addWidget(panel)

assert "Sombre" in items(panel.theme_combobox)
assert "Aléatoire" in items(panel.splash_combobox)
assert "Afficher le Chemin Complet" in items(panel.filepath_combobox)
assert "Modifier le Tag" in items(panel.tag_click_action_combobox)


@pytest.mark.usefixtures("french")
def test_field_type_options_use_the_current_language(qtbot: QtBot):
modal = EditFieldTemplateModal()
qtbot.addWidget(modal)

assert "Texte" in items(modal._type_combobox)
Loading