Hi,
how can we implement positional arguments like %1$s, %2$s for android strings? We are using [%s] in crowdin and its being parsed into You have %s gift card which is ok but not recommended for android. Android recommends the placeholder as %1$s to avoid grammar issue.
In French, the sentence structure might require the amount to appear before the name. Using %s does not allow reordering.
Here is an example:
source string in crowdin: [%s] has [%s] gift cards left.
parsed strings.xml
<string name="example_message">%s has %s gift cards left.</string>
code:
val message = getString(R.string.example_message, "John", "5")
println(message) // Output: John has 5 gift cards left.
French Translation: In French, the structure might require the number to appear first: <string name="example_message">%s cartes-cadeaux restent à %s.</string>
If %s is used, the arguments cannot be reordered programmatically, resulting in:
val message = getString(R.string.example_message, "John", "5")
println(message) // Incorrect Output: John cartes-cadeaux restent à 5.
Using %1$s and %2$s allows translators to reorder placeholders: <string name="example_message">%2$s cartes-cadeaux restent à %1$s.</string>
val message = getString(R.string.example_message, "John", "5")
println(message) // Output: 5 cartes-cadeaux restent à John.
how can this problem be resolved? any info would be helpful.
Thank you for reaching out. To implement positional arguments like %1$s and %2$s for Android strings in Crowdin, you can use the “Convert placeholders to target file format” option in the Android XML Exporter settings under Project settings → Parser configuration. This should convert the placeholders appropriately for your Android strings.
If you need further assistance or have any other questions, please feel free to contact us.
I’d love to see some tutorials, because I tried setting [%s] in the source string but esp.. when i export to android and ios, its not parsed properly. or i dont get any option to set positional placeholers.
checking and unclicking the toggle for placeholder didnt satisfy my requirement or may be i’m missing something here.