From 25b859747b06178c64e947b75a869fe4721cda9b Mon Sep 17 00:00:00 2001 From: hawkeye116477 Date: Mon, 4 Nov 2024 15:21:24 +0100 Subject: [PATCH] Reorganize translations to make it reusable --- ...legendaryLocKeys.txt => commonLocKeys.txt} | 9 +++ make_scripts/download_translations.py | 26 +++---- make_scripts/update_3p_localization.py | 30 ++++---- src/Comet.cs | 2 +- src/GogOssGameController.cs | 2 +- src/GogOssLibrary.cs | 2 +- src/GogOssLibrarySettingsView.xaml.cs | 8 +- src/Gogdl.cs | 2 +- src/Localization/en_US-gog-oss.xaml | 10 --- src/Localization/en_US.xaml | 9 +++ src/LocalizationKeys.cs | 76 +++++++++---------- 11 files changed, 89 insertions(+), 87 deletions(-) rename make_scripts/config/{legendaryLocKeys.txt => commonLocKeys.txt} (92%) diff --git a/make_scripts/config/legendaryLocKeys.txt b/make_scripts/config/commonLocKeys.txt similarity index 92% rename from make_scripts/config/legendaryLocKeys.txt rename to make_scripts/config/commonLocKeys.txt index 2dfb70d..40012e9 100644 --- a/make_scripts/config/legendaryLocKeys.txt +++ b/make_scripts/config/commonLocKeys.txt @@ -128,3 +128,12 @@ LOCLegendarySystemHibernateCountdown LOCLegendarySystemSuspendCountdown LOCLegendaryMigrationCompleted LOCLegendaryMigrationNoGames +LOCLegendaryLauncherNotInstalled +LOCLegendaryDownloadManagerWhatsUp +LOCLegendaryPanel +LOCLegendaryDownloadAlreadyExists +LOCLegendaryDownloadAlreadyExistsOther +LOCLegendaryGamesUpdatesUnderway +LOCLegendaryMigrateGamesEpic +LOCLegendaryMigratingGamesEpic +LOCLegendaryMigrationConfirm diff --git a/make_scripts/download_translations.py b/make_scripts/download_translations.py index 37e8f06..79ef7f0 100644 --- a/make_scripts/download_translations.py +++ b/make_scripts/download_translations.py @@ -52,37 +52,37 @@ class FirstCrowdinClient(CrowdinClient): "sys": xmlns_sys, "x": xmlns_x} # Copy only needed localizations and rename - legendary_loc_keys = {} - with open(pj(script_path, "config", "legendaryLocKeys.txt"), - "r", encoding="utf-8") as legendary_loc_keys_content: - for line in legendary_loc_keys_content: + common_loc_keys = {} + with open(pj(script_path, "config", "commonLocKeys.txt"), + "r", encoding="utf-8") as common_loc_keys_content: + for line in common_loc_keys_content: if line := line.strip(): - legendary_loc_keys[line] = "" + common_loc_keys[line] = "" - legendary_loc_path = pj(tmpdirname, "src", "Localization") - for filename in os.listdir(legendary_loc_path): - path = os.path.join(legendary_loc_path, filename) + common_loc_path = pj(tmpdirname, "src", "Localization") + for filename in os.listdir(common_loc_path): + path = os.path.join(common_loc_path, filename) if os.path.isdir(path): continue if any(x in filename for x in ["legendary", "gog-oss"]): if "gog-oss" in filename: shutil.copy(path, pj(src_path, "Localization")) continue - legendary_loc = ET.parse(pj(legendary_loc_path, filename)) + common_loc = ET.parse(pj(common_loc_path, filename)) xml_root = ET.Element("ResourceDictionary", nsmap=NSMAP) xml_doc = ET.ElementTree(xml_root) - for child in legendary_loc.getroot(): + for child in common_loc.getroot(): key = child.get(ET.QName(xmlns_x, "Key")) - if key in legendary_loc_keys: + if key in common_loc_keys: key_text = child.text if not key_text: key_text = "" key = key.replace("Legendary", "GogOss") new_key = ET.Element(ET.QName(xmlns_sys, "String")) - new_key.set(ET.QName(xmlns_x, "Key"), key) - new_key.text = key_text.replace("Legendary", "GOG OSS") + new_key.set(ET.QName(xmlns_x, "Key"), key.replace("Epic", "Gog")) + new_key.text = key_text.replace("Legendary", "GOG OSS").replace("{PluginShortName}", "GOG OSS").replace("{OriginalPluginShortName}", "GOG").replace("{SourceName}", "GOG") xml_root.append(new_key) ET.indent(xml_doc, level=0) diff --git a/make_scripts/update_3p_localization.py b/make_scripts/update_3p_localization.py index ae8ef20..c2c046c 100644 --- a/make_scripts/update_3p_localization.py +++ b/make_scripts/update_3p_localization.py @@ -22,12 +22,12 @@ if line := line.strip(): gog_loc_keys[line] = "" -legendary_loc_keys = {} -with open(pj(script_path, "config", "legendaryLocKeys.txt"), - "r", encoding="utf-8") as legendary_loc_keys_content: - for line in legendary_loc_keys_content: +common_loc_keys = {} +with open(pj(script_path, "config", "commonLocKeys.txt"), + "r", encoding="utf-8") as common_loc_keys_content: + for line in common_loc_keys_content: if line := line.strip(): - legendary_loc_keys[line] = "" + common_loc_keys[line] = "" playnite_loc_keys = {} with open(pj(script_path, "config", "playniteLocKeys.txt"), @@ -48,29 +48,27 @@ "sys": xmlns_sys, "x": xmlns_x} -# Copy localizations from Legendary -legendary_loc_path = pj(main_path, "..", "playnite-legendary-plugin", "src", "Localization") -for filename in os.listdir(legendary_loc_path): - path = os.path.join(legendary_loc_path, filename) +# Copy common localizations +common_loc_path = pj(main_path, "..", "playnite-common-plugin", "src", "Localization") +for filename in os.listdir(common_loc_path): + path = os.path.join(common_loc_path, filename) if os.path.isdir(path): continue - if "legendary" in filename: - continue - legendary_loc = ET.parse(pj(legendary_loc_path, filename)) + common_loc = ET.parse(pj(common_loc_path, filename)) xml_root = ET.Element("ResourceDictionary", nsmap=NSMAP) xml_doc = ET.ElementTree(xml_root) - for child in legendary_loc.getroot(): + for child in common_loc.getroot(): key = child.get(ET.QName(xmlns_x, "Key")) - if key in legendary_loc_keys: + if key in common_loc_keys: key_text = child.text if not key_text: key_text = "" key = key.replace("Legendary", "GogOss") new_key = ET.Element(ET.QName(xmlns_sys, "String")) - new_key.set(ET.QName(xmlns_x, "Key"), key) - new_key.text = key_text.replace("Legendary", "GOG OSS") + new_key.set(ET.QName(xmlns_x, "Key"), key.replace("Epic", "Gog")) + new_key.text = key_text.replace("Legendary", "GOG OSS").replace("{PluginShortName}", "GOG OSS").replace("{OriginalPluginShortName}", "GOG").replace("{SourceName}", "GOG") xml_root.append(new_key) ET.indent(xml_doc, level=0) diff --git a/src/Comet.cs b/src/Comet.cs index e18c10b..fd15f30 100644 --- a/src/Comet.cs +++ b/src/Comet.cs @@ -120,7 +120,7 @@ public static async Task GetVersionInfoContent() var logger = LogManager.GetLogger(); if (!IsInstalled) { - throw new Exception(ResourceProvider.GetString(LOC.GogOssCometNotInstalled)); + throw new Exception(ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Comet")); } var cacheVersionPath = GogOssLibrary.Instance.GetCachePath("infocache"); if (!Directory.Exists(cacheVersionPath)) diff --git a/src/GogOssGameController.cs b/src/GogOssGameController.cs index 44bd42c..9df9ad6 100644 --- a/src/GogOssGameController.cs +++ b/src/GogOssGameController.cs @@ -46,7 +46,7 @@ public static void LaunchInstaller(List installDat { if (!Gogdl.IsInstalled) { - throw new Exception(ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled)); + throw new Exception(ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl")); } var playniteAPI = API.Instance; Window window = null; diff --git a/src/GogOssLibrary.cs b/src/GogOssLibrary.cs index 0bb512a..55ee299 100644 --- a/src/GogOssLibrary.cs +++ b/src/GogOssLibrary.cs @@ -1017,7 +1017,7 @@ public override IEnumerable GetMainMenuItems(GetMainMenuItemsArgs { if (!Gogdl.IsInstalled) { - PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled)); + PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl")); return; } diff --git a/src/GogOssLibrarySettingsView.xaml.cs b/src/GogOssLibrarySettingsView.xaml.cs index 0781751..3cc0438 100644 --- a/src/GogOssLibrarySettingsView.xaml.cs +++ b/src/GogOssLibrarySettingsView.xaml.cs @@ -116,8 +116,8 @@ private async void GogOssSettingsUC_Loaded(object sender, RoutedEventArgs e) else { troubleshootingInformation.CometVersion = "Not%20installed"; - CometVersionTxt.Text = ResourceProvider.GetString(LOC.GogOssCometNotInstalled); - CometBinaryTxt.Text = ResourceProvider.GetString(LOC.GogOssCometNotInstalled); + CometVersionTxt.Text = ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Comet"); + CometBinaryTxt.Text = ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Comet"); CheckForCometUpdatesBtn.IsEnabled = false; OpenCometBinaryBtn.IsEnabled = false; } @@ -134,8 +134,8 @@ private async void GogOssSettingsUC_Loaded(object sender, RoutedEventArgs e) else { troubleshootingInformation.GogdlVersion = "Not%20installed"; - GogdlVersionTxt.Text = ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled); - GogdlBinaryTxt.Text = ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled); + GogdlVersionTxt.Text = ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl"); + GogdlBinaryTxt.Text = ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl"); CheckForGogdlUpdatesBtn.IsEnabled = false; OpenGogdlBinaryBtn.IsEnabled = false; } diff --git a/src/Gogdl.cs b/src/Gogdl.cs index 1fc5d52..2b3deac 100644 --- a/src/Gogdl.cs +++ b/src/Gogdl.cs @@ -174,7 +174,7 @@ public static async Task GetVersionInfoContent() var logger = LogManager.GetLogger(); if (!IsInstalled) { - throw new Exception(ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled)); + throw new Exception(ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl")); } var cacheVersionPath = GogOssLibrary.Instance.GetCachePath("infocache"); if (!Directory.Exists(cacheVersionPath)) diff --git a/src/Localization/en_US-gog-oss.xaml b/src/Localization/en_US-gog-oss.xaml index f2ce332..5191eaa 100644 --- a/src/Localization/en_US-gog-oss.xaml +++ b/src/Localization/en_US-gog-oss.xaml @@ -1,26 +1,16 @@ Comet Path - Comet is not installed. Comet version Comet binary Gogdl Path Gogdl version Gogdl binary - Gogdl is not installed. Use vertical covers Language Beta channel {0} doesn't appear to be installable. Check downloadable content at {1}. - The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar. - GOG OSS Panel - {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. - Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. Enable Comet support It's required for achievements, leaderboards and multiplayer mode, but may cause problems with operation of some games. Check for Comet and Gogdl updates - Updates for games from GOG are being downloaded. - Migrate all games from GOG plugin - Migrating all games from GOG plugin... - All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this? diff --git a/src/Localization/en_US.xaml b/src/Localization/en_US.xaml index d9a07d6..bb29dc8 100644 --- a/src/Localization/en_US.xaml +++ b/src/Localization/en_US.xaml @@ -129,4 +129,13 @@ {0} has been successfully uninstalled. Following games have been successfully uninstalled: {0}. Games + {AppName} is not installed. + GOG OSS Panel + The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar. + {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. + Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. + Migrate all games from GOG plugin + Migrating all games from GOG plugin... + All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this? + Updates for games from GOG are being downloaded. diff --git a/src/LocalizationKeys.cs b/src/LocalizationKeys.cs index 592476a..85a90ec 100644 --- a/src/LocalizationKeys.cs +++ b/src/LocalizationKeys.cs @@ -10,10 +10,6 @@ public static class LOC /// public const string GogOssCometCustomPath = "LOCGogOssCometCustomPath"; /// - /// Comet is not installed. - /// - public const string GogOssCometNotInstalled = "LOCGogOssCometNotInstalled"; - /// /// Comet version /// public const string GogOssCometVersion = "LOCGogOssCometVersion"; @@ -34,10 +30,6 @@ public static class LOC /// public const string GogOssGogdlBinary = "LOCGogOssGogdlBinary"; /// - /// Gogdl is not installed. - /// - public const string GogOssGogdlNotInstalled = "LOCGogOssGogdlNotInstalled"; - /// /// Use vertical covers /// public const string GogOssUseVerticalCovers = "LOCGogOssUseVerticalCovers"; @@ -54,22 +46,6 @@ public static class LOC /// public const string GogOssGameNotInstallable = "LOCGogOssGameNotInstallable"; /// - /// The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar. - /// - public const string GogOssDownloadManagerWhatsUp = "LOCGogOssDownloadManagerWhatsUp"; - /// - /// GOG OSS Panel - /// - public const string GogOssPanel = "LOCGogOssPanel"; - /// - /// {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. - /// - public const string GogOssDownloadAlreadyExists = "LOCGogOssDownloadAlreadyExists"; - /// - /// Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. - /// - public const string GogOssDownloadAlreadyExistsOther = "LOCGogOssDownloadAlreadyExistsOther"; - /// /// Enable Comet support /// public const string GogOssEnableCometSupport = "LOCGogOssEnableCometSupport"; @@ -82,22 +58,6 @@ public static class LOC /// public const string GogOssCometUpdatePolicy = "LOCGogOssCometUpdatePolicy"; /// - /// Updates for games from GOG are being downloaded. - /// - public const string GogOssGamesUpdatesUnderway = "LOCGogOssGamesUpdatesUnderway"; - /// - /// Migrate all games from GOG plugin - /// - public const string GogOssMigrateGamesGog = "LOCGogOssMigrateGamesGog"; - /// - /// Migrating all games from GOG plugin... - /// - public const string GogOssMigratingGamesGog = "LOCGogOssMigratingGamesGog"; - /// - /// All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this? - /// - public const string GogOssMigrationConfirm = "LOCGogOssMigrationConfirm"; - /// /// Games Installation Path /// public const string GogOssGamesInstallationPath = "LOCGogOssGamesInstallationPath"; @@ -614,6 +574,42 @@ public static class LOC /// public const string GogOssGames = "LOCGogOssGames"; /// + /// {AppName} is not installed. + /// + public const string GogOssLauncherNotInstalled = "LOCGogOssLauncherNotInstalled"; + /// + /// GOG OSS Panel + /// + public const string GogOssPanel = "LOCGogOssPanel"; + /// + /// The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar. + /// + public const string GogOssDownloadManagerWhatsUp = "LOCGogOssDownloadManagerWhatsUp"; + /// + /// {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. + /// + public const string GogOssDownloadAlreadyExists = "LOCGogOssDownloadAlreadyExists"; + /// + /// Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar. + /// + public const string GogOssDownloadAlreadyExistsOther = "LOCGogOssDownloadAlreadyExistsOther"; + /// + /// Migrate all games from GOG plugin + /// + public const string GogOssMigrateGamesGog = "LOCGogOssMigrateGamesGog"; + /// + /// Migrating all games from GOG plugin... + /// + public const string GogOssMigratingGamesGog = "LOCGogOssMigratingGamesGog"; + /// + /// All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this? + /// + public const string GogOssMigrationConfirm = "LOCGogOssMigrationConfirm"; + /// + /// Updates for games from GOG are being downloaded. + /// + public const string GogOssGamesUpdatesUnderway = "LOCGogOssGamesUpdatesUnderway"; + /// /// Filter Active /// public const string GogOss3P_PlayniteFilterActiveLabel = "LOCGogOss3P_PlayniteFilterActiveLabel";