From 77ac64ad5e3778db3f10ddc4764a3c462aad525a Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 13 Sep 2024 13:49:07 +0900 Subject: [PATCH 1/5] Add support for target DependencyProperty in Uids.Uid For example: ``` ``` --- WinUI3Localizer/Localizer.cs | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/WinUI3Localizer/Localizer.cs b/WinUI3Localizer/Localizer.cs index 44e3d8e..b8422eb 100644 --- a/WinUI3Localizer/Localizer.cs +++ b/WinUI3Localizer/Localizer.cs @@ -294,27 +294,45 @@ private async Task LocalizeDependencyObjects() private void LocalizeDependencyObject(DependencyObject dependencyObject) { - if (Uids.GetUid(dependencyObject) is string uid && - CurrentDictionary.TryGetItems(uid, out LanguageDictionary.Items? items) is true) + if (Uids.GetUid(dependencyObject) is not string uidSource || + string.IsNullOrEmpty(uidSource) is true) { - foreach (LanguageDictionary.Item item in items) - { - LocalizeDependencyObject(dependencyObject, item); - } + Logger.LogWarning("DependencyObject does not have Uid. [Type: {Type}]", dependencyObject.GetType()); + return; + } + + string uid = uidSource; + string? uidDependencyPropertyName = null; + + if (uidSource.Split('.') is { Length: 2 } splitResult) + { + uid = splitResult[0]; + uidDependencyPropertyName = splitResult[1] + "Property"; + } + + if (CurrentDictionary.TryGetItems(uid, out LanguageDictionary.Items? items) is false) + { + Logger.LogWarning("DependencyObject does not have Uid in the dictionary. [Type: {Type} Uid: {Uid}]", dependencyObject.GetType(), uid); + return; + } + + foreach (LanguageDictionary.Item item in items) + { + LocalizeDependencyObject(dependencyObject, uidDependencyPropertyName ?? item.DependencyPropertyName, item.Value); } } - private void LocalizeDependencyObject(DependencyObject dependencyObject, LanguageDictionary.Item item) + private void LocalizeDependencyObject(DependencyObject dependencyObject, string dependencyPropertyName, string value) { if (GetDependencyProperty( dependencyObject, - item.DependencyPropertyName) is DependencyProperty dependencyProperty) + dependencyPropertyName) is DependencyProperty dependencyProperty) { - LocalizeDependencyObjectsWithDependencyProperty(dependencyObject, dependencyProperty, item.Value); + LocalizeDependencyObjectsWithDependencyProperty(dependencyObject, dependencyProperty, value); return; } - LocalizeDependencyObjectsWithoutDependencyProperty(dependencyObject, item.Value); + LocalizeDependencyObjectsWithoutDependencyProperty(dependencyObject, value); } private void LocalizeDependencyObjectsWithDependencyProperty(DependencyObject dependencyObject, DependencyProperty dependencyProperty, string value) From 8db74632d748910298339fedb727d7c3e70070fd Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 13 Sep 2024 13:52:32 +0900 Subject: [PATCH 2/5] Update version --- WinUI3Localizer/WinUI3Localizer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinUI3Localizer/WinUI3Localizer.csproj b/WinUI3Localizer/WinUI3Localizer.csproj index 9f79113..c844951 100644 --- a/WinUI3Localizer/WinUI3Localizer.csproj +++ b/WinUI3Localizer/WinUI3Localizer.csproj @@ -17,7 +17,7 @@ - You/users can add new languages even after deployment - Use standard Resources.resw - 2.2.0 + 2.3.0 winui3;winappsdk;localization;localize;language;multilanguage https://github.com/AndrewKeepCoding/WinUI3Localizer https://github.com/AndrewKeepCoding/WinUI3Localizer From ebc8b1859253f8a981234b84cee54afd14229ed2 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 13 Sep 2024 14:03:31 +0900 Subject: [PATCH 3/5] Use the new DependencyProperty in Uids.Uid in the sample app titlebar --- WinUI3Localizer.SampleApp/MainWindow.xaml | 3 +-- WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw | 2 +- WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw | 2 +- WinUI3Localizer.SampleApp/Strings/ja/Resources.resw | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/WinUI3Localizer.SampleApp/MainWindow.xaml b/WinUI3Localizer.SampleApp/MainWindow.xaml index f921fb2..b550b09 100644 --- a/WinUI3Localizer.SampleApp/MainWindow.xaml +++ b/WinUI3Localizer.SampleApp/MainWindow.xaml @@ -25,9 +25,8 @@ Grid.Column="1" Margin="8,0,0,0" VerticalAlignment="Center" - l:Uids.Uid="MainWindow_AppTitleBar" + l:Uids.Uid="MainWindow_AppTitleBar.Text" FontSize="12" - Text="WinUI 3 Localizer" TextWrapping="NoWrap" /> diff --git a/WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw b/WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw index db7526e..fc08318 100644 --- a/WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw +++ b/WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw @@ -216,7 +216,7 @@ Main - + WinUI3Localizer Sample App😎 diff --git a/WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw b/WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw index 8da698c..49a8169 100644 --- a/WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw +++ b/WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw @@ -216,7 +216,7 @@ Principal - + WinUI3Localizer App de Muestra😎 diff --git a/WinUI3Localizer.SampleApp/Strings/ja/Resources.resw b/WinUI3Localizer.SampleApp/Strings/ja/Resources.resw index 74485c2..2b4bdea 100644 --- a/WinUI3Localizer.SampleApp/Strings/ja/Resources.resw +++ b/WinUI3Localizer.SampleApp/Strings/ja/Resources.resw @@ -216,7 +216,7 @@ メイン - + WinUI3Localizer サンプルアプリ 😎 From 0d49cc0f691a40d5c7f171fa5c3d7e62ab397bd2 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 13 Sep 2024 14:20:03 +0900 Subject: [PATCH 4/5] Set the version as 'alpha' --- WinUI3Localizer/WinUI3Localizer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinUI3Localizer/WinUI3Localizer.csproj b/WinUI3Localizer/WinUI3Localizer.csproj index c844951..6197063 100644 --- a/WinUI3Localizer/WinUI3Localizer.csproj +++ b/WinUI3Localizer/WinUI3Localizer.csproj @@ -17,7 +17,7 @@ - You/users can add new languages even after deployment - Use standard Resources.resw - 2.3.0 + 2.3.0-alpha winui3;winappsdk;localization;localize;language;multilanguage https://github.com/AndrewKeepCoding/WinUI3Localizer https://github.com/AndrewKeepCoding/WinUI3Localizer From 31bba1bd8a880ebdc0ab612e36652d99b592b66f Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 13 Sep 2024 14:39:04 +0900 Subject: [PATCH 5/5] Update sample app NuGet packages --- .../WinUI3Localizer.SampleApp.csproj | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/WinUI3Localizer.SampleApp/WinUI3Localizer.SampleApp.csproj b/WinUI3Localizer.SampleApp/WinUI3Localizer.SampleApp.csproj index 928b849..bebf534 100644 --- a/WinUI3Localizer.SampleApp/WinUI3Localizer.SampleApp.csproj +++ b/WinUI3Localizer.SampleApp/WinUI3Localizer.SampleApp.csproj @@ -1,4 +1,4 @@ - + WinExe net8.0-windows10.0.19041.0 @@ -17,6 +17,7 @@ None true --> + 10.0.19041.38 @@ -43,26 +44,23 @@ - + - - - + + + - - + + + - - - -