Skip to content
Merged
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
7 changes: 6 additions & 1 deletion dependencies/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ qasync==0.27.1
tqdm==2.2.3
tzdata
zstd==1.5.7.3
countryflag==1.1.1
pycountry==26.2.16
cutlet
unidic-lite
pypinyin
koroman==1.0.14
arabic_buckwalter_transliteration
10 changes: 5 additions & 5 deletions src/Helpers/TSHCountryHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from .TSHLocaleHelper import TSHLocaleHelper
import orjson
from loguru import logger
import countryflag
from countryflag.core.exceptions import InvalidCountryError
import pycountry


class TSHCountryHelperSignals(QObject):
Expand Down Expand Up @@ -92,9 +91,10 @@ def GetBasicCountryInfo(country_code):
}

try:
data["emoji"] = countryflag.getflag(TSHCountryHelper.countries[country_code]["code"])
except InvalidCountryError:
# logger.warning(f'The following country could not be found in the countryflag library: {TSHCountryHelper.countries[country_code]["code"]}')
country = pycountry.countries.get(alpha_2=TSHCountryHelper.countries[country_code]["code"])
data["emoji"] = country.flag
except AttributeError:
logger.warning(f'The following country could not be found in the pycountry library: {TSHCountryHelper.countries[country_code]["code"]}')
data["emoji"] = None

return data
Expand Down
27 changes: 25 additions & 2 deletions src/Helpers/TSHLocaleHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
from .TSHDictHelper import deep_clone
from .TSHDirHelper import TSHResolve

# Import romanizers
import cutlet
from pypinyin import pinyin
import koroman
from arabic_buckwalter_transliteration.transliteration import arabic_to_buckwalter


class TSHLocaleHelperSignals(QObject):
localeChanged = Signal()
Expand Down Expand Up @@ -106,6 +112,24 @@ def GetCountrySpokenLanguages(countryCode2: str):
def GetCountryContinent(countryCode2: str):
return TSHLocaleHelper.countryToContinent.get(countryCode2.upper(), "")

def RomanizeTextFromCountry(text, countryCode2: str):
romanized_text = text
if romanized_text:
languages = TSHLocaleHelper.GetCountrySpokenLanguages(countryCode2)
if "ja" in languages:
katsu = cutlet.Cutlet()
romanized_text = katsu.romaji(text)
elif "zh" in languages:
pinyin_text = pinyin(text)
romanized_text = ""
for pinyin_character in pinyin_text:
romanized_text = romanized_text + pinyin_character[0]
elif "ko" in languages:
romanized_text = koroman.romanize(text)
elif "ar" in languages:
romanized_text = arabic_to_buckwalter(text)
return(romanized_text)

def LoadRoundNames():
# Load default round names and translation
try:
Expand Down Expand Up @@ -210,7 +234,6 @@ def LoadMatchNamesToWidget(widget):
except:
logger.error(
f"Unable to generate match strings for {matchString}")



TSHLocaleHelper.LoadLanguages()
TSHLocaleHelper.LoadCountryToLanguage()
18 changes: 18 additions & 0 deletions src/TSHScoreboardPlayerWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import threading
from .Helpers.TSHBadWordFilter import TSHBadWordFilter
from .Helpers.TSHCustomPlayerCompleter import TSHCustomPlayerCompleter
from .Helpers.TSHLocaleHelper import TSHLocaleHelper
from loguru import logger


Expand Down Expand Up @@ -270,6 +271,8 @@ def NameChanged(self):

self.lastExportedName = merged

self.SetRomanizedText()

def ExportMergedName(self):
with self.dataLock:
team = self.findChild(QLineEdit, "team").text()
Expand Down Expand Up @@ -632,6 +635,7 @@ def LoadCountries(self):
country.lineEdit().setFont(QFont(country.font().family(), 9))

country.currentIndexChanged.connect(self.LoadStates)
country.currentIndexChanged.connect(self.SetRomanizedText)

state: QComboBox = self.findChild(QComboBox, "state")
state.completer().setFilterMode(Qt.MatchFlag.MatchContains)
Expand Down Expand Up @@ -1037,3 +1041,17 @@ def Clear(self, no_mains=False):
else:
c.setCurrentIndex(0)
StateManager.ReleaseSaving()

def SetRomanizedText(self):
name = self.findChild(QWidget, "name").text()
team = self.findChild(QWidget, "team").text()
romanized_data = {"name": name, "team": team}
country = self.findChild(QComboBox, "country")
if country.currentData(Qt.ItemDataRole.UserRole) != None:
country_code = country.currentData(Qt.ItemDataRole.UserRole).get("code")
if country_code:
romanized_data = {
"name": TSHLocaleHelper.RomanizeTextFromCountry(name, country_code),
"team": TSHLocaleHelper.RomanizeTextFromCountry(team, country_code)
}
StateManager.Set(f"{self.path}.romanized_data", romanized_data)