Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC: Localized texts with new line?

I've an Asp.Net MVC 3 website, which will be localized.

I've several resx files which contains my texts, and I've in my views some

@My.NameSpace.Through.My.LocalizationFile.Key

But I can't make it represent the new line.

I tried:

  • Shift+enter: I've got the new line in the resource file, but not in my browser
  • \r\n : I see the \r\n in my browser
  • \n : Same
  • <br/> : I see the <br/> in my text

So what should I do to have a new line?

Edit: I know that I could use Html.Raw, but I just can't ask to translators to put html code in their translation.

like image 407
J4N Avatar asked Apr 11 '12 14:04

J4N


People also ask

How do you insert a line break in resources?

Use Shift + Enter to insert a new line. Save this answer. Show activity on this post.

What is IStringLocalizer?

IStringLocalizer uses the ResourceManager and ResourceReader to provide culture-specific resources at run time. The interface has an indexer and an IEnumerable for returning localized strings. IStringLocalizer doesn't require storing the default language strings in a resource file.

What is Globalisation and Localisation in asp net?

Globalization is the process of designing the application in such a way that it can be used by users from across the globe (multiple cultures). Localization, on the other hand, is the process of customization to make our application behave as per the current culture and locale.


2 Answers

To be honest, I know it's not the nicest thing in the world, but it's fool-proof and it means your translators don't have to put any code in their translations:

Building upon the answers already given, why don't you just use Html.Raw, but before doing so, replacing the \r\n that using Shift+Enter in the resource file results in, with a <br />

So say for example you had the string named Welcome in the resource file ApplicationMessage, you could do:

@Html.Raw(ApplicationMessage.Welcome.Replace("\r\n", "<br />")

That will give you what you need. Here's a similar question:

HTMLencode HTMLdecode

like image 147
mattytommo Avatar answered Sep 24 '22 02:09

mattytommo


You can put the <br /> for the line breaks and use the @Html.Raw() method to show the string with the line break instead of the <br /> string.

like image 41
Scorpion-Prince Avatar answered Sep 24 '22 02:09

Scorpion-Prince