![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all. I am writing an application that will allow the user to change cultures at runtime. I've found info on how to do that and I think I'm good there. I'd like to provide the user a menu (or something similar) that lists the available cultures to choose from. It's simple to just add these in statically at build time (or have an external data file). But I'd much rather prefer that there was some way to detect what languages are available to the application (or to a given Form; it makes no difference to me). That way as we add new languages we don't have to change the program or extra data files. I've looked through the MSDN documentation and tried several things, with no success. I've searched on the web and not had any luck either. Is this possible? Even a routine that would just enumerate what satellite assemblies were available (again, for the application or just a single Form is fine) would be good. Anyone know how to do this or have any tips on where to look? Thanks! Carl |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Excellent, thank you! It's unfortunate that we have to cycle through them all (not to mention it takes a few seconds). I did have to add this to the code ("cultures" is a generic list of CultureInfos): catch (FileNotFoundException) { // Swallow this exception, it means no such resources exist for the given language // But... if the CurrentUICulture is not found, it means we // are using the default culture, and we need to add it to the list. if (ci.Equals(Thread.CurrentThread.CurrentUICulture)) cultures.Add(ci); } ... since my default culture is geared for en-US, and I don't have specific en-US resources. Perhaps this is not "best practice", I'm not sure (new to .NET). Unfortunately, if the code is run on a machine whose CurrentUICulture isn't en-US and isn't represented by a satellite assembly, the machine's current culture will be incorrectly added as the default culture. I'm not sure how to get around this issue (other than making blank en-US resources, which I'm not too hot on). Thanks again! Carl |
#5
| |||
| |||
|
|
Well, since you are looking for your app's languages rather than the .NET Framework's, you would change the code that gets the assembly from the .NET Framework itself to something that gets your own assembly! |
#6
| |||
| |||
|
|
I think I have that: Assembly assembly = Assembly.GetExecutingAssembly(); .... I use that in place of the line that accessed the mscorlib assembly. But I'm not sure if this will solve the problem... if someone is running our app on, say, a machine with the Finnish culture installed, and we haven't localized for this culture, then this: if (ci.Equals(Thread.CurrentThread.CurrentUICulture)) cultures.Add(ci); .... will return true when ci is the Finnish culture, and add Finnish to the cultures list. When what I really want is it to take account of the special case of adding the "default" culture (in this case, en-US). I could hard code for this I suppose, but it would break if the default culture was anything but en-US. Perhaps this will never be the case and is "good enough". Carl Michael (michka) Kaplan [MS] wrote: Well, since you are looking for your app's languages rather than the .NET Framework's, you would change the code that gets the assembly from the .NET Framework itself to something that gets your own assembly! |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |