SPUtility.GetLocalizedString method
Retrieves the value for a named resource string from the resource file for a specified language.
Namespace: Microsoft.SharePoint.Utilities
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public Shared Function GetLocalizedString ( _
source As String, _
defaultResourceFile As String, _
language As UInteger _
) As String
'Usage
Dim source As String
Dim defaultResourceFile As String
Dim language As UInteger
Dim returnValue As String
returnValue = SPUtility.GetLocalizedString(source, _
defaultResourceFile, language)
public static string GetLocalizedString(
string source,
string defaultResourceFile,
uint language
)
Parameters
source
Type: System.StringAn ASP.NET resource expression in the form $Resources:keyname, where keyname is the name half of a name/value pair in a resource file (.resx).
defaultResourceFile
Type: System.StringThe base file name of the language resource file containing a localized string value. For example, if you have a series of resource files named myresources.en-us.resx, myresources.es-es.resx, myresources.de-de.resx, and so on, the value to pass in this parameter is myresources.
language
Type: System.UInt32The LCID of the target language. For a list, see the overview topic for the CultureInfo class.
Return value
Type: System.String
The string value for the specified language. If a value cannot be found in the requested language, the value for the invariant language is returned. If a resource file for the invariant language does not exist or the specified resource name does not exist, the source string is returned without localization.
Remarks
This method can retrieve a string value from a resource file located in the Resources folder that is just below the SharePoint Foundation installation root. The token that Visual Studio uses for this folder is {SharePointRoot}\Resources. The full path is %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\Resources.
Examples
The following example is a console application that enumerates the languages supported by a Web site. For each language, the application gets the value for the resource named "onet_TeamSite" from the resource file with the base file name "core".
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.RootWeb)
{
if (web.IsMultilingual)
{
IEnumerable<CultureInfo> cultures = web.SupportedUICultures;
foreach (CultureInfo culture in cultures)
{
// Print the value of a language resource in the current language.
string str = "$Resources:onet_TeamWebSite";
string locStr = SPUtility.GetLocalizedString(str, "core", (uint)culture.LCID);
Console.WriteLine("{0} {1}", culture.Name, locStr);
}
}
}
}
Console.Write("\nPress ENTER to continue....");
Console.ReadLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Module ConsoleApp
Sub Main()
Using site As New SPSite("https://localhost")
Using web As SPWeb = site.RootWeb
Dim cultures As IEnumerable(Of CultureInfo) = web.SupportedUICultures
For Each culture As CultureInfo In cultures
' Print the value of a language resource in the current language.
Dim str As String = "$Resources:onet_TeamWebSite"
Dim locStr As String = SPUtility.GetLocalizedString(str, "core", CUInt(culture.LCID))
Console.WriteLine("{0} {1}", culture.Name, locStr)
Next
End Using
End Using
Console.Write(vbCrLf & "Press ENTER to continue....")
Console.Read()
End Sub
End Module
See also
Reference
Microsoft.SharePoint.Utilities namespace
Other resources
Understanding the Multilingual User Interface (MUI)
Walkthrough: Localizing the User Interface for Custom Columns, Content Types, and Lists