ASP.NET website with multiple languages?

How can I convert a website to be able to handle several languages ​​(for example: English, French, Spanish)?

I do not like the resource file because I feel limited and it is rather difficult to create a list. Do you have any suggestions?

Update

So far, the best way we have found is to use an XML file and with some Xpath et get values.

+6
multilanguage
source share
7 answers

Implicit localization (in the menu "Visual Studio - Tools" - "Create local resources") is as simple as it can be. Write your pages in the default language, select the menu option, and your resource files are created and can be sent to someone for translation.

The resx file is just xml, so if the translation company wants it, you can easily convert it to and from spreadsheets.

Using databases instead of resx as backup storage is easy. Rick Strahl has a good explanation and sample code for a localization provider based on the database here - there is a good built-in localization editor with an interface for Google and Babelfish translations.

+9
source share

We store resources for multilingual sites in a database. We have created several tools that simplify their creation and access to them. There's a custom ExpressionBuilder that allows us to use this syntax:

<asp:linkbutton runat='server' text='<%$ LanguageStrings:ClickMe%>' /> 

And a custom shortcut containing the default text, and adds a row to the database, if it does not already exist.

  <r:languagelabel runat="server" name="AboutUs">About Us</r:languagelabel> 

A table containing rows contains one column for each language. This simplifies the creation of the site in English (or regardless of the default language), and then sends the table (which fills itself) to the translator. It is also very easy to see in which languages ​​you need to translate the material. With resources every time you need to add a new line, you need to stop what you are doing, and then go to the resource file for each language and add the resource.

Here is the code for the language label:

 ''' <summary> ''' Retrieves a language-specific string. ''' </summary> Public Class LanguageLabel Inherits Label Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private Sub Populate() If Len(Me.Name) > 0 Then Dim LanguageString As String = GetLanguageString(Me.Name, Me.Text) If Len(LanguageString) > 0 Then Me.Text = LanguageString End If End Sub Private Sub LanguageLabel_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender Populate() End Sub Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) ' By default a label wraps the text in a <span>, which we don't want in some situations writer.Write(Me.Text) End Sub End Class 

and utility function:

  Public Function GetLanguageString(ByVal Name As String, Optional ByVal DefaultText As String = "") As String Dim DefaultLanguage As Language = Languages.GetById(1) Name = StripPunctuation(Name).Trim.Replace(" ", "") ' Remove punctuation, spaces from name Dim SelectSql As String = String.Format("Select {0},{1} from LanguageStrings where Name=@Name ", Languages.CurrentLanguage.Code, DefaultLanguage.Code) Dim LanguageStringTable As DataTable = ExecuteDataset(cs, CommandType.Text, SelectSql, New SqlParameter("@Name", Name)).Tables(0) If LanguageStringTable IsNot Nothing AndAlso LanguageStringTable.Rows.Count > 0 Then Dim LanguageText As String = LanguageStringTable.Rows(0)(Languages.CurrentLanguage.Code).ToString Dim DefaultLanguageText As String = LanguageStringTable.Rows(0)(DefaultLanguage.Code).ToString If Len(LanguageText) > 0 Then ' We have a string in this language Return LanguageText Else ' Nothing in this language - return default language value Return DefaultLanguageText End If Else ' No record with this name - create a dummy one If DefaultText = "" Then DefaultText = Name Dim InsertSql As String = String.Format("Insert into LanguageStrings (Name, {0}) values (@Name, @Text)", DefaultLanguage.Code) ExecuteNonQuery(cs, CommandType.Text, InsertSql, New SqlParameter("@Name", Name), New SqlParameter("@Text", DefaultText)) Return Name End If End Function 
+6
source share

Resource files are the way to go. We ship our product in 12 languages. We pull all the lines into resource files and send them to the translation company. Sometimes it's a pain, but it's a de facto way to do it.

It also takes pleasure when 4-letter English words are translated into 17-letter phrases, and you need to customize your user interface.

+2
source share

How late are you in the design process? If it’s not too late, and if the budget allows, consider migrating to a multilingual CMS, for example Ektron CMS300.net (which has built-in translation tools). If not, then you have a huge task ahead.

+1
source share

Another solution I use is to create language folders containing aspx pages containing all the required texts in that particular language.

The only problem here is how you can inject as little code as possible into these replicated pages. To do this, I use the controller template and then the object's data source to get the data and bind it to the controls on all pages.

Thus, I have achieved the goal of disposing of resource files, and I can save the code in one place without replicating it (if necessary).

Edit: I would also recommend a good CMS structure.

0
source share

One of the web applications we developed also has this NLS requirement.

I found that there are at least 3 places where you have localized texts:

  • user interface
  • database tables ("directories" or whatever you want to name)
  • backend code (services, etc.)

My solution has one table for pages, tables, etc. ("Container"), one table for each item in this container (for example, labels, buttons by identifier, record identifiers) and one table for translated items (plus a language identifier).

The translation application helps me keep the translation up to date and export all translations to XML.

The product comes with translations, but customers can adjust translations, changes take effect immediately.

0
source share

Sample code I made using the resource file Add global.asax

  void Application_BeginRequest(Object sender, EventArgs e) { // Code that runs on application startup HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"]; if (cookie != null &amp;&amp; cookie.Value != null) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value); } else { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en"); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en"); } } 

http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html

http://satindersinght.wordpress.com/2012/06/14/create-website-for-multilanguage-support/

0
source share

All Articles