Get All Languages

Posted by Community Admin on 04-Aug-2018 20:18

Get All Languages

All Replies

Posted by Community Admin on 21-Oct-2013 00:00

We are utilizing 15 different languages for our site.  I am attempting to get all languages for some current functionality that I have which needs done for all languages.  I need to get all languages then do a "foreach" on each language.  Any help would be greatly appreciated!

Posted by Community Admin on 24-Oct-2013 00:00

Hi Jared,

 In order to get all of the cultures of a certain object you first need to know all of the cultures you have. Please see the code below for further reference:

NewsManager manager = NewsManager.GetManager();
            var items = manager.GetNewsItems();  
 
            foreach (var item in items)
            
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
                var title = item.GetValue("Title");
 
                Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
                var title = item.GetValue("Title");
 
 
            
It gets the titles of all English and French news items. Regards,
Ivan D. Dimitrov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 24-Oct-2013 00:00

I know all the languages, but I do not want to hard code the languages.  Is there a way to get all the languages?  I want to GetAllLanguages, then for each language "do something".

Posted by Community Admin on 24-Oct-2013 00:00

I resolved my issue and here is what I did:

CultureInfo[] languages = SystemManager.CurrentContext.AppSettings.DefinedBackendLanguages;

This got all the languages and here is what I did to see the results:

            foreach (var language in languages)
           
                resultLanguages.Text += language.ToString() + "<br>";
           

Posted by Community Admin on 24-Oct-2013 00:00

I was wrong above as I pasted the incorrect code.

Instead of "CultureInfo[] languages = SystemManager.CurrentContext.AppSettings.DefinedBackendLanguages;"

I meant "CultureInfo[] languages = SystemManager.CurrentContext.AppSettings.DefinedFrontendLanguages;"

This thread is closed