Skip to content

Commit

Permalink
fix: localization
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 7, 2024
1 parent 7b7be44 commit a54e287
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 36 deletions.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/az/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "",
"or": "ya"
}
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/ca/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "i",
"or": "o"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/cs/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "a",
"or": "nebo"
}
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/da/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "og",
"or": "eller"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/de/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "und",
"or": "oder"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/en/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "and",
"or": "or"
}
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/fa/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "و",
"or": "یا"
}
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/pl/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "oraz",
"or": "lub"
}
File renamed without changes.
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/sl/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "in",
"or": "ali"
}
4 changes: 4 additions & 0 deletions ovos_workshop/res/text/uk/word_connectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"and": "та",
"or": "або"
}
13 changes: 7 additions & 6 deletions ovos_workshop/skills/common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def __init__(self, *args, **kwargs):
}
super().__init__(*args, **kwargs)

noise_words_filepath = f"text/{self.lang}/noise_words.list"
default_res = f"{dirname(dirname(__file__))}/res/text/{self.lang}" \
lang = self.lang.split("-")[0]
noise_words_filepath = f"text/{lang}/noise_words.list"
default_res = f"{dirname(dirname(__file__))}/res/text/{lang}" \
f"/noise_words.list"
noise_words_filename = \
resolve_resource_file(noise_words_filepath,
Expand All @@ -79,7 +80,7 @@ def __init__(self, *args, **kwargs):
if noise_words_filename:
with open(noise_words_filename) as f:
translated_noise_words = f.read().strip()
self._translated_noise_words[self.lang] = \
self._translated_noise_words[lang] = \
translated_noise_words.split()

@property
Expand All @@ -89,13 +90,13 @@ def translated_noise_words(self) -> List[str]:
"""
log_deprecation("self.translated_noise_words will become a "
"private variable", "0.1.0")
return self._translated_noise_words.get(self.lang, [])
return self._translated_noise_words.get(self.lang.split("-")[0], [])

@translated_noise_words.setter
def translated_noise_words(self, val: List[str]):
log_deprecation("self.translated_noise_words will become a "
"private variable", "0.1.0")
self._translated_noise_words[self.lang] = val
self._translated_noise_words[self.lang.split("-")[0]] = val

def bind(self, bus):
"""Overrides the default bind method of MycroftSkill.
Expand Down Expand Up @@ -179,7 +180,7 @@ def remove_noise(self, phrase: str, lang: str = None) -> str:
@param lang: language of `phrase`, else defaults to `self.lang`
@return: cleaned `phrase` with extra words removed
"""
lang = lang or self.lang
lang = (lang or self.lang).split("-")[0]
phrase = ' ' + phrase + ' '
for word in self._translated_noise_words.get(lang, []):
mtch = ' ' + word + ' '
Expand Down
47 changes: 17 additions & 30 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import json
import os
import re
import sys
Expand Down Expand Up @@ -2515,21 +2516,14 @@ def _get_and_word(lang):
Returns:
str: translated version of resource name
"""
# TODO - localization
mapp = {
"az": "və",
"ca": "i",
"cs": "a",
"da": "og",
"de": "und",
"en": "and",
"fa": "و",
"pl": "oraz",
"pt": "e",
"sl": "in",
"uk": "та"
}
return mapp.get(lang.split("-")[0]) or ", "
res_file = f"{dirname(dirname(__file__))}/res/text/{lang}" \
f"/word_connectors.json"
if not os.path.isfile(res_file):
LOG.warning(f"untranslated file: {res_file}")
return ", "
with open(res_file) as f:
w = json.load(f)["and"]
return w

def _get_or_word(lang):
""" Helper to get word translations
Expand All @@ -2541,21 +2535,14 @@ def _get_or_word(lang):
Returns:
str: translated version of resource name
"""
# TODO - localization
mapp = {
"az": "ya",
"ca": "o",
"cs": "nebo",
"da": "eller",
"de": "oder",
"fa": "یا",
"pl": "lub",
"en": "or",
"sl": "ali",
"uk": "або",
"pt": "ou"
}
return mapp.get(lang.split("-")[0]) or ", "
res_file = f"{dirname(dirname(__file__))}/res/text/{lang}" \
f"/word_connectors.json"
if not os.path.isfile(res_file):
LOG.warning(f"untranslated file: {res_file}")
return ", "
with open(res_file) as f:
w = json.load(f)["or"]
return w


def join_word_list(items: List[str], connector: str, sep: str, lang:str) -> str:
Expand Down

0 comments on commit a54e287

Please sign in to comment.