Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW-FEATURE] When an added property of string contains localization attributes it should use translator #97

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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ public override void Init(AstContext context, ParseTreeNode treeNode)

public override void AcceptVisitor(IAstVisitor visitor)
{
if (visitor is PragmaVisitor v) v.Product = $"{AccessQualifier} {Type} {Identifier} {{ get; set; }}";
if (visitor is PragmaVisitor v)
{
if (Type.ToUpperInvariant() == "STRING")
{
v.Product = $"private {Type} _{Identifier};" +
$"\n{AccessQualifier} {Type} {Identifier} " +
$"{{ " +
$"get" +
$"{{ " +
$"return Ix.Localizations.LocalizationHelper.CleanUpLocalizationTokens(_{Identifier}); " +
$"}} " +
$"set; " +
$"{{_{Identifier} = value;" +
$"}} " +
$"}}";
}
else
{
v.Product = $"{AccessQualifier} {Type} {Identifier} {{ get; set; }}";
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override void Init(AstContext context, ParseTreeNode treeNode)

public override void AcceptVisitor(IAstVisitor visitor)
{

if (visitor is PragmaVisitor v)
v.Product = MemberName != null
? $"{MemberName}.{PropertyName} = {InitValue};"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Ix.Compiler.Cs.Pragmas.PragmaParser;

internal class DeclarationAttributeAstNode : AstNode
internal class AttributeDeclarationAstNode : AstNode
{
public string? AttributeLiteral { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class PragmaGrammar : Grammar
public readonly NonTerminal AddedPropertySetter = new(nameof(AddedPropertySetter), typeof(AddedPropertySetterAstNode));
public readonly Terminal assing = new(nameof(assing));

public readonly NonTerminal DeclarationAttribute = new(nameof(DeclarationAttribute), typeof(DeclarationAttributeAstNode));
public readonly NonTerminal DeclarationAttribute = new(nameof(DeclarationAttribute), typeof(AttributeDeclarationAstNode));
public readonly NonTerminal ClrAttribute = new(nameof(ClrAttribute));

public readonly FreeTextLiteral ClrAttributeContent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void should_get_attribute_source()
[Fact]
public void should_declare_property()
{
var expected = "public string AttributeName { get; set; }";
var expected = "private string _AttributeName;\npublic string AttributeName { get{ return Ix.Localizations.LocalizationHelper.CleanUpLocalizationTokens(_AttributeName); } set; {_AttributeName = value;} }";
var field = new TypeMock("someField",
new ReadOnlyCollection<IPragma>(new IPragma[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,19 @@ public Ix.Connector.ITwinObject GetParent()

public partial class NoAccessModifierClass : Ix.Connector.ITwinObject
{
public string AttributeName { get; set; }
private string _AttributeName;
public string AttributeName
{
get
{
return Ix.Localizations.LocalizationHelper.CleanUpLocalizationTokens(_AttributeName);
}

set;
{
_AttributeName = value;
}
}

public OnlinerString SomeClassVariable { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ namespace TypesWithPropertyAttributes
{
public partial class SomeAddedProperties : Ix.Connector.ITwinObject
{
public string Description { get; set; }
private string _Description;
public string Description
{
get
{
return Ix.Localizations.LocalizationHelper.CleanUpLocalizationTokens(_Description);
}

set;
{
_Description = value;
}
}

public OnlinerInt Counter { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal static IEnumerable<LocalizableItem> GetTranslatable(string input,
return localizables;
}

internal static string CleanUpLocalizationTokens(string localized)
public static string CleanUpLocalizationTokens(this string localized)
{
if (localized != null) return localized.Replace("<#", string.Empty).Replace("#>", string.Empty);

Expand Down