English 中文(简体)
C # 中本地化字符串中的新行
原标题:New Line in localization string in C#

我在C#.net和VS2010开发了一个网站。这个网站是本地化的,在整体上运作良好。然而,有些本地化字符串看起来并不理想。

例如,我在登录页面的顶端有一条信息

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.

我无法更改包含的 div 大小, 因为每个语言的宽度可能不同 。

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, , , and <br/> all appear in the string because it is rendered with " around the string.

是否有其他可行办法?这是否是一个坏主意?我们如何弥补多种语言之间的长期差异?

最佳回答

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>

做到这一点 :

<div class= whatever >@Html.Raw(Resources.MyString)</div>
问题回答

暂无回答




相关问题
.net Satellite assembly?

How can i create satellite assemblies in .net 3.5? I have a nativetext.resx file in english and want to create assemblies for french and italian in different folders like it --> nativetext.resources....

Access system:string resource dictionary XAML in C#

How do I access the contents in a resource dictionary using C#? For example, here is my code in XAML: <system:String x:Key="NewGroup">New Group Name</system:String> And I want to access ...

Localization in Prism WPF App

I m looking for the best way to localize a Prism 2 WPF app that might have several modules ported to Silverlight 3. Has anyone successfully localized a Prism 2 WPF app with several modules?

page content in multiple languages

I want to display content in more than one languages in a page. For example all menus are in English and content of post in local language (ie. Hindi). Contents on page are stored in database. For ...

Localization problem

I need to make a form that have to suport two languages (for now). the two languages dont have the same look and also half of the form is not a like but it still have some similiarity beetwen them. ...

determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

HOW TO MAKE localization?

I have a question about localization how can i do localization lets say that i have a dropdown list that holds the available languages: English,french and arabic and I have a label which get it says "...

热门标签