I am currently experimenting with localization using resource files (resx).
I've already got it to work, but now i am in the next phase. How do i get a list of available languages?
By 'scanning?' for resx files or something like this:
|
I've searched the web for a answer but couldn't find a answer.
I think this should be pretty easy but well.. I'm new ;).
Thank you!
Kirtan PatelPosted Aug 16, 2009, 1:24 AM
Code Will Scan resource Files you have and List languages As below Image
string[] list = Directory.GetFiles(Server.MapPath("App_LocalResources"));
foreach (string str in list)
{
Regex regex = new Regex("[a-zA-Z-]*.resx");
string language = regex.Match(str).ToString().Replace(".resx",String.Empty);
if (language == "aspx")
{
language = CultureInfo.CurrentCulture.NativeName;
DropDownList1.Items.Add(language);
}
else
{
language = CultureInfo.GetCultureInfo(language).NativeName;
DropDownList1.Items.Add(language);
}
}
Dominique de GraaffPosted Aug 16, 2009, 1:36 AM
Dominique de GraaffPosted Aug 16, 2009, 12:55 AM
I have 5 resource files:
/Languages/Resources.resx
/Languages/Resources.de.resx
/Languages/Resources.es.resx
/Languages/Resources.fr.resx
/Languages/Resources.nl.resx
(English, German, Spanish, French, Dutch)
From here i want to 'scan' what languages (from these resource files) are available so i can put them in a array and display them to the user for selecting. After releasing my program, people should be able to add more languages. The program will scan for new languages and make them selectable from a list.
So, i don't want AllCultures, but only the cultures i have a resource file for.
Kirtan PatelPosted Aug 16, 2009, 12:35 AM
,Friend Here is Code For That
private void button1_Click(object sender, EventArgs e)
{
//Get All Culture in Culture info Array
CultureInfo[] AllCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
//Iterate Trough Each and Add in ListBox
foreach (CultureInfo c in AllCultures)
{
//Add to List Box
listBox1.Items.Add(c.Name);
/*
if you want Full LanguageName Use below
listBox1.Items.Add(c.NativeName);
*/
}
}