-
Notifications
You must be signed in to change notification settings - Fork 35
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
Missing PO Entry when using String Concatenation (+
) or Referencing Text defined in const
/Field/Property/Variable
#87
Comments
+
) or Referencing Text defined Otherplace+
) or Referencing Text defined in Field/Property/const
+
) or Referencing Text defined in Field/Property/const
+
) or Referencing Text defined in const
/Field/Property/Variable
I have reproduced this with the current version on develop - the behavior is the same as the latest release 1.0.1 = the issue still exists. |
I will try to reproduce it |
@BrunoJuchli sorry for the delay on this, could you please write a unit test for each and push a PR for fixing those? |
@hishamco It would be really nice if you could release a new version, though. Since this would fix a few of the issues we experience with the tool, it would go a long way to convince the team. |
Please let me know if you need any support on the tool, it's my pleasure that the tool is already used by OC and hopefully other projects
Ya I will do ASAP |
I've figured out the code to extract the string from a string literal concatenation expression like: ["foo" + "bar" + "licious"] here's the code: public static bool IsStringLiteralExpression(
ExpressionSyntax expression,
[NotNullWhen(true)] out string? stringLiteralExpression)
{
if(GetLiteralExpressionValue(expression) is { } s)
{
stringLiteralExpression = s;
return true;
}
string concatenatedRights = string.Empty;
while(expression is BinaryExpressionSyntax binaryExpressionSyntax)
{
if (GetLiteralExpressionValue(binaryExpressionSyntax.Right) is not { } right)
{
break;
}
concatenatedRights = right + concatenatedRights;
if (GetLiteralExpressionValue(binaryExpressionSyntax.Left) is { } left)
{
stringLiteralExpression = left + concatenatedRights;
return true;
}
expression = binaryExpressionSyntax.Left;
}
stringLiteralExpression = null;
return false;
}
static string? GetLiteralExpressionValue(
ExpressionSyntax expression)
{
if(expression is LiteralExpressionSyntax literal &&
literal.IsKind(SyntaxKind.StringLiteralExpression))
{
return literal.Token.ValueText;
}
return null;
} I've tested this with 2, 5 and 6 concatenations. I'm not planning on creating a PR since we're not going to use POExtractor after all. |
As I said before you can skip the limitation of the variable names, check #92 |
yes, thanks, but as I said before, I don't like it - because it actually doesn't eliminate the limitation, it just broadens the list of possible values. Also, my solution respects the
In my environment I anticipate these downsides as having minimal impact. Feel free to close the issues I've reported. |
Repro Cases
String Concatenation
+
String Reference (Field/Property...)
Actual Behavior
extractpo
runs successfully, but the generated *.po file does not contain any entries for these calls.Expected (Desired) Behavior
Either one of the following would be fine for me:
Hey there how do you like this? I know it's not recommended
/This is my message
turns up in the PO file, respectively.S[...]
line as contextNote: for the string
+
-concatenation I would prefer if it would be supported. The reason is, that this is the only supported way how to break a long single-line string into multiple source code lines. All other approaches introduce new lines.Also note, that the
+
-concatenation is compiler optimized so that the compilation actually contains a single string -> in the compiled assembly there is no difference between"a" + "b"
and"ab"
! Something I've learned today :DThe text was updated successfully, but these errors were encountered: