boss
boss

Reputation: 1606

New Line char in resource file in Xamarin.Android

I have a multi-lang app which retrieves the translations from strings.xml.

It was working correctly but after migration (maybe regarding VS 2019), \r\n becomes r\n and always I see an extra "r" char in my translated text because of missing backslash.

For example

<string name="general_checkforupdate_updateavailableOnGooglePlay_Message">
New version (v{0}) is available on Google Play.\r\nWould you like to update it now?</string>

and the code

 string message= string.Format(_activity.GetString(                                  
                 Resource.String.general_checkforupdate_updateavailableOnGooglePlay_Message),
                 newVersionInfo.Version);

I see the message like this

enter image description here

and when I read this part in debug

_activity.GetString(Resource.String.general_checkforupdate_updateavailableOnGooglePlay_Message)

I see the message is New version (v{0}) is available on Google Play.r\nWould you like to update it now?

As you see \ backslash character is deleted but for \n is OK. what can be the reason?

Upvotes: 1

Views: 563

Answers (2)

Leo Zhu
Leo Zhu

Reputation: 15001

In Android, users tend to put all of the string stored in the string. The XML, the purpose is convenient and unified management, and conducive to the internationalization, but direct input symbols in the string is no effect, such as Spaces, line breaks, is greater than, less than, etc., which requires the use of escape characters to transfer, such ability when use correctly display character.

you could refer to below :

Space:&#160; (normal English half space but not line break)

Narrow Space:&#8201;

&#12288; (full corner space (one Chinese width))

&#8194; (half Chinese width, but two Spaces are slightly larger than one Chinese)

&#8195; (one Chinese width, but slightly wider than Chinese)

\u3000\u3000 (first line indent)

\u3000 (full corner space (Chinese symbol))

\u0020 (half corner space (English symbol))

&#8230; (ellipsis)

so you could try to use &#160; or \u3000

Upvotes: 1

Kluddizz
Kluddizz

Reputation: 723

The \r does not work on all platforms / terminals in the same way. See Difference between \n and \r?. On your system it is replaced by r, because it might not support it.

Upvotes: 1

Related Questions