Skip to content

Commit

Permalink
Reorganize translations to make it reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye116477 committed Nov 4, 2024
1 parent 2dbb788 commit 25b8597
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,12 @@ LOCLegendarySystemHibernateCountdown
LOCLegendarySystemSuspendCountdown
LOCLegendaryMigrationCompleted
LOCLegendaryMigrationNoGames
LOCLegendaryLauncherNotInstalled
LOCLegendaryDownloadManagerWhatsUp
LOCLegendaryPanel
LOCLegendaryDownloadAlreadyExists
LOCLegendaryDownloadAlreadyExistsOther
LOCLegendaryGamesUpdatesUnderway
LOCLegendaryMigrateGamesEpic
LOCLegendaryMigratingGamesEpic
LOCLegendaryMigrationConfirm
26 changes: 13 additions & 13 deletions make_scripts/download_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 14 additions & 16 deletions make_scripts/update_3p_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Comet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static async Task<LauncherVersion> 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))
Expand Down
2 changes: 1 addition & 1 deletion src/GogOssGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void LaunchInstaller(List<DownloadManagerData.Download> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/GogOssLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ public override IEnumerable<MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs
{
if (!Gogdl.IsInstalled)
{
PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.GogOssGogdlNotInstalled));
PlayniteApi.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.GogOssLauncherNotInstalled).Replace("{AppName}", "Gogdl"));
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/GogOssLibrarySettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gogdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static async Task<LauncherVersion> 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))
Expand Down
10 changes: 0 additions & 10 deletions src/Localization/en_US-gog-oss.xaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
<?xml version='1.0' encoding='utf-8'?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<sys:String x:Key="LOCGogOssCometCustomPath">Comet Path</sys:String>
<sys:String x:Key="LOCGogOssCometNotInstalled">Comet is not installed.</sys:String>
<sys:String x:Key="LOCGogOssCometVersion">Comet version</sys:String>
<sys:String x:Key="LOCGogOssCometBinary">Comet binary</sys:String>
<sys:String x:Key="LOCGogOssGogdlCustomPath">Gogdl Path</sys:String>
<sys:String x:Key="LOCGogOssGogdlVersion">Gogdl version</sys:String>
<sys:String x:Key="LOCGogOssGogdlBinary">Gogdl binary</sys:String>
<sys:String x:Key="LOCGogOssGogdlNotInstalled">Gogdl is not installed.</sys:String>
<sys:String x:Key="LOCGogOssUseVerticalCovers">Use vertical covers</sys:String>
<sys:String x:Key="LOCGogOssLanguage">Language</sys:String>
<sys:String x:Key="LOCGogOssBetaChannel">Beta channel</sys:String>
<sys:String x:Key="LOCGogOssGameNotInstallable">{0} doesn't appear to be installable. Check downloadable content at {1}.</sys:String>
<sys:String x:Key="LOCGogOssDownloadManagerWhatsUp">The download will start soon. You can see its status by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssPanel">GOG OSS Panel</sys:String>
<sys:String x:Key="LOCGogOssDownloadAlreadyExists">{0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssDownloadAlreadyExistsOther">Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssEnableCometSupport">Enable Comet support</sys:String>
<sys:String x:Key="LOCGogOssEnableCometSupportToolTip">It's required for achievements, leaderboards and multiplayer mode, but may cause problems with operation of some games.</sys:String>
<sys:String x:Key="LOCGogOssCometUpdatePolicy">Check for Comet and Gogdl updates</sys:String>
<sys:String x:Key="LOCGogOssGamesUpdatesUnderway">Updates for games from GOG are being downloaded.</sys:String>
<sys:String x:Key="LOCGogOssMigrateGamesGog">Migrate all games from GOG plugin</sys:String>
<sys:String x:Key="LOCGogOssMigratingGamesGog">Migrating all games from GOG plugin...</sys:String>
<sys:String x:Key="LOCGogOssMigrationConfirm">All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this?</sys:String>
</ResourceDictionary>
9 changes: 9 additions & 0 deletions src/Localization/en_US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,13 @@
<sys:String x:Key="LOCGogOssUninstallSuccess">{0} has been successfully uninstalled.</sys:String>
<sys:String x:Key="LOCGogOssUninstallSuccessOther">Following games have been successfully uninstalled: {0}.</sys:String>
<sys:String x:Key="LOCGogOssGames">Games</sys:String>
<sys:String x:Key="LOCGogOssLauncherNotInstalled">{AppName} is not installed.</sys:String>
<sys:String x:Key="LOCGogOssPanel">GOG OSS Panel</sys:String>
<sys:String x:Key="LOCGogOssDownloadManagerWhatsUp">The download will start soon. You can see its status by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssDownloadAlreadyExists">{0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssDownloadAlreadyExistsOther">Following games are already in the download list: {0}. You can see status of the download by accessing GOG OSS Panel via Menu =&gt; View or sidebar.</sys:String>
<sys:String x:Key="LOCGogOssMigrateGamesGog">Migrate all games from GOG plugin</sys:String>
<sys:String x:Key="LOCGogOssMigratingGamesGog">Migrating all games from GOG plugin...</sys:String>
<sys:String x:Key="LOCGogOssMigrationConfirm">All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this?</sys:String>
<sys:String x:Key="LOCGogOssGamesUpdatesUnderway">Updates for games from GOG are being downloaded.</sys:String>
</ResourceDictionary>
76 changes: 36 additions & 40 deletions src/LocalizationKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public static class LOC
/// </summary>
public const string GogOssCometCustomPath = "LOCGogOssCometCustomPath";
/// <summary>
/// Comet is not installed.
/// </summary>
public const string GogOssCometNotInstalled = "LOCGogOssCometNotInstalled";
/// <summary>
/// Comet version
/// </summary>
public const string GogOssCometVersion = "LOCGogOssCometVersion";
Expand All @@ -34,10 +30,6 @@ public static class LOC
/// </summary>
public const string GogOssGogdlBinary = "LOCGogOssGogdlBinary";
/// <summary>
/// Gogdl is not installed.
/// </summary>
public const string GogOssGogdlNotInstalled = "LOCGogOssGogdlNotInstalled";
/// <summary>
/// Use vertical covers
/// </summary>
public const string GogOssUseVerticalCovers = "LOCGogOssUseVerticalCovers";
Expand All @@ -54,22 +46,6 @@ public static class LOC
/// </summary>
public const string GogOssGameNotInstallable = "LOCGogOssGameNotInstallable";
/// <summary>
/// The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar.
/// </summary>
public const string GogOssDownloadManagerWhatsUp = "LOCGogOssDownloadManagerWhatsUp";
/// <summary>
/// GOG OSS Panel
/// </summary>
public const string GogOssPanel = "LOCGogOssPanel";
/// <summary>
/// {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar.
/// </summary>
public const string GogOssDownloadAlreadyExists = "LOCGogOssDownloadAlreadyExists";
/// <summary>
/// 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.
/// </summary>
public const string GogOssDownloadAlreadyExistsOther = "LOCGogOssDownloadAlreadyExistsOther";
/// <summary>
/// Enable Comet support
/// </summary>
public const string GogOssEnableCometSupport = "LOCGogOssEnableCometSupport";
Expand All @@ -82,22 +58,6 @@ public static class LOC
/// </summary>
public const string GogOssCometUpdatePolicy = "LOCGogOssCometUpdatePolicy";
/// <summary>
/// Updates for games from GOG are being downloaded.
/// </summary>
public const string GogOssGamesUpdatesUnderway = "LOCGogOssGamesUpdatesUnderway";
/// <summary>
/// Migrate all games from GOG plugin
/// </summary>
public const string GogOssMigrateGamesGog = "LOCGogOssMigrateGamesGog";
/// <summary>
/// Migrating all games from GOG plugin...
/// </summary>
public const string GogOssMigratingGamesGog = "LOCGogOssMigratingGamesGog";
/// <summary>
/// All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this?
/// </summary>
public const string GogOssMigrationConfirm = "LOCGogOssMigrationConfirm";
/// <summary>
/// Games Installation Path
/// </summary>
public const string GogOssGamesInstallationPath = "LOCGogOssGamesInstallationPath";
Expand Down Expand Up @@ -614,6 +574,42 @@ public static class LOC
/// </summary>
public const string GogOssGames = "LOCGogOssGames";
/// <summary>
/// {AppName} is not installed.
/// </summary>
public const string GogOssLauncherNotInstalled = "LOCGogOssLauncherNotInstalled";
/// <summary>
/// GOG OSS Panel
/// </summary>
public const string GogOssPanel = "LOCGogOssPanel";
/// <summary>
/// The download will start soon. You can see its status by accessing GOG OSS Panel via Menu => View or sidebar.
/// </summary>
public const string GogOssDownloadManagerWhatsUp = "LOCGogOssDownloadManagerWhatsUp";
/// <summary>
/// {0} is already in the download list. You can see status of the download by accessing GOG OSS Panel via Menu => View or sidebar.
/// </summary>
public const string GogOssDownloadAlreadyExists = "LOCGogOssDownloadAlreadyExists";
/// <summary>
/// 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.
/// </summary>
public const string GogOssDownloadAlreadyExistsOther = "LOCGogOssDownloadAlreadyExistsOther";
/// <summary>
/// Migrate all games from GOG plugin
/// </summary>
public const string GogOssMigrateGamesGog = "LOCGogOssMigrateGamesGog";
/// <summary>
/// Migrating all games from GOG plugin...
/// </summary>
public const string GogOssMigratingGamesGog = "LOCGogOssMigratingGamesGog";
/// <summary>
/// All games will be removed from GOG plugin and moved to GOG OSS. Are you sure you want to do this?
/// </summary>
public const string GogOssMigrationConfirm = "LOCGogOssMigrationConfirm";
/// <summary>
/// Updates for games from GOG are being downloaded.
/// </summary>
public const string GogOssGamesUpdatesUnderway = "LOCGogOssGamesUpdatesUnderway";
/// <summary>
/// Filter Active
/// </summary>
public const string GogOss3P_PlayniteFilterActiveLabel = "LOCGogOss3P_PlayniteFilterActiveLabel";
Expand Down

0 comments on commit 25b8597

Please sign in to comment.