I want to make my application which supports all the languages based on the resx file. If not resx file is available it has to take the default language from the display language set in the control panel. How can I do this? Which is the best way to do it?
Asked
Active
Viewed 355 times
-1
-
1Note that resx files only exist at design-time. During compilation they're embedded within your program's assembly file or as "satellite assemblies". – Dai Jun 12 '14 at 06:25
-
@Dai - How are these string.en-US.resx defers from string.en-us.resources and string.en-us.txt? – roopini n Jun 12 '14 at 06:37
2 Answers
0
You can't.
The default language in the control panel is the language that is going to be used automatically (unless you change the UI culture).
However, what do you expect the application to do if the default windows language cannot be found?
You have to create a resource file which do not have the language suffix (just yourResource.resx
and not yourResource.fi.resx
). The resource files without the prefix will be used if the chosen language is not found.

jgauffin
- 99,844
- 45
- 235
- 372
-
the default language should be English. And also yourResource.resx is this automatically takes the language based on the culture which is not set? – roopini n Jun 12 '14 at 06:34
-
yourResource.resx is chosen if the resource file for the current culture can not be found. For instance if `en-US` is the current culture and neither `yourResource.en-US.resx` or `yourResource.en.resx` is found then `yourResource.resx` will be used. – jgauffin Jun 12 '14 at 06:36
-
ok I got it now.. thanks for the help. Can I use these resources as shared resources? How can I do this? – roopini n Jun 12 '14 at 06:40
-
1Put all resx files in separate class libraries and reference them in other projects. – jgauffin Jun 12 '14 at 06:51
-
You can set `Thread.CurrentThread.CurrentUICulture` to force-use a specific resource language. – Dai Jun 12 '14 at 20:07
0
Can't we do like this:
using System.Xml.Linq;
class ExternalRMStrings
{
public static bool allAtOnce = true;
//static string path = @"C:\WOI\Code\VC Days are here again\Ode to Duty\WinForms\Globalization\MultiLingual\MultiLingual\Resource_Hindi.resx";
//@"d:\Resources.resx";
static string path = @"C:\WOI\Code\VC Days are here again\Ode to Duty\WinForms\Globalization\MultiLingual\MultiLingual\Properties\Resources.resx";
static XElement xelement = XElement.Load(path);
static IEnumerable<XElement> employees = null;
static Dictionary<string, string> dicOfLocalizedStrings = new Dictionary<string, string>();
static void LoadAllAtOnce()
{
if (employees == null) employees = xelement.Elements();
employees.Where(e => e.Name == "data").Select(x => x).All(xele =>
{
dicOfLocalizedStrings[xele.Attribute("name").Value] = xele.Element("value").Value;
return true;
});
}
public static string GetString(string key)
{
if (employees == null) employees = xelement.Elements();
if (allAtOnce) LoadAllAtOnce();
try
{
string sibla = null;
if (dicOfLocalizedStrings.TryGetValue(key, out sibla)) return sibla;
sibla = employees.Where(e => e.Name == "data" && e.Attribute("name").Value == key).Select(x => x.Element("value").Value).FirstOrDefault();
dicOfLocalizedStrings[key] = sibla;
return sibla;
}
catch
{
return null;
}
}
}
Useage
ExternalRMStrings.GetString("MyKey");

Dr.sai
- 285
- 3
- 4