Access alternate languages of an item

Version: 10.4

Each item can contain multiple languages. You can use the Sitecore.Globalization.Language class to specify a language when accessing an item using the Sitecore.Data.Database.GetItem() method. For example, to access the current version of the /Sitecore/Content/Home item in the default en language:

RequestResponse
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse("en");

Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home",language);
Note

If you do not specify a language, Sitecore uses the context language by default. Sitecore user interface components specify the content language.

You can use the Sitecore.Data.Items.Item.Versions.Count property to determine if any versions exist for a language. For example, to access the current version in each language of the /Sitecore/Content/Home item in the Master database:

RequestResponse
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home");

foreach (Sitecore.Globalization.Language language in home.Languages)
{
    Sitecore.Data.Items.Item langItem = home.Database.GetItem(home.ID, language);
    
    if (langItem.Versions.Count > 0)
    {
        // Process language item
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,