Programmatically set Alternate languages

I’m using variations again. But this time the backend has to be multilingual too.
So I have to set up the alternate languages.

Since I want to help my users when they set up a new site, I’m using the code below in combination with a WebProvisioned event receiver.

        /// <summary>
        /// Activates all language packs that are installed on SP2010
        /// </summary>
        /// <param name="properties"></param>
        private void SetAlternateLanguages(SPWebEventProperties properties)
        {
            try
            {
                SPWeb web = properties.Web;
                SPWebTemplateCollection templates = properties.Web.Site.GetWebTemplates(web.Language);
                SPWebTemplate template = templates[web.WebTemplate];
                if (template.SupportsMultilingualUI)
                {
                    web.IsMultilingual = true;
                    SPLanguageCollection installed = SPRegionalSettings.GlobalInstalledLanguages;
                    IEnumerable<CultureInfo> supported = web.SupportedUICultures;
                    foreach (SPLanguage language in installed)
                    {
                        CultureInfo culture = new CultureInfo(language.LCID);
                        if (!supported.Contains(culture))
                        {
                            web.AddSupportedUICulture(culture);
                        }
                    }
                    web.OverwriteTranslationsOnChange = true;
                    web.Update();
                }
            }
            catch (Exception ex)
            {
                //Log the error
            }
        }



Of course has MSD more information about this subject.

Reacties

Populaire posts