[89] add variables to translations

pull/1093/head
meisnate12 2 years ago
parent 34ee0e63a1
commit 121c43775a

@ -1 +1 @@
1.17.3-develop88 1.17.3-develop89

@ -1,15 +1,16 @@
version: 1.18.0.2 version: 1.18.0.2
variables:
library_type: library_type:
# For Movie Libraries # For Movie Libraries
movie: movie movie: Movie
# For Show Libraries # For Show Libraries
show: show show: Show
# For Music Libraries # For Music Libraries
artist: artist artist: Artist
# For Other Video Libraries # For Other Video Libraries
video: video video: Video
# For Playlists # For Playlists
item: item item: Item
key_names: key_names:
translations: translations:

@ -1,15 +1,16 @@
version: 1.18.0.2 version: 1.18.0.2
variables:
library_type: library_type:
# For Movie Libraries # For Movie Libraries
movie: film movie: Film
# For Show Libraries # For Show Libraries
show: émission show: Émission
# For Music Libraries # For Music Libraries
artist: artiste artist: Artiste
# For Other Video Libraries # For Other Video Libraries
video: vidéo video: Vidéo
# For Playlists # For Playlists
item: article item: Article
key_names: key_names:
translations: translations:

@ -14,7 +14,7 @@ These collections are applied by calling the below paths into the `metadata_path
|:------------|:--------------------|----------------------------------------------|:-----------------:|:----------------:| |:------------|:--------------------|----------------------------------------------|:-----------------:|:----------------:|
| AniList | `anilist` | AniList Popular, AniList Season | ✅ | ✅ | | AniList | `anilist` | AniList Popular, AniList Season | ✅ | ✅ |
| Basic | `basic` | Newly Released, New Episodes | ✅ | ✅ | | Basic | `basic` | Newly Released, New Episodes | ✅ | ✅ |
| FlixPatrol | `flixpatrol` | Top Disney, Hbo, Hulu, Netflix, Prime, Para+ | ✅ | ✅ | | FlixPatrol | `flixpatrol` | Top Disney, Top Hbo, Top Hulu, Top Netflix | ✅ | ✅ |
| IMDb | `imdb` | IMDb Popular, IMDb Top 250 | ✅ | ✅ | | IMDb | `imdb` | IMDb Popular, IMDb Top 250 | ✅ | ✅ |
| MyAnimeList | `myanimelist` | MyAnimeList Popular, MyAnimeList Top Rated | ✅ | ✅ | | MyAnimeList | `myanimelist` | MyAnimeList Popular, MyAnimeList Top Rated | ✅ | ✅ |
| Other | `other` | AniDB Popular, Common Sense Selection | ✅ | ✅ | | Other | `other` | AniDB Popular, Common Sense Selection | ✅ | ✅ |

@ -145,13 +145,21 @@ class DataFile:
if "translations" not in yaml.data: if "translations" not in yaml.data:
raise Failed(f"URL Error: Top Level translations attribute not found in {content_path}") raise Failed(f"URL Error: Top Level translations attribute not found in {content_path}")
translations = {k: {"default": v} for k, v in yaml.data["translations"].items()} translations = {k: {"default": v} for k, v in yaml.data["translations"].items()}
translations["library_type"] = {"default": self.library.type.lower() if self.library else "item"} lib_type = self.library.type.lower() if self.library else "item"
translations["library_type"] = {"default": lib_type}
logger.debug(f"Translations Loaded From: {dir_path}") logger.debug(f"Translations Loaded From: {dir_path}")
key_names = {} key_names = {}
def add_translation(yaml_path, yaml_key, data=None): def add_translation(yaml_path, yaml_key, data=None):
yaml_content = YAML(input_data=data, path=yaml_path if data is None else None, check_empty=True) yaml_content = YAML(input_data=data, path=yaml_path if data is None else None, check_empty=True)
if "translations" in yaml_content.data: if "variables" in yaml_content.data and yaml_content.data["variables"]:
for var_key, var_value in yaml_content.data["variables"]:
if lib_type in var_value:
if var_key not in key_names:
key_names[var_key] = {}
key_names[var_key][yaml_key] = var_value[lib_type]
if "translations" in yaml_content.data and yaml_content.data["translations"]:
for ky, vy in yaml_content.data["translations"].items(): for ky, vy in yaml_content.data["translations"].items():
if ky in translations: if ky in translations:
translations[ky][yaml_key] = vy translations[ky][yaml_key] = vy
@ -161,7 +169,7 @@ class DataFile:
logger.error(f"Config Error: Top Level translations attribute not found in {yaml_path}") logger.error(f"Config Error: Top Level translations attribute not found in {yaml_path}")
if "key_names" in yaml_content.data and yaml_content.data["key_names"]: if "key_names" in yaml_content.data and yaml_content.data["key_names"]:
for kn, vn in yaml_content.data["key_names"].items(): for kn, vn in yaml_content.data["key_names"].items():
if kn not in translations: if kn not in key_names:
key_names[kn] = {} key_names[kn] = {}
key_names[kn][yaml_key] = vn key_names[kn][yaml_key] = vn
@ -241,15 +249,14 @@ class DataFile:
else: else:
variables[temp_key] = temp_value variables[temp_key] = temp_value
translation_variables = {}
language = variables["language"] if "language" in variables else "default" language = variables["language"] if "language" in variables else "default"
logger.debug(variables) translation_variables = {k: v[language if language in v else "default"] for k, v in self.translations.items()}
for temp_key, temp_value in self.translations.items(): for var_key, var_value in self.key_names.items():
if temp_key == "library_type": if var_key == "library_type" and language in var_value:
variables[temp_key] = temp_value[language if language in temp_value else "default"] variables[var_key] = var_value[language].lower()
variables[f"{temp_key}U"] = temp_value[language if language in temp_value else "default"].capitalize() variables[f"{var_key}U"] = var_value[language]
else: elif language in var_value:
translation_variables[temp_key] = temp_value[language if language in temp_value else "default"] translation_variables[var_key] = var_value[language]
for key, value in variables.copy().items(): for key, value in variables.copy().items():
variables[f"{key}_encoded"] = requests.utils.quote(str(value)) variables[f"{key}_encoded"] = requests.utils.quote(str(value))
@ -775,9 +782,9 @@ class MetadataFile(DataFile):
test = util.parse("Config", "test", dynamic, parent=map_name, methods=methods, default=False, datatype="bool") if "test" in methods else False test = util.parse("Config", "test", dynamic, parent=map_name, methods=methods, default=False, datatype="bool") if "test" in methods else False
sync = util.parse("Config", "sync", dynamic, parent=map_name, methods=methods, default=False, datatype="bool") if "sync" in methods else False sync = util.parse("Config", "sync", dynamic, parent=map_name, methods=methods, default=False, datatype="bool") if "sync" in methods else False
if "<<library_type>>" in title_format: if "<<library_type>>" in title_format:
title_format = title_format.replace("<<library_type>>", library.type) title_format = title_format.replace("<<library_type>>", library.type.lower())
if "<<library_typeU>>" in title_format: if "<<library_typeU>>" in title_format:
title_format = title_format.replace("<<library_typeU>>", library.type.capitalize()) title_format = title_format.replace("<<library_typeU>>", library.type)
if "limit" in self.temp_vars and "<<limit>>" in title_format: if "limit" in self.temp_vars and "<<limit>>" in title_format:
title_format = title_format.replace("<<limit>>", self.temp_vars["limit"]) title_format = title_format.replace("<<limit>>", self.temp_vars["limit"])
template_variables = util.parse("Config", "template_variables", dynamic, parent=map_name, methods=methods, datatype="dictdict") if "template_variables" in methods else {} template_variables = util.parse("Config", "template_variables", dynamic, parent=map_name, methods=methods, datatype="dictdict") if "template_variables" in methods else {}

@ -623,7 +623,7 @@ class Operations:
yaml.data["metadata"][map_key] = loop_dict(attrs, og_dict) yaml.data["metadata"][map_key] = loop_dict(attrs, og_dict)
logger.exorcise() logger.exorcise()
yaml.save() yaml.save()
logger.info(f"{len(yaml.data['metadata'])} {self.library.type.capitalize()}{'s' if len(yaml.data['metadata']) > 1 else ''} Backed Up") logger.info(f"{len(yaml.data['metadata'])} {self.library.type}{'s' if len(yaml.data['metadata']) > 1 else ''} Backed Up")
operation_run_time = str(datetime.now() - operation_start).split('.')[0] operation_run_time = str(datetime.now() - operation_start).split('.')[0]
logger.info("") logger.info("")

Loading…
Cancel
Save