Skip to content

How to encode newlines? #818

Answered by kazupon
LifeIsStrange asked this question in Q&A
Dec 2, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

You can do this by changing the line breaks in the Translation component and locale messages to look like this:

locale messages (JSON resource):

{
  "oneline": "first line{newline}second line'"
}

Translation component:

      <i18n-t tag="p" keypath="oneline">
        <template #newline><br /></template>
      </i18n-t>

the break line in the resources of locale messages are not very desirable for localization and maintenance considerations.
I recommend defining "first line" and "second line" as separate keys in the locale resources and implementing them as follows:

locale messages (JSON resource):

{
  "first": "first line",
  "second": "second line'"
}
<p>{{ $t('first') }}<br />{{ $t('seco…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@LifeIsStrange
Comment options

@rvanlaak
Comment options

Answer selected by LifeIsStrange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants