Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two resource key for single label .Net

For making an existing site to multilingual, I follow globalization technique, I have created 3 resource files for different content like label & header text file, grid header text file etc... Now I have two keys in different resource files i.e Email and Message, at a third place I want to show both these keyword together i.e Email message. Do I need to create third key or I can concatenate already existing keys. Currently I am using below two codes

For showing directly on page:
HttpContext.GetGlobalResourceObject("ResourceLabelButton", "Email")

For showing as text of any control like Textbox, label:
Text ="<%$ Resources:ResourceContent, Email %>"

I can concatenate two resource string on .cs page but it will increase timeline, so please suggest so I can only change on .aspx pages.

Thanks in advance

like image 926
Tarun Mathur Avatar asked Dec 18 '13 06:12

Tarun Mathur


2 Answers

ASP.NET tag attribute values that use <%$ Something: Something Else %> are of a special syntax called ASP.NET Expressions. Using them as attribute values are pretty much all-or-nothing; there's no way to add any code into the ASPX file to manipulate what those expressions evaluate to. You'll have to do this in the code-behind.

like image 150
Arjun Sharma Avatar answered Sep 21 '22 20:09

Arjun Sharma


You should create a separate resource entry for "Email Message" instead of concatenating "Email" and "Message". To understand why, look at Spanish:

  • Email = Correo electrónico
  • Message = Mensaje

Simple concatenation gives you Correo electrónico Mensaje. This is wrong. The correct translation is:

  • Email Message = Mensaje de correo electrónico

Notice that in the translation, the order of "Email" and "Message" has been reversed, and a new word (de, which means "of") has been inserted between them.

On the other hand, look at the translations for "New Message" and "Last Message":

  • New Message = Mensaje nuevo
  • Last Message = Último mensaje

As you can see, there are complex rules that govern when to reverse the order of words and when to insert de. These rules, of course, are different in other languages.

So in general, you should never concatenate localized words or phrases to form a longer phrase.
Always provide a separate resource entry for every phrase.

like image 41
Michael Liu Avatar answered Sep 22 '22 20:09

Michael Liu