0

I have the resources.resx in my c# code with some strings filled:

Text1,"Some Text" 

and i can call it during running time by

Properties.Resources.Text1

which results in

"Some Text"

Now i want to have Text1 a different output (another language for example or something) so that Properties.Resources.Text1 results in "Different Text".

How can i achieve this?

EDIT1: i discovered this but i was looking for a different approach with the resource files.

Community
  • 1
  • 1
Gobliins
  • 3,848
  • 16
  • 67
  • 122

2 Answers2

1

I am afraid you have to add another resource file for other culture. just look into this thread How to use localization in C#

In reference to a comment: get the current cultureinfo and load resources like this:

Thread.CurrentThread.CurrentCulture.ClearCachedData();
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
if(currentCulture.Name == "en-US")
   Console.WriteLine(resources.Text1);
else if if(currentCulture.Name == "ja-JP")
   Console.WriteLine(resourcesJapan.Text1);
Community
  • 1
  • 1
Talha
  • 18,898
  • 8
  • 49
  • 66
  • i could add another resource file that was my intention, but how can i tell the code to use the other resource file – Gobliins Feb 01 '13 at 10:24
  • rm = new ResourceManager(typeof(Resource1)); was the thing i was looking for. But thx anyways – Gobliins Feb 01 '13 at 11:44
1

If you want to use different Resource Files, you can use the ResourceManager:

ResourceManager rm;
if (Configuration.Default.Culture == "en-US")
    rm = new ResourceManager(typeof(Resource1));
else
    // ...
String label = rm.GetString("Text1");

Save the the Culture in the User Settings, add a configuration file and define a user variable.

Configuration.Default.Culture= "en-US";
Configuration.Default.Save();

Updated question according to information

efkah
  • 1,628
  • 16
  • 30
  • well that could work, but i was hoping to have at programm startup load a different ressource file or something like that – Gobliins Feb 01 '13 at 10:22
  • if you have different resource files, you could use the resourcemanager. i might be wrong though: http://msdn.microsoft.com/de-de/library/yfsz7ac5.aspx – efkah Feb 01 '13 at 10:25
  • the name you chose in the add file wizard when you added your resx file, assuming that you are already using the namespace – efkah Feb 01 '13 at 10:54
  • Ah thx, i misspelled the whole time in my code and wondered. Now it works. – Gobliins Feb 01 '13 at 10:59