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.
right now we are not uploading to crowdin from android project but only downloading via crowdin as we are generating fresh set of strings.
its not just for plurals, but also for regulat strings that has multiple placeholers. we need this esp for non english transtions such as this
<string name="delete_account.remaining_and_scheduled_alert_v1">Vous avez %s carte-cadeau restante dans votre portefeuille et %s cartes-cadeaux prévues pour la livraison.</string>
would be great if you could guide me to any tutorials for pre/post processor module.
For handling strings with multiple placeholders, you can utilize the Custom Pre-Export and Post-Export Processors available on the Crowdin Store. These processors allow you to modify the strings before export or after import, which can be particularly useful for your use case.
Please note that on the export, by default, we return the same file (in terms of structure and syntax) that was uploaded as a source, so theoretically it might be needed to re-import the file using the importer modification so the source reflects the needed changes.