moko-resources
moko-resources copied to clipboard
0.24.0-beta-4 incorrectly handles plurals with `"` character; displays as `\"` on iOS and doesn't display on Android.
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 ":
Note that replacing the " with " 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 "%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>
</plurals>
However, when using MR.plurals.search__results_for.format(0, 0, "Example"), the resulting string drops the quotes entirely:
Is this an Android issue somewhere inside PluralFormattedStringDesc?
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 "%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>
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 \"%s\" 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
will be fixed in 0.24.0-beta-5