put new line in string to translate

前端 未结 3 1794
小蘑菇
小蘑菇 2021-02-19 05:24

I\'m using ngx-translate.

How can I put a line break in a string to translate ?

In my template I have :

{{\'STRING_TO_TRANSLATE\' | translate}}
         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 06:06

    You can use \n but you will have to provide some styling.

    So in your template use this:

    {{'STRING_TO_TRANSLATE' | translate}}

    Your en.json:

    {
    "STRING_TO_TRANSLATE": "text on first line.\nText on second line"
    }
    

    Your (s)CSS file:

    .my-translated-paragraph{
        white-space: pre-wrap;
    }
    

    More info an the magic behind white-space: https://stackoverflow.com/a/42354356/3757110

    See also a github Issue about this: https://github.com/angular-translate/angular-translate/issues/595

提交回复
热议问题