LOCALIZED STRINGS FORMATTING

Hey guys,

I am unable to find a way to format strings with placeholders from localized .strings files.

For example, in Android I can define a string with placeholder in strings.xml:

<string name="app_name">My App's name is %s</strings>

and then in the code I format the string like this:

`String appName = "My App"

String finalString = context.getString(R.string.app_name, appName)`

so the finalString is: My App's name is My App.

How to get this in iOS with Xamarin and C#?

Best Answer

Answers

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited September 2016

    IMHO, even if it were possible to do that in .strings file, that would not be a good idea. REASON: It adds the risk that one of the translated versions would accidentally garble that formatting. Strings files are, and should be, purely pairs of strings: key string + value in a given language.

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited September 2016

    Cancel my previous comment. I see a situation where different grammar (word order) of different languages makes it challenging to adapt correctly without having a placeholder [in my case, a person's name] that can be moved to a different location in the sentence, per language. Without that, have to manually instruct the person translating what the complete sentence is, then give keys to the two parts of the sentence (before and after the placeholder). The translator has to provide a translation for the sentence as a whole, and then break it into the before and after pieces - even though the translation of each piece is not what it would be by itself (one word moved from after to before). Rather than rely on translator to do that correctly, provided a sentence with an example name, let them translate, then had the coder break the sentence down. So it is a more cumbersome process - can't just hand the strings file to translator, then double-check the result to make sure the key-value formatting hasn't been messed up. Extra manual step per language.

Sign In or Register to comment.