I want to build an multi language ASP.NET MVC 2 website.
Let’s say I have the following sentences:
MyStrings.resx:
TestString : "This is my test"
MyStrings.de.resx:
TestString : "Dies ist mein Test"
MyStrings.fr.resx:
TestString : "C'est mon test"
Now on my site I want to make the words my/mein/mon in an other color. For example I want to asssign an other span class. What is the best/standard practice to do that?
How can I do that?
"This is <span class="x">my</span> test"string.Format: Resource:"This is {0}my{1} test", use:string.Format(Resources.TestString, "<span class=\"x\">", "</span">)."This is --my-- test", and write some extension method accepting a string, and replacing all--with the right tags.UPDATE
4. You can use custom format method. See code below.
Your resource could look like
Hello {firstname}, you still have {amount} {currency} in your bankaccount.You would “consume” this resource in the following way:As you can see, it is case insensitive, and you can mix in constants and variables. I made a custom translation web app, where I check if the translator uses all of the “variables” that are present in the original English string. That is quite an important check according to me.
Let me do add that this way is a bit controversial, since it uses reflection, but I find that the pros weigh heavier than the cons.