Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to localize text in all my project depending on the User Chosen language
example
C#
MessageBox.Show($"Hello {User.Name} ,thanks For Joining");

i already set the translation into the resource files but i don't know what to do with {User.Name}
string1 value in resource file =Hello {User.Name} ,thanks For Joining

what i get Hello {User.Name} ,thanks For Joining

what i aim to Hello Jack ,thanks For Joining

thanks,

What I have tried:

C#
ResourceManager rm = new ResourceManager(typeof(Form4));
    MessageBox.Show(rm.GetString("String1"));
Posted
Updated 24-Jul-21 18:42pm

1 solution

You cannot use string interpolation in that way: interpolated strings are a syntactic sugar for the older method using numbered parameters and are evaluated when thw interpolated string is constructed, not when it is used:
C#
using System;

public class Program
	{
	static string name = "???";
	static string xxx = $"Hello {name}!";
	static string yyy = "Hello {0}!";
	public static void Main()
	{
		name = "Paul";
		Console.WriteLine($"Hello {name}!");
		Console.WriteLine(xxx);
		Console.WriteLine(yyy, name);
	}
}
Will give you:
Hello Paul!
Hello ???!
Hello Paul!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900