Skip to content

Commit

Permalink
Merge pull request #7411 from xoriole/fix/language-support-script-rel…
Browse files Browse the repository at this point in the history
…ease

Fix/language support script release
  • Loading branch information
xoriole authored Jul 21, 2023
2 parents 3c61742 + b6b5a3b commit ff7639b
Show file tree
Hide file tree
Showing 13 changed files with 1,847 additions and 1,354 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.
538 changes: 311 additions & 227 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.
957 changes: 551 additions & 406 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.
703 changes: 389 additions & 314 deletions src/tribler/gui/i18n/ru_RU.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/tribler/gui/i18n/update_translations.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#sudo apt install qtchooser qt5-default qttools5-dev-tools
#sudo apt install qtchooser qttools5-dev-tools
lrelease *.ts
Binary file modified src/tribler/gui/i18n/zh_CN.qm
Binary file not shown.
953 changes: 554 additions & 399 deletions src/tribler/gui/i18n/zh_CN.ts

Large diffs are not rendered by default.

27 changes: 26 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,25 @@ 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_and_languages_content(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

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 ff7639b

Please sign in to comment.