Skip to content

Commit

Permalink
Merge pull request #48 from AndrewKeepCoding/support-target-dp-in-uid
Browse files Browse the repository at this point in the history
Support target DependencyProperty in Uids.Uid
  • Loading branch information
AndrewKeepCoding authored Sep 13, 2024
2 parents b8fc0a9 + 31bba1b commit 42cad4d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
3 changes: 1 addition & 2 deletions WinUI3Localizer.SampleApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</Grid>
<!-- Shell -->
Expand Down
2 changes: 1 addition & 1 deletion WinUI3Localizer.SampleApp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<data name="MainPage" xml:space="preserve">
<value>Main</value>
</data>
<data name="MainWindow_AppTitleBar.Text" xml:space="preserve">
<data name="MainWindow_AppTitleBar" xml:space="preserve">
<value>WinUI3Localizer Sample App😎</value>
</data>
<data name="MainWindow_en-US.Text" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion WinUI3Localizer.SampleApp/Strings/es-ES/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<data name="MainPage" xml:space="preserve">
<value>Principal</value>
</data>
<data name="MainWindow_AppTitleBar.Text" xml:space="preserve">
<data name="MainWindow_AppTitleBar" xml:space="preserve">
<value>WinUI3Localizer App de Muestra😎</value>
</data>
<data name="MainWindow_en-US.Text" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion WinUI3Localizer.SampleApp/Strings/ja/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<data name="MainPage" xml:space="preserve">
<value>メイン</value>
</data>
<data name="MainWindow_AppTitleBar.Text" xml:space="preserve">
<data name="MainWindow_AppTitleBar" xml:space="preserve">
<value>WinUI3Localizer サンプルアプリ 😎</value>
</data>
<data name="MainWindow_en-US.Text" xml:space="preserve">
Expand Down
20 changes: 9 additions & 11 deletions WinUI3Localizer.SampleApp/WinUI3Localizer.SampleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
Expand All @@ -17,6 +17,7 @@
<WindowsPackageType>None</WindowsPackageType>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
-->
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -43,26 +44,23 @@

<ItemGroup>
<PackageReference Include="ColorCode.WinUI" Version="2.0.15" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.1" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240829007" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="WinUI3Localizer" Version="2.3.0-alpha" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WinUI3Localizer\WinUI3Localizer.csproj" />
</ItemGroup>

<!-- Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging Tools extension
to be activated for this project even if the Windows App SDK Nuget package has not yet been restored -->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
Expand Down
38 changes: 28 additions & 10 deletions WinUI3Localizer/Localizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion WinUI3Localizer/WinUI3Localizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- You/users can add new languages even after deployment
- Use standard Resources.resw
</Description>
<Version>2.2.0</Version>
<Version>2.3.0-alpha</Version>
<PackageTags>winui3;winappsdk;localization;localize;language;multilanguage</PackageTags>
<PackageProjectUrl>https://github.com/AndrewKeepCoding/WinUI3Localizer</PackageProjectUrl>
<RepositoryUrl>https://github.com/AndrewKeepCoding/WinUI3Localizer</RepositoryUrl>
Expand Down

0 comments on commit 42cad4d

Please sign in to comment.