From 121c43775a7429cb5b09a27cbb7a0db2b6640cd0 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 5 Oct 2022 10:49:39 -0400 Subject: [PATCH] [89] add variables to translations --- VERSION | 2 +- defaults/translations/default.yml | 23 ++++++++++----------- defaults/translations/fr.yml | 23 ++++++++++----------- docs/defaults/files.md | 2 +- modules/meta.py | 33 +++++++++++++++++++------------ modules/operations.py | 2 +- 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/VERSION b/VERSION index d473693a..b364fda3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3-develop88 +1.17.3-develop89 diff --git a/defaults/translations/default.yml b/defaults/translations/default.yml index a862d86e..b9e53be5 100644 --- a/defaults/translations/default.yml +++ b/defaults/translations/default.yml @@ -1,15 +1,16 @@ version: 1.18.0.2 -library_type: - # For Movie Libraries - movie: movie - # For Show Libraries - show: show - # For Music Libraries - artist: artist - # For Other Video Libraries - video: video - # For Playlists - item: item +variables: + library_type: + # For Movie Libraries + movie: Movie + # For Show Libraries + show: Show + # For Music Libraries + artist: Artist + # For Other Video Libraries + video: Video + # For Playlists + item: Item key_names: translations: diff --git a/defaults/translations/fr.yml b/defaults/translations/fr.yml index c704514a..886aa595 100644 --- a/defaults/translations/fr.yml +++ b/defaults/translations/fr.yml @@ -1,15 +1,16 @@ version: 1.18.0.2 -library_type: - # For Movie Libraries - movie: film - # For Show Libraries - show: émission - # For Music Libraries - artist: artiste - # For Other Video Libraries - video: vidéo - # For Playlists - item: article +variables: + library_type: + # For Movie Libraries + movie: Film + # For Show Libraries + show: Émission + # For Music Libraries + artist: Artiste + # For Other Video Libraries + video: Vidéo + # For Playlists + item: Article key_names: translations: diff --git a/docs/defaults/files.md b/docs/defaults/files.md index aeddb82b..341a13c4 100644 --- a/docs/defaults/files.md +++ b/docs/defaults/files.md @@ -14,7 +14,7 @@ These collections are applied by calling the below paths into the `metadata_path |:------------|:--------------------|----------------------------------------------|:-----------------:|:----------------:| | AniList | `anilist` | AniList Popular, AniList Season | ✅ | ✅ | | 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 | ✅ | ✅ | | MyAnimeList | `myanimelist` | MyAnimeList Popular, MyAnimeList Top Rated | ✅ | ✅ | | Other | `other` | AniDB Popular, Common Sense Selection | ✅ | ✅ | diff --git a/modules/meta.py b/modules/meta.py index 44ccb004..48b50335 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -145,13 +145,21 @@ class DataFile: if "translations" not in yaml.data: 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["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}") key_names = {} 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) - 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(): if ky in translations: 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}") if "key_names" in yaml_content.data and yaml_content.data["key_names"]: 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][yaml_key] = vn @@ -241,15 +249,14 @@ class DataFile: else: variables[temp_key] = temp_value - translation_variables = {} language = variables["language"] if "language" in variables else "default" - logger.debug(variables) - for temp_key, temp_value in self.translations.items(): - if temp_key == "library_type": - variables[temp_key] = temp_value[language if language in temp_value else "default"] - variables[f"{temp_key}U"] = temp_value[language if language in temp_value else "default"].capitalize() - else: - translation_variables[temp_key] = temp_value[language if language in temp_value else "default"] + translation_variables = {k: v[language if language in v else "default"] for k, v in self.translations.items()} + for var_key, var_value in self.key_names.items(): + if var_key == "library_type" and language in var_value: + variables[var_key] = var_value[language].lower() + variables[f"{var_key}U"] = var_value[language] + elif language in var_value: + translation_variables[var_key] = var_value[language] for key, value in variables.copy().items(): 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 sync = util.parse("Config", "sync", dynamic, parent=map_name, methods=methods, default=False, datatype="bool") if "sync" in methods else False if "<>" in title_format: - title_format = title_format.replace("<>", library.type) + title_format = title_format.replace("<>", library.type.lower()) if "<>" in title_format: - title_format = title_format.replace("<>", library.type.capitalize()) + title_format = title_format.replace("<>", library.type) if "limit" in self.temp_vars and "<>" in title_format: title_format = title_format.replace("<>", 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 {} diff --git a/modules/operations.py b/modules/operations.py index cc451de2..c8042694 100644 --- a/modules/operations.py +++ b/modules/operations.py @@ -623,7 +623,7 @@ class Operations: yaml.data["metadata"][map_key] = loop_dict(attrs, og_dict) logger.exorcise() 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] logger.info("")