Condividi tramite


SPRegionalSettings.InstalledLanguages Property

Gets the collection of languages installed on Web servers in the farm.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property InstalledLanguages As SPLanguageCollection
    Get
'Usage
Dim instance As SPRegionalSettings
Dim value As SPLanguageCollection

value = instance.InstalledLanguages
public SPLanguageCollection InstalledLanguages { get; }

Property Value

Type: Microsoft.SharePoint.SPLanguageCollection
An SPLanguageCollection object that represents the installed languages.

Remarks

The first language that is installed in a farm is the SKU language — the language in which SharePoint Foundation 2010 is installed. You can discover the SKU language by accessing the static GlobalServerLanguage property. Other languages are added to the collection by language packs that farm administrators can install on the Web servers in the farm. For a list of the language packs that are available, see Language Packs for SharePoint Foundation 2010.

When languages are installed in the farm, they are not automatically enabled for use in the multilingual user interface for a given Web site. This must be done as a separate step by the site owner, who can access Site Settings page in the user interface, then the Language Settings page. In the Alternate language(s) group is a list of installed languages. A language is added to the multilingual user interface by checking the box next to its name. The same task can be accomplished by executing code that enumerates the collection of installed languages and enables support for each language by calling the AddSupportedUICulture(CultureInfo) method.

Examples

The following example is a console application that enumerates the installed languages and adds any that are currently not supported to the list of cultures supported by the multilingual user interface.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    web.IsMultilingual = true;

                    SPLanguageCollection installed = web.RegionalSettings.InstalledLanguages;
                    IEnumerable<CultureInfo> supported = web.SupportedUICultures;

                    foreach (SPLanguage language in installed)
                    {
                        CultureInfo culture = new CultureInfo(language.LCID);

                        if (!supported.Contains(culture))
                        {
                            Console.WriteLine("Adding {0}", culture.Name);
                            web.AddSupportedUICulture(culture);
                        }
                    }
                    web.Update();
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using site As New SPSite("https://localhost")
            Using web As SPWeb = site.OpenWeb()

                web.IsMultilingual = True

                Dim installed As SPLanguageCollection = web.RegionalSettings.InstalledLanguages
                Dim supported As IEnumerable(Of CultureInfo) = web.SupportedUICultures

                For Each language As SPLanguage In installed
                    Dim culture As New CultureInfo(language.LCID)

                    If Not supported.Contains(culture) Then
                        Console.WriteLine("Adding {0}", culture.Name)
                        web.AddSupportedUICulture(culture)
                    End If
                Next
                web.Update()

            End Using
        End Using
        Console.Write(vbCrLf + "Press ENTER to continue....")
        Console.Read()
    End Sub
End Module

See Also

Reference

SPRegionalSettings Class

SPRegionalSettings Members

Microsoft.SharePoint Namespace

SupportedUICultures