Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3401226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:59:22+00:00 2026-05-18T04:59:22+00:00

I want to build an multi language ASP.NET MVC 2 website. Let’s say I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:59:23+00:00Added an answer on May 18, 2026 at 4:59 am
    1. You could mix HTML into your resource: "This is <span class="x">my</span> test"
    2. You could use string.Format: Resource: "This is {0}my{1} test" , use: string.Format(Resources.TestString, "<span class=\"x\">", "</span">).
    3. You could use some custom formatting scheme: For example resource: "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:

    Resources.Bla.Bla.FormatWith(new { Firstname = SomeVariable, AMOUNT = 4, currency = "USD"  });
    

    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.

    public static string FormatWith(this string format, object source)
        {
            StringBuilder sbResult = new StringBuilder(format.Length);
            StringBuilder sbCurrentTerm = new StringBuilder();
            char[] formatChars = format.ToCharArray();
            bool inTerm = false;
            object currentPropValue = source;
    
            var sourceProps = source.GetType().GetProperties();
    
            for (int i = 0; i < format.Length; i++)
            {
                if (formatChars[i] == '{')
                    inTerm = true;
                else if (formatChars[i] == '}')
                {
                    PropertyInfo pi = sourceProps.First(sp=>sp.Name.Equals(sbCurrentTerm.ToString(), StringComparison.InvariantCultureIgnoreCase));
                    sbResult.Append((string)(pi.PropertyType.GetMethod("ToString", new Type[] { }).Invoke(pi.GetValue(currentPropValue, null) ?? string.Empty, null)));
                    sbCurrentTerm.Clear();
                    inTerm = false;
                    currentPropValue = source;
                }
                else if (inTerm)
                {
                    if (formatChars[i] == '.')
                    {
                        PropertyInfo pi = currentPropValue.GetType().GetProperty(sbCurrentTerm.ToString());
                        currentPropValue = pi.GetValue(source, null);
                        sbCurrentTerm.Clear();
                    }
                    else
                        sbCurrentTerm.Append(formatChars[i]);
                }
                else
                    sbResult.Append(formatChars[i]);
            }
            return sbResult.ToString();
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java multi-module Maven project that I want to build an MVN
I'm looking for a good solution for the following problem: I have a ASP.NET
I want to build a website that uses Flex/Flash as the GUI, and Java
I want to build a bot that basically does the following: Listens to the
As the title says, I want to have a build tool that quite much
is it possible to have a collation on a table? I build a multi
I have a multi-dimensional array similar to the example below that I want to
I'm going to build a multi-user website, much like wordpress.com, that users can signup
I am trying to build a notepad application. I want to have lines in
I want to build a multi tenent cloud app. My stack is javascript /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.