Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docfx/articles/connectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ Example
ix_plc.PlcTranslator.Instance.SetLocalizationResource(typeof(myproject.ResourcesOverride.OverridePlcStringResources));
~~~

### Localization in a client in server-side application

In order to get translation in given culture for a client in a server side application you should use methods `Get{ProperyName}(CultureInfo culture)` to get translation for client current culture. The properties will returned original string where localization tokens are removed.

~~~csharp
var notTranlsated = obj.AttributeName;
var translated = obj.GetAttribute(new CultureInfo("sk-SK"));
~~~

### Setting connector's culture

In some instances it might be necessary to set the culture for the threads handling connectors. In that case use the following method to impose a specific culture.

~~~csharp
AXSharp.Connector.Connector.SetCulture(new CultureInfo("en-US"));
~~~

See also

[Dummy Connector](Dummy.md)
Expand Down
8 changes: 1 addition & 7 deletions docfx/articles/ixr/IXR.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ Ixr support all these special characters:
``!"#$'()*+,-.:;<=>?@[\]^_`{|}~€``
No other characters can be used.

## Localization in a client in server-side application

In order to get translation in given culture for a client in a server side application you should use methods `Get{ProperyName}(CultureInfo culture)` to get translation for client current culture. The properties will returned original string where localization tokens are removed.

~~~csharp
var notTranlsated = obj.AttributeName;
var translated = obj.GetAttribute(new CultureInfo("sk-SK"));
~~~
[See also](../connectors/README.md#controller-string-localization)

## Notes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using AXSharp.Connector.Identity;
using AXSharp.Connector.Localizations;
using AXSharp.Connector.ValueTypes;
Expand Down Expand Up @@ -378,6 +380,19 @@ internal void AddToNextPeriodicReadSet(ITwinPrimitive primitive)
NextPeriodicReadSet[primitive.Symbol] = primitive;
}

private static CultureInfo desiredCulture = CultureInfo.InvariantCulture;

/// <summary>
/// Sets the culture for this connector.
/// </summary>
/// <param name="culture">Desired culture</param>
public static void SetCulture(CultureInfo culture)
{
desiredCulture = culture;
}



/// <summary>
/// Starts cyclical read write operation on this connector.
/// </summary>
Expand All @@ -392,6 +407,14 @@ await Task.Run(async () =>
while (true)
if (!IsRwLoopSuspended)
{
if (desiredCulture.Name != CultureInfo.InvariantCulture.Name
&& (Thread.CurrentThread.CurrentUICulture.Name != desiredCulture.Name ||
Thread.CurrentThread.CurrentCulture.Name != desiredCulture.Name))
{
Thread.CurrentThread.CurrentUICulture = desiredCulture;
Thread.CurrentThread.CurrentCulture = desiredCulture;
}

await Task.Delay(ReadWriteCycleDelay);
sw.Restart();
try
Expand Down