Skip to content

Commit

Permalink
85 Add LocalizedAttribute to LocalizedText LocaleIds (#89)
Browse files Browse the repository at this point in the history
* Address Comments on Description and DisplayName

* Added LocalizedAttribute

* Apply LocalizedAttribute to Value LocaleIds
  • Loading branch information
Archie-Miller authored Jan 24, 2025
1 parent f1a1318 commit 46e8072
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
38 changes: 22 additions & 16 deletions NodeSetToAML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,25 +606,24 @@ private void BuildLocalizedTextAttribute(
{
if( localizedTexts != null )
{
CAEXObject findObject = m_cAEXDocument.FindByPath(
"AutomationMLBaseAttributeTypeLib/LocalizedAttribute" );
AttributeFamilyType localizedAttributeFamilyType = findObject as AttributeFamilyType;

if( localizedTexts.Length > 1 )
{
AddModifyAttribute( seq, attributeName, "LocalizedText", localizedTexts[ 0 ].Value );

AttributeType displayNameAttribute = seq[ attributeName ];
if( displayNameAttribute != null )
AttributeType root = AddModifyAttribute( seq, attributeName,
"LocalizedText", localizedTexts[ 0 ].Value ); ;
if( root != null )
{
string previousLocaleId = string.Empty;
string defaultLocaleId = GetLocaleId( localizedTexts[ 0 ], ref previousLocaleId );
AttributeType arrayRoot = AddModifyAttribute( displayNameAttribute.Attribute, defaultLocaleId, "String",
localizedTexts[ 0 ].Value );

// Redo first element
previousLocaleId = string.Empty;
for( int index = 0; index < localizedTexts.Length; index++ )
{
string localeId = GetLocaleId( localizedTexts[ index ], ref previousLocaleId );
AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId,
"String", localizedTexts[ index ].Value );
NodeSet.LocalizedText localizedText = localizedTexts[ index ];
string localeId = GetLocaleId( localizedText, ref previousLocaleId );
AttributeType textAttribute = root.Attribute.Append( localeId );
textAttribute.RecreateAttributeInstance( localizedAttributeFamilyType );
textAttribute.Value = localizedText.Value;
}
}
}
Expand All @@ -638,7 +637,9 @@ private void BuildLocalizedTextAttribute(

if( !String.IsNullOrEmpty( localizedText.Locale ) )
{
AddModifyAttribute( root.Attribute, localizedText.Locale, "LocalizedText", localizedText.Value );
AttributeType textAttribute = root.Attribute.Append( localizedText.Locale );
textAttribute.RecreateAttributeInstance( localizedAttributeFamilyType );
textAttribute.Value = localizedText.Value;
}
}
}
Expand Down Expand Up @@ -986,8 +987,13 @@ private AttributeType AddModifyAttribute(AttributeSequence seq, string name, str
a.DefaultAttributeValue = a.AttributeValue = localizedText.Text;
if ( !string.IsNullOrEmpty( localizedText.Locale ) )
{
AddModifyAttribute(a.Attribute, localizedText.Locale,
"String", localizedText.Text);
CAEXObject findObject = m_cAEXDocument.FindByPath(
"AutomationMLBaseAttributeTypeLib/LocalizedAttribute" );
AttributeFamilyType localizedAttributeFamilyType =
findObject as AttributeFamilyType;
AttributeType textAttribute = a.Attribute.Append( localizedText.Locale );
textAttribute.RecreateAttributeInstance( localizedAttributeFamilyType );
textAttribute.Value = localizedText.Text;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Opc2Aml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<ItemGroup>
<PackageReference Include="Aml.Engine" Version="3.1.1" />
<PackageReference Include="Aml.Engine.Resources" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.5.374.158" />
</ItemGroup>

Expand Down
5 changes: 2 additions & 3 deletions SystemTest/TestLocalizedText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,11 @@ public void MultipleLocalizedText( string nodeId, string attributeName, string[]
{
SystemUnitClassType objectToTest = GetTestObject( nodeId );
AttributeType topLevel = ValidateAttribute( objectToTest.Attribute, attributeName, text[ 0 ] );
AttributeType textLevel = ValidateAttribute( topLevel.Attribute, localeId[0], text[ 0 ] );

for( int index = 0; index < localeId.Length; index++ )
{
string subLocale = "aml-lang=" + localeId[ index ];
ValidateAttribute( textLevel.Attribute, subLocale, text[index] );
string subLocale = localeId[ index ];
ValidateAttribute( topLevel.Attribute, subLocale, text[index] );
}
}

Expand Down

0 comments on commit 46e8072

Please sign in to comment.