Skip to content

Commit f342e1c

Browse files
committed
Enhance localization support by updating SetLocalizationResource method to accept target assembly and improving label retrieval for culture awareness
1 parent f77a00c commit f342e1c

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/Templates/TemplateBase.razor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ protected override Task OnInitializedAsync()
120120
/// <returns></returns>
121121
protected string GetLabel()
122122
{
123-
return Onliner.GetAttributeName(CultureInfo.CurrentUICulture) + (string.IsNullOrWhiteSpace(Onliner.AttributeUnits) ? null : $" [{Onliner.AttributeUnits}]");
123+
var retVal = Onliner.GetAttributeName(CultureInfo.CurrentUICulture) + (string.IsNullOrWhiteSpace(Onliner.AttributeUnits) ? null : $" [{Onliner.AttributeUnits}]");
124+
return retVal;
124125
}
125126
}
126127
}

src/AXSharp.compiler/src/ixc/Properties/launchSettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"commandName": "Project",
6666
"commandLineArgs": "--skip-deps",
6767
"workingDirectory": "c:\\W\\Develop\\gh\\inxton\\simatic-ax\\ppppppsjsjsjs\\MTS258585\\ax\\"
68+
},
69+
"axopen-traversal-in-tepmplates": {
70+
"commandName": "Project",
71+
"workingDirectory": "C:\\W\\Develop\\gh\\inxton\\simatic-ax\\axopen.templates\\axopen\\src\\traversals\\apax"
6872
}
6973
}
7074
}

src/AXSharp.connectors/src/AXSharp.Connector/Localizations/Translator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public string Translate(string originalString, ITwinElement twin, CultureInfo cu
5252
/// Sets the localization resource for this translator.
5353
/// </summary>
5454
/// <param name="resourceType">Type of resource to be used.</param>
55-
public void SetLocalizationResource(Type resourceType)
55+
/// <param name="targetAssembly"></param>
56+
public void SetLocalizationResource(Type resourceType, Assembly targetAssembly = null)
5657
{
5758
if (resourceType != null)
5859
{
@@ -61,6 +62,10 @@ public void SetLocalizationResource(Type resourceType)
6162
IgnoreCase = true
6263
};
6364
}
65+
else
66+
{
67+
Console.WriteLine($"No resource type provided for `{targetAssembly?.FullName}`");
68+
}
6469
}
6570

6671
internal static IEnumerable<string> GetTranslatable(string input,

src/AXSharp.connectors/tests/AXSharp.ConnectorTests/AXSharp.ConnectorTests/Localizations/TranslatorExtensionTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace AXSharp.ConnectorTests.Localizations
99
using Xunit;
1010
using NSubstitute;
1111
using AXSharp.Connector;
12+
using System.Reflection;
1213

1314
public static class TranslatorExtensionTests
1415
{
@@ -33,7 +34,7 @@ public static void Translate_localized_string_keep_default_translation()
3334
// Arrange
3435
var twin = Substitute.For<ITwinElement>();
3536
var interpreter = new Translator();
36-
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary));
37+
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary), Assembly.GetExecutingAssembly());
3738
twin.Interpreter.Returns(interpreter);
3839
var originalString = "<#In the middle of the night#>";
3940

@@ -70,7 +71,7 @@ public static void Translate_partially_localized_string_translate_to_sk()
7071
// Arrange
7172
var twin = Substitute.For<ITwinElement>();
7273
var interpreter = new Translator();
73-
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary));
74+
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary), Assembly.GetExecutingAssembly());
7475
twin.Interpreter.Returns(interpreter);
7576
var originalString = "(A4)<#In the middle of the night#> 1.5";
7677
var expected = "(A4)Uprostred noci 1.5";
@@ -110,7 +111,7 @@ public static void Translate_partially_localized_inexisting_translation()
110111
// Arrange
111112
var twin = Substitute.For<ITwinElement>();
112113
var interpreter = new Translator();
113-
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary));
114+
interpreter.SetLocalizationResource(typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary), Assembly.GetExecutingAssembly());
114115
twin.Interpreter.Returns(interpreter);
115116
var originalString = "(A4)<#In the middle of the night does not exist#> 1.5";
116117

src/AXSharp.connectors/tests/AXSharp.ConnectorTests/AXSharp.ConnectorTests/Localizations/TranslatorTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
namespace AXSharp.ConnectorTests.Localizations
22
{
3+
using AXSharp.Connector;
34
using AXSharp.Connector.Localizations;
5+
using AXSharp.ConnectorTests.Localizations.Resources;
6+
using NSubstitute;
47
using System;
58
using System.Globalization;
9+
using System.Reflection;
610
using Xunit;
7-
using NSubstitute;
8-
using AXSharp.Connector;
9-
using AXSharp.ConnectorTests.Localizations.Resources;
1011

1112
public class TranslatorTests
1213
{
@@ -54,7 +55,7 @@ public void CanCallSetLocalizationResource()
5455
var resourceType = typeof(AXSharp.ConnectorTests.Localizations.Resources.Dictionary);
5556

5657
// Act
57-
_testClass.SetLocalizationResource(resourceType);
58+
_testClass.SetLocalizationResource(resourceType, Assembly.GetExecutingAssembly());
5859
}
5960

6061
[Fact]
@@ -80,7 +81,7 @@ public void Translate_falls_back_to_library_resource_when_primary_does_not_have_
8081
// Arrange
8182
Translator.SetPrimaryTranslatorResource(typeof(OverrideApplication));
8283
var translator = new Translator();
83-
translator.SetLocalizationResource(typeof(OverrideLibrary));
84+
translator.SetLocalizationResource(typeof(OverrideLibrary), Assembly.GetExecutingAssembly());
8485
var twin = Substitute.For<ITwinElement>();
8586
var originalString = "<#Library only#>";
8687

0 commit comments

Comments
 (0)