[162] fix key_name translations

pull/1361/head
meisnate12 2 years ago
parent 98f535c20e
commit fcccd02067

@ -1 +1 @@
1.18.3-develop161 1.18.3-develop162

@ -41,13 +41,13 @@ scheduled_boolean = ["visible_library", "visible_home", "visible_shared"]
string_details = ["sort_title", "content_rating", "name_mapping"] string_details = ["sort_title", "content_rating", "name_mapping"]
ignored_details = [ ignored_details = [
"smart_filter", "smart_label", "smart_url", "run_again", "schedule", "sync_mode", "template", "variables", "test", "suppress_overlays", "smart_filter", "smart_label", "smart_url", "run_again", "schedule", "sync_mode", "template", "variables", "test", "suppress_overlays",
"delete_not_scheduled", "tmdb_person", "build_collection", "collection_order", "builder_level", "overlay", "delete_not_scheduled", "tmdb_person", "build_collection", "collection_order", "builder_level", "overlay", "pmm_poster",
"validate_builders", "libraries", "sync_to_users", "exclude_users", "collection_name", "playlist_name", "name", "validate_builders", "libraries", "sync_to_users", "exclude_users", "collection_name", "playlist_name", "name", "limit",
"blank_collection", "allowed_library_types", "run_definition", "delete_playlist", "ignore_blank_results", "only_run_on_create", "blank_collection", "allowed_library_types", "run_definition", "delete_playlist", "ignore_blank_results", "only_run_on_create",
"delete_collections_named", "tmdb_person_offset", "append_label", "key_name", "translation_key", "translation_prefix" "delete_collections_named", "tmdb_person_offset", "append_label", "key_name", "translation_key", "translation_prefix"
] ]
details = [ details = [
"ignore_ids", "ignore_imdb_ids", "server_preroll", "changes_webhooks", "collection_filtering", "collection_mode", "limit", "url_theme", "ignore_ids", "ignore_imdb_ids", "server_preroll", "changes_webhooks", "collection_filtering", "collection_mode", "url_theme",
"file_theme", "minimum_items", "label", "album_sorting", "cache_builders", "tmdb_region", "default_percent" "file_theme", "minimum_items", "label", "album_sorting", "cache_builders", "tmdb_region", "default_percent"
] + boolean_details + scheduled_boolean + string_details ] + boolean_details + scheduled_boolean + string_details
collectionless_details = ["collection_order", "plex_collectionless", "label", "label_sync_mode", "test", "item_label"] + \ collectionless_details = ["collection_order", "plex_collectionless", "label", "label_sync_mode", "test", "item_label"] + \
@ -249,10 +249,56 @@ class CollectionBuilder:
self.builder_language = str(self.data[methods["language"]]).lower() self.builder_language = str(self.data[methods["language"]]).lower()
self.name = None self.name = None
if "translation_key" in methods: if "name" in methods:
logger.debug("")
logger.debug("Validating Method: name")
if not self.data[methods["name"]]:
raise Failed(f"{self.Type} Error: name attribute is blank")
logger.debug(f"Value: {self.data[methods['name']]}")
self.name = str(self.data[methods["name"]])
english = None
translations = None
self.limit = 0
if "limit" in methods:
logger.debug("")
logger.debug("Validating Method: limit")
if not self.data[methods["limit"]]:
raise Failed(f"{self.Type} Error: limit attribute is blank")
self.limit = util.parse(self.Type, "limit", self.data[methods["limit"]], datatype="int", minimum=1)
en_key = None
trans_key = None
if "key_name" in methods:
english = self.config.GitHub.translation_yaml("en") english = self.config.GitHub.translation_yaml("en")
translations = self.config.GitHub.translation_yaml(self.builder_language) translations = self.config.GitHub.translation_yaml(self.builder_language)
logger.debug("") logger.debug("")
logger.debug("Validating Method: key_name")
if not self.data[methods["key_name"]]:
raise Failed(f"{self.Type} Error: key_name attribute is blank")
en_key = str(self.data[methods["key_name"]])
trans_key = en_key
if self.builder_language != "en":
key_name_key = None
for k, v in english["key_names"].items():
if en_key == v:
key_name_key = k
break
if key_name_key and key_name_key in translations["key_names"]:
trans_key = translations["key_names"][key_name_key]
logger.debug(f"Value: {trans_key}")
en_name = None
en_summary = None
trans_name = None
trans_summary = None
if "translation_key" in methods:
if not english:
english = self.config.GitHub.translation_yaml("en")
if not translations:
translations = self.config.GitHub.translation_yaml(self.builder_language)
logger.debug("")
logger.debug("Validating Method: translation_key") logger.debug("Validating Method: translation_key")
if not self.data[methods["translation_key"]]: if not self.data[methods["translation_key"]]:
raise Failed(f"{self.Type} Error: translation_key attribute is blank") raise Failed(f"{self.Type} Error: translation_key attribute is blank")
@ -261,83 +307,85 @@ class CollectionBuilder:
if translation_key not in english["collections"]: if translation_key not in english["collections"]:
raise Failed(f"{self.Type} Error: translation_key: {translation_key} is invalid") raise Failed(f"{self.Type} Error: translation_key: {translation_key} is invalid")
key_name = "" en_name = english["collections"][translation_key]["name"]
if "key_name" in methods: en_summary = english["collections"][translation_key]["summary"]
if translation_key in translations["collections"]:
if "name" in translations["collections"][translation_key]:
trans_name = translations["collections"][translation_key]["name"]
if "summary" in translations["collections"][translation_key]:
trans_summary = translations["collections"][translation_key]["summary"]
if "translation_prefix" in methods:
logger.debug("") logger.debug("")
logger.debug("Validating Method: key_name") logger.debug("Validating Method: translation_prefix")
if not self.data[methods["key_name"]]: if not self.data[methods["translation_prefix"]]:
raise Failed(f"{self.Type} Error: key_name attribute is blank") raise Failed(f"{self.Type} Error: translation_prefix attribute is blank")
logger.debug(f"Value: {self.data[methods['key_name']]}") logger.debug(f"Value: {self.data[methods['translation_prefix']]}")
key_name = str(self.data[methods["key_name"]]) en_name = f"{self.data[methods['translation_prefix']]}{en_name}"
if self.builder_language != "en": trans_name = f"{self.data[methods['translation_prefix']]}{trans_name}"
key_name_key = None
for k, v in english["key_names"]: if self.name or en_name or trans_name:
if key_name == v: if not english:
key_name_key = k english = self.config.GitHub.translation_yaml("en")
break if not translations:
if key_name_key and key_name_key in translations["key_names"]: translations = self.config.GitHub.translation_yaml(self.builder_language)
key_name = translations["key_names"][key_name_key]
t_limit = self.data[methods["limit"]] if "limit" in methods and self.data[methods["limit"]] else 0
lib_type = self.library.type.lower() if self.library else "item" lib_type = self.library.type.lower() if self.library else "item"
en_vars = {k: v[lib_type] for k, v in english["variables"].items() if lib_type in v and v[lib_type]} en_vars = {k: v[lib_type] for k, v in english["variables"].items() if lib_type in v and v[lib_type]}
t_vars = {k: v[lib_type] for k, v in translations["variables"].items() if lib_type in v and v[lib_type]} trans_vars = {k: v[lib_type] for k, v in translations["variables"].items() if lib_type in v and v[lib_type]}
for k, v in en_vars.items(): for k, v in en_vars.items():
if k not in t_vars: if k not in trans_vars:
t_vars[k] = v trans_vars[k] = v
def apply_vars(input_str, var_set): def apply_vars(input_str, var_set, var_key, var_limit):
input_str = str(input_str) input_str = str(input_str)
if "<<library_type>>" in input_str:
input_str = input_str.replace("<<library_type>>", "<<library_translation>>")
if "<<library_typeU>>" in input_str:
input_str = input_str.replace("<<library_typeU>>", "<<library_translationU>>")
for ik, iv in var_set.items(): for ik, iv in var_set.items():
if f"<<{ik}>>" in input_str: if f"<<{ik}>>" in input_str:
input_str = input_str.replace(f"<<{ik}>>", str(iv)) input_str = input_str.replace(f"<<{ik}>>", str(iv))
if f"<<{ik}U>>" in input_str: if f"<<{ik}U>>" in input_str:
input_str = input_str.replace(f"<<{ik}U>>", str(iv).capitalize()) input_str = input_str.replace(f"<<{ik}U>>", str(iv).capitalize())
if "<<key_name>>" in input_str: if var_key and "<<key_name>>" in input_str:
input_str = input_str.replace("<<key_name>>", str(key_name)) input_str = input_str.replace("<<key_name>>", str(var_key))
if "<<limit>>" in input_str: if var_limit and "<<limit>>" in input_str:
input_str = input_str.replace("<<limit>>", str(t_limit)) input_str = input_str.replace("<<limit>>", str(var_limit))
return input_str return input_str
self.name = None if self.name:
summary = None self.name = apply_vars(self.name, trans_vars, trans_key, self.limit)
english_name = apply_vars(english["collections"][translation_key]["name"], en_vars) if en_name:
self.name = english_name en_name = apply_vars(en_name, en_vars, en_key, self.limit)
if translation_key in translations["collections"]: if trans_name:
logger.info(translations["collections"][translation_key]) trans_name = apply_vars(trans_name, trans_vars, trans_key, self.limit)
if "name" in translations["collections"][translation_key]: if en_summary:
self.name = apply_vars(translations["collections"][translation_key]["name"], t_vars) en_summary = apply_vars(en_summary, en_vars, en_key, self.limit)
if "summary" in translations["collections"][translation_key]: if trans_summary:
summary = apply_vars(translations["collections"][translation_key]["summary"], t_vars) trans_summary = apply_vars(trans_summary, trans_vars, trans_key, self.limit)
if not summary:
summary = apply_vars(english["collections"][translation_key]["summary"], en_vars) delete_cols = []
if summary: if (self.name and self.name != en_name) or (not self.name and en_name != trans_name):
self.summaries["translation"] = summary delete_cols.append(en_name)
if "translation_prefix" in methods: if self.name and self.name != trans_name:
logger.debug("") delete_cols.append(trans_name)
logger.debug("Validating Method: translation_prefix")
if not self.data[methods["translation_prefix"]]: if delete_cols:
raise Failed(f"{self.Type} Error: translation_prefix attribute is blank")
logger.debug(f"Value: {self.data[methods['translation_prefix']]}")
self.name = f"{self.data[methods['translation_prefix']]}{self.name}"
english_name = f"{self.data[methods['translation_prefix']]}{english_name}"
if self.name != english_name:
if "delete_collections_named" not in methods: if "delete_collections_named" not in methods:
self.data["delete_collections_named"] = english_name self.data["delete_collections_named"] = delete_cols
methods["delete_collections_named"] = "delete_collections_named" methods["delete_collections_named"] = "delete_collections_named"
if not isinstance(self.data[methods["delete_collections_named"]], list): elif not self.data[methods["delete_collections_named"]]:
self.data[methods["delete_collections_named"]] = [self.data[methods["delete_collections_named"]]] self.data[methods["delete_collections_named"]] = delete_cols
if english_name not in self.data[methods["delete_collections_named"]]: elif not isinstance(self.data[methods["delete_collections_named"]], list):
self.data[methods["delete_collections_named"]].append(english_name) delete_cols.append(self.data[methods["delete_collections_named"]])
self.data[methods["delete_collections_named"]] = delete_cols
else:
self.data[methods["delete_collections_named"]].extend(delete_cols)
if "name" in methods: if not self.name:
logger.debug("") self.name = trans_name if trans_name else en_name
logger.debug("Validating Method: name") logger.info(self.name)
if not self.data[methods["name"]]: if en_summary or trans_summary:
raise Failed(f"{self.Type} Error: name attribute is blank") self.summaries["translation"] = trans_summary if trans_summary else en_summary
logger.debug(f"Value: {self.data[methods['name']]}")
self.name = str(self.data[methods["name"]])
if not self.name: if not self.name:
self.name = self.mapping_name self.name = self.mapping_name
@ -533,7 +581,6 @@ class CollectionBuilder:
self.posters = {} self.posters = {}
self.backgrounds = {} self.backgrounds = {}
self.schedule = "" self.schedule = ""
self.limit = 0
self.beginning_count = 0 self.beginning_count = 0
self.default_percent = 50 self.default_percent = 50
self.minimum = self.library.minimum_items self.minimum = self.library.minimum_items
@ -1100,8 +1147,6 @@ class CollectionBuilder:
logger.error(f"Config Error: {method_data} collection_filtering invalid\n\tadmin (Always the server admin user)\n\tuser (User currently viewing the content)") logger.error(f"Config Error: {method_data} collection_filtering invalid\n\tadmin (Always the server admin user)\n\tuser (User currently viewing the content)")
elif method_name == "minimum_items": elif method_name == "minimum_items":
self.minimum = util.parse(self.Type, method_name, method_data, datatype="int", minimum=1) self.minimum = util.parse(self.Type, method_name, method_data, datatype="int", minimum=1)
elif method_name == "limit":
self.limit = util.parse(self.Type, method_name, method_data, datatype="int", minimum=1)
elif method_name == "cache_builders": elif method_name == "cache_builders":
self.details[method_name] = util.parse(self.Type, method_name, method_data, datatype="int", minimum=0) self.details[method_name] = util.parse(self.Type, method_name, method_data, datatype="int", minimum=0)
elif method_name == "default_percent": elif method_name == "default_percent":
@ -2853,12 +2898,13 @@ class CollectionBuilder:
title = self.name title = self.name
for op in ["The ", "A ", "An "]: for op in ["The ", "A ", "An "]:
if title.startswith(f"{op} "): if title.startswith(f"{op} "):
title = f"{new_sort_title[len(op):].strip()}, {op.strip()}" title = f"{title[len(op):].strip()}, {op.strip()}"
break break
new_sort_title.replace("<<title>>", title) new_sort_title = new_sort_title.replace("<<title>>", title)
logger.info(new_sort_title)
if new_sort_title != str(self.obj.titleSort): if new_sort_title != str(self.obj.titleSort):
self.obj.editSortTitle(self.details["sort_title"]) self.obj.editSortTitle(new_sort_title)
batch_display += f"\nSort Title | {self.details['sort_title']}" batch_display += f"\nSort Title | {new_sort_title}"
if "content_rating" in self.details and str(self.details["content_rating"]) != str(self.obj.contentRating): if "content_rating" in self.details and str(self.details["content_rating"]) != str(self.obj.contentRating):
self.obj.editContentRating(self.details["content_rating"]) self.obj.editContentRating(self.details["content_rating"])

@ -84,7 +84,7 @@ class GitHub:
if translation_key not in self._translations: if translation_key not in self._translations:
url = f"{self.translation_url}{translation_key}.yml" url = f"{self.translation_url}{translation_key}.yml"
yaml = util.YAML(input_data=self.config.get(url).content).data yaml = util.YAML(input_data=self.config.get(url).content).data
output = {"collections": {}, "key_name": {}, "variables": {}} output = {"collections": {}, "key_names": {}, "variables": {}}
for k in output: for k in output:
if k in yaml: if k in yaml:
output[k] = yaml[k] output[k] = yaml[k]

@ -251,10 +251,11 @@ class DataFile:
return_item = input_item return_item = input_item
for search_dict in search_dicts: for search_dict in search_dicts:
for rk, rv in search_dict.items(): for rk, rv in search_dict.items():
if f"<<{rk}>>" == str(return_item): if rk not in ["name_format", "summary_format"]:
return_item = rv if f"<<{rk}>>" == str(return_item):
if f"<<{rk}>>" in str(return_item): return_item = rv
return_item = str(return_item).replace(f"<<{rk}>>", str(rv)) if f"<<{rk}>>" in str(return_item):
return_item = str(return_item).replace(f"<<{rk}>>", str(rv))
return return_item return return_item
conditionals = {} conditionals = {}
@ -504,10 +505,15 @@ class DataFile:
for variable, variable_data in variables.items(): for variable, variable_data in variables.items():
if (variable == "collection_name" or variable == "playlist_name") and _method in ["radarr_tag", "item_radarr_tag", "sonarr_tag", "item_sonarr_tag"]: if (variable == "collection_name" or variable == "playlist_name") and _method in ["radarr_tag", "item_radarr_tag", "sonarr_tag", "item_sonarr_tag"]:
_data = scan_text(_data, variable, variable_data.replace(",", "")) _data = scan_text(_data, variable, variable_data.replace(",", ""))
elif variable != "name": elif (variable == "name_format" and _method != "name") or (variable == "summary_format" and _method != "summary"):
continue
elif variable != "name" and (_method not in ["name", "summary"] or variable != "key_name"):
_data = scan_text(_data, variable, variable_data) _data = scan_text(_data, variable, variable_data)
for dm, dd in default.items(): for dm, dd in default.items():
_data = scan_text(_data, dm, dd) if (dm == "name_format" and _method != "name") or (dm == "summary_format" and _method != "summary"):
continue
elif _method not in ["name", "summary"] or dm != "key_name":
_data = scan_text(_data, dm, dd)
except Failed: except Failed:
if _debug: if _debug:
logger.trace(f"Failed {_method}: {_data}") logger.trace(f"Failed {_method}: {_data}")

@ -227,7 +227,7 @@ class Overlay:
raise Failed(f"Overlay Error: failed to parse overlay text name: {self.name}") raise Failed(f"Overlay Error: failed to parse overlay text name: {self.name}")
self.name = f"text({match.group(1)})" self.name = f"text({match.group(1)})"
text = f"{match.group(1)}" text = f"{match.group(1)}"
code_base = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) code_base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
font_base = os.path.join(code_base, "fonts") font_base = os.path.join(code_base, "fonts")
self.font_name = os.path.join(font_base, "Roboto-Medium.ttf") self.font_name = os.path.join(font_base, "Roboto-Medium.ttf")
if "font_size" in self.data: if "font_size" in self.data:

Loading…
Cancel
Save