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

0.24.0-beta-4 incorrectly handles plurals with " character; displays as \" on iOS and doesn't display on Android. #710

Closed
darronschall opened this issue May 16, 2024 · 2 comments · Fixed by #711
Assignees
Labels
bug Something isn't working
Milestone

Comments

@darronschall
Copy link
Contributor

darronschall commented May 16, 2024

Given this plural:

<plural name="search__results_for">
    <item quantity="zero">%d results for "%s"</item>
    <item quantity="one">%d result for "%s"</item>
    <item quantity="two">%d results for "%s"</item>
    <item quantity="few">%d results for "%s"</item>
    <item quantity="many">%d results for "%s"</item>
    <item quantity="other">%d results for "%s"</item>
</plural>

iOS

The iOS plural generation in Localizable.stringsdict generates as:

<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>%%d results for \"%%s\"</string>
<key>one</key>
<string>%%d result for \"%%s\"</string>
<key>two</key>
<string>%%d results for \"%%s\"</string>
<key>few</key>
<string>%%d results for \"%%s\"</string>
<key>many</key>
<string>%%d results for \"%%s\"</string>
<key>other</key>
<string>%%d results for \"%%s\"</string>

The quotes in those <string> elements should not be escaped. This is causing the string to show \" instead of just ":

Screenshot 2024-05-16 at 9 48 42 AM

Note that replacing the " with &quot; does not make a difference - the generated output is still \".

Android

For Android, the generated content in multiplatform_plurals.xml looks correct:

<plurals name="search__results_for">
    <item quantity="zero">%d results for &quot;%s&quot;</item>
    <item quantity="one">%d result for &quot;%s&quot;</item>
    <item quantity="two">%d results for &quot;%s&quot;</item>
    <item quantity="few">%d results for &quot;%s&quot;</item>
    <item quantity="many">%d results for &quot;%s&quot;</item>
    <item quantity="other">%d results for &quot;%s&quot;</item>
</plurals>

However, when using MR.plurals.search__results_for.format(0, 0, "Example"), the resulting string drops the quotes entirely:

Screenshot 2024-05-16 at 10 22 20 AM

Is this an Android issue somewhere inside PluralFormattedStringDesc?

@ExNDY
Copy link
Contributor

ExNDY commented May 17, 2024

Hm, i'm not sure in android plurals, because i'm try two variants in native:

<resources>
    <plurals name="android_res_test">
        <item quantity="zero">zero chars &quot;%s&quot;</item>
        <item quantity="one">%d char &quot;%s&quot;</item>
        <item quantity="two">%d chars &quot;%s&quot;</item>
        <item quantity="other">%d chars &quot;%s&quot;</item>
    </plurals>
</resources>

And:

<resources>
    <plurals name="android_res_test">
        <item quantity="zero">zero chars "%s"</item>
        <item quantity="one">%d char "%s"</item>
        <item quantity="two">%d chars "%s"</item>
        <item quantity="other">%d chars "%s"</item>
    </plurals>
</resources>

Call inside activity:

this.resources.getQuantityString(R.plurals.android_res_test, 2, 2,"Same")

For all variants i'm get string without quotes.
If i'm add mirror for quotes: like: \"%s\" or \&quot;%s\&quot; then i'm get quoting around Same.

start of my research on android: https://developer.android.com/guide/topics/resources/string-resource

And if i'm add mirror in plurals of moko-resource it will be fine for android, but other platform has incorrect mirror for quot. Thanks for info

@ExNDY ExNDY self-assigned this May 17, 2024
@ExNDY ExNDY added this to the 0.24.0 milestone May 17, 2024
@ExNDY ExNDY added the bug Something isn't working label May 17, 2024
ExNDY added a commit that referenced this issue May 17, 2024
ExNDY added a commit that referenced this issue May 17, 2024
@ExNDY ExNDY linked a pull request May 17, 2024 that will close this issue
ExNDY added a commit that referenced this issue May 17, 2024
@ExNDY
Copy link
Contributor

ExNDY commented May 17, 2024

will be fixed in 0.24.0-beta-5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants