1

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?

ertan2002
  • 1,458
  • 1
  • 32
  • 68

2 Answers2

1

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.

Kluddizz
  • 703
  • 3
  • 8
  • but it was working.. If you were right, it would not work in the beginning. It is somehow related with new VS or maybe xamarin framework. Thank you for your reply – ertan2002 Mar 16 '20 at 12:55
  • 1
    You can try to use ` ` instead of `\r` and ` ` instead of `\n`. – Kluddizz Mar 16 '20 at 15:34
1

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

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23