B3nedikt / restring

Restring is a android library to replace string resources dynamically
Apache License 2.0
317 stars 31 forks source link

How can I translate \n into new lines instead of display it as text? #113

Closed abinop closed 2 years ago

abinop commented 2 years ago

I am using the latest restring (5.2.1), and the putStrings method to load strings. However, when the strings contain a new line \n character it loads it as text. I've looked at one other mention in a past issue, but it is not clear to me what I need to do in order to load it as expected. Can you please clarify?

PS. Thank you for the library, it's working great in all other aspects.

B3nedikt commented 2 years ago

In short the easiest way to use formatting is using Spanned, like this:

HtmlCompat.fromHtml("A string with a  \n in it", HtmlCompat.FROM_HTML_MODE_COMPACT)

In general Restring works with CharSequence, so any formatted String, Editable, Spannable etc. is rendered as it is, to be consistent with normal android resources behaviour. The StringRepository does persist these strings as HTML by default, so you can use all formatting ways, you can also use in your strings.xml.

Glad you like my library :)