Skip to content

Commit

Permalink
Update language support scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Jul 18, 2023
1 parent 3c61742 commit 55c2661
Show file tree
Hide file tree
Showing 12 changed files with 1,830 additions and 1,328 deletions.
8 changes: 2 additions & 6 deletions src/tribler/gui/dialogs/editmetadatadialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Dict, List

from PyQt5 import uic
Expand All @@ -7,11 +6,10 @@

from tribler.core.components.knowledge.db.knowledge_db import ResourceType
from tribler.core.components.knowledge.knowledge_constants import MAX_RESOURCE_LENGTH, MIN_RESOURCE_LENGTH
from tribler.core.utilities.path_util import Path
from tribler.gui.defs import TAG_HORIZONTAL_MARGIN
from tribler.gui.dialogs.dialogcontainer import DialogContainer
from tribler.gui.network.request_manager import request_manager
from tribler.gui.utilities import connect, get_objects_with_predicate, get_ui_file_path, tr
from tribler.gui.utilities import connect, get_languages_file_content, get_objects_with_predicate, get_ui_file_path, tr
from tribler.gui.widgets.tagbutton import TagButton

METADATA_TABLE_PREDICATES = [
Expand Down Expand Up @@ -51,9 +49,7 @@ def __init__(self, parent: QWidget, index: QModelIndex) -> None:
connect(self.dialog_widget.edit_metadata_table.doubleClicked, self.on_edit_metadata_table_item_clicked)

# Load the languages
languages_path = get_ui_file_path("languages.json")
content = Path(languages_path).read_text(encoding='utf-8')
self.languages = json.loads(content)
self.languages = get_languages_file_content()

# Fill in the metadata table and make the items in the 2nd column editable
for ind in range(self.dialog_widget.edit_metadata_table.topLevelItemCount()):
Expand Down
Binary file modified src/tribler/gui/i18n/es_ES.qm
Binary file not shown.
518 changes: 301 additions & 217 deletions src/tribler/gui/i18n/es_ES.ts

Large diffs are not rendered by default.

File renamed without changes.
Binary file modified src/tribler/gui/i18n/pt_BR.qm
Binary file not shown.
952 changes: 551 additions & 401 deletions src/tribler/gui/i18n/pt_BR.ts

Large diffs are not rendered by default.

Binary file modified src/tribler/gui/i18n/ru_RU.qm
Binary file not shown.
687 changes: 381 additions & 306 deletions src/tribler/gui/i18n/ru_RU.ts

Large diffs are not rendered by default.

Binary file modified src/tribler/gui/i18n/zh_CN.qm
Binary file not shown.
949 changes: 552 additions & 397 deletions src/tribler/gui/i18n/zh_CN.ts

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion src/tribler/gui/tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
from pathlib import Path
from unittest.mock import MagicMock, Mock, patch
from urllib.parse import unquote_plus

Expand All @@ -6,7 +8,8 @@
from tribler.gui.utilities import TranslatedString, compose_magnetlink, create_api_key, dict_item_is_any_of, \
duration_to_string, \
format_api_key, \
quote_plus_unicode, set_api_key, unicode_quoter
quote_plus_unicode, set_api_key, unicode_quoter, get_i18n_file_path, I18N_DIR, LANGUAGES_FILE, \
get_languages_file_content


def test_quoter_char():
Expand Down Expand Up @@ -215,3 +218,29 @@ def test_missed_key_in_both_translated_and_original_strings(warning: Mock):

warning.assert_called_once_with('KeyError: No value provided for \'key2\' in translation "translated %(key2)s", '
'original string: "original %(key1)s"')


@patch("tribler.gui.utilities.get_base_path")
def test_i18n_file_path(mock_get_base_path, tmp_path):
mock_get_base_path.return_value = tmp_path

filename = "languages.json"
expected_path = Path(tmp_path) / I18N_DIR / filename

assert get_i18n_file_path(filename) == expected_path


@patch("tribler.gui.utilities.get_base_path")
def test_get_languages_file_content(mock_get_base_path, tmp_path):
mock_get_base_path.return_value = tmp_path

languages_json = {
"unknown": "Unknown",
"en": "English",
"nl": "Dutch"
}
language_path = get_i18n_file_path(LANGUAGES_FILE)
language_path.parents[0].mkdir(parents=True, exist_ok=True)
language_path.write_text(json.dumps(languages_json))

assert languages_json == get_languages_file_content()
13 changes: 13 additions & 0 deletions src/tribler/gui/utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import inspect
import json
import logging
import math
import os
Expand Down Expand Up @@ -34,6 +35,8 @@
logger = logging.getLogger(__name__)

NUM_VOTES_BARS = 8
I18N_DIR = "i18n"
LANGUAGES_FILE = "languages.json"


class TranslatedString(str):
Expand Down Expand Up @@ -223,6 +226,16 @@ def get_ui_file_path(filename):
return os.path.join(get_base_path(), 'qt_resources', filename)


def get_i18n_file_path(filename):
return Path(get_base_path()) / I18N_DIR / filename


def get_languages_file_content():
languages_path = get_i18n_file_path(LANGUAGES_FILE)
content = Path(languages_path).read_text(encoding='utf-8')
return json.loads(content)


def get_image_path(filename: str, convert_slashes_to_forward: bool = False) -> str:
"""
Return a path to a particular file in the image directory.
Expand Down

0 comments on commit 55c2661

Please sign in to comment.