0

I have a site developed in C#.net and VS2010. It is is localized and works well overall. However, some of the localization strings don't look the best.

For example, I have a message at the top of the login page

Currently it appears like this:
Your session has expired. Please login to
continue.

I would like it to appear like this:
Your session has expired.
Please login to continue.

I can't change the size of the containing div because the width could be different for each language.

I am looking for a way to put layout capabilities in the localization file. The simplest approach (on the surface) is to put new line characters in the string. However, \n, \r\n, and <br/> all appear in the string because it is rendered with " around the string.

Is there another approach that will work? Is this a bad idea? How else can we compensate for length differences accross the many languages?

davids
  • 5,397
  • 12
  • 57
  • 94
  • If nothing else, have you considered splitting the text into two strings? – Babak Naffas May 24 '12 at 22:23
  • I have considered it, but would prefer not. There are many situations where this is an issue and trying to translate tightly connected, but distinct strings could become a nightmare. Also, other languages may have a great way to convey the full concept in one line. Conversely, another language may need three lines to convey the same concept in a visually pleasing format. – davids May 24 '12 at 22:29
  • See http://stackoverflow.com/questions/931114/carriage-return-line-feed-in-net-resource-file-app-globalresources – Babak Naffas May 24 '12 at 23:10

1 Answers1

1

The best approach in this case is to use HTML formatting in your string (both in English and in your translation) and where necessary adjust the translation. There is no reason why you could not include <br /> in your string and have it rendered as intended. I don't know if you are using WebForms or ASP.NET MVC, but in the case of MVC you can avoid the default behaviour (automatic HTML encoding of your string) by using the Html.Raw helper, for example instead of this:

<div class='whatever'>@Resources.MyString</div>

Do this:

<div class='whatever'>@Html.Raw(Resources.MyString)</div>
Clafou
  • 15,250
  • 7
  • 58
  • 89