+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get All Languages

Get All Languages

5 posts, 2 answered
  1. Jared
    Jared avatar
    122 posts
    Registered:
    04 Apr 2013
    21 Oct 2013
    Link to this post
    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!
  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    24 Oct 2013
    Link to this post
    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
  3. Jared
    Jared avatar
    122 posts
    Registered:
    04 Apr 2013
    24 Oct 2013 in reply to Ivan D. Dimitrov
    Link to this post
    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".
  4. Jared
    Jared avatar
    122 posts
    Registered:
    04 Apr 2013
    24 Oct 2013 in reply to Jared
    Link to this post
    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>";
                }
    Answered
  5. Jared
    Jared avatar
    122 posts
    Registered:
    04 Apr 2013
    24 Oct 2013 in reply to Jared
    Link to this post
    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;"
    Answered
5 posts, 2 answered