共用方式為


SPWeb.ExportUserResources method

匯出使用者指定之語言的資源。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Sub ExportUserResources ( _
    language As CultureInfo, _
    allResources As Boolean, _
    outputFile As Stream _
)
'用途
Dim instance As SPWeb
Dim language As CultureInfo
Dim allResources As Boolean
Dim outputFile As Stream

instance.ExportUserResources(language, _
    allResources, outputFile)
public void ExportUserResources(
    CultureInfo language,
    bool allResources,
    Stream outputFile
)

參數

  • allResources
    Type: System.Boolean

    true包含所有使用者指定的文字,包括已經翻譯 ; 的文字false包含未轉譯的文字。

Exceptions

Exception Condition
InvalidOperationException

沒有替代語言會在網站上啟用。

InvalidOperationException

指定的語言不是其中一個已安裝的語言。

InvalidOperationException

網站不支援的語言。

備註

使用者資源會寫入指定的資料流中。Resx 檔案格式。如需詳細資訊,請參閱資源中。Resx 檔案格式。尚未轉譯成語言參數所指定語言的文字是在網站的預設語言。UICulture屬性會傳回站台的預設語言。

注意

匯出的轉譯網頁在使用者介面背後的程式碼會呼叫ExportUserResources方法。不過, allResources參數所暗示的邏輯會完全相反的結果的使用者介面,提供要只匯出的文字,不會轉譯選項所隱含的邏輯。如果您選擇 [],頁面程式碼會傳遞falseallResources參數中。如果您選擇 [] 時,網頁程式碼會傳遞trueallResources參數中。

這個方法會匯出使用者資源會在網站中包含而不是只是資源的網站清單的資源。您可以呼叫ExportUserResources方法,來為每個站台、 所支援的語言建立資源檔,然後為檔案提供給可以翻譯字串,其所包含的任何人。這項工作完成時,您可以呼叫ImportUserResources方法,以匯入轉譯,讓它們可以多語系使用者介面。

Examples

下列範例會列舉網站所支援的語言是主控台應用程式,並將匯出的每一種語言未轉譯的資源。

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    // Get the default language for the website.
                    int lcid = (int)web.Language;
                    CultureInfo defaultCulture = new CultureInfo(lcid);

                    // Export resources for all alternate languages supported by the website.
                    if (web.IsMultilingual)
                    {
                        string resxFileName;

                        IEnumerable<CultureInfo> cultures = web.SupportedUICultures;
                        foreach (CultureInfo culture in cultures)
                        {
                            if (culture.LCID == defaultCulture.LCID)
                                continue;
                            // Export only untranslated resources.
                            resxFileName = WriteResourceFile(web, culture.LCID, true);
                            Console.WriteLine("Resources for {0} exported to {1}.", culture.Name, resxFileName);
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }

        static string WriteResourceFile(SPWeb web, int lcid, bool onlyUntranslated)
        {
            CultureInfo ci = new CultureInfo(lcid);

            string fileName = web.Title + "." + ci.Name + ".resx";
            char[] invalidChars = Path.GetInvalidFileNameChars();
            foreach (char c in invalidChars)
            {
                fileName.Replace(c, '_');
            }

            FileStream fs = File.Create(fileName);
            web.ExportUserResources(ci, !onlyUntranslated, fs);
            fs.Close();
            
            return fileName;
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.IO
Imports Microsoft.SharePoint

Module ConsoleApp

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

                ' Get the default language for the website
                Dim lcid As Integer = CInt(web.Language)
                Dim defaultCulture As New CultureInfo(lcid)

                ' Export resources for all alternate languages supported by the website.
                If web.IsMultilingual Then
                    Dim resxFileName As String

                    Dim cultures As IEnumerable(Of CultureInfo) = web.SupportedUICultures
                    For Each culture As CultureInfo In cultures
                        If culture.LCID = defaultCulture.LCID Then
                            Continue For
                        End If
                        ' Export only untranslated resources.
                        resxFileName = WriteResourceFile(web, culture.LCID, True)
                        Console.WriteLine("Resources for {0} exported to {1}.", culture.Name, resxFileName)
                    Next
                End If

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

    Function WriteResourceFile(ByVal web As SPWeb, ByVal lcid As Integer, ByVal onlyUntranslated As Boolean) As String
        Dim ci As New CultureInfo(lcid)

        Dim fileName As String = web.Title + "." + ci.Name + ".resx"
        Dim invalidChars As Char() = Path.GetInvalidFileNameChars()
        For Each c As Char In invalidChars
            fileName.Replace(c, "_"c)
        Next

        Dim fs As FileStream = File.Create(fileName)
        web.ExportUserResources(ci, Not onlyUntranslated, fs)
        fs.Close()

        Return fileName
    End Function

End Module

請參閱

參照

SPWeb class

SPWeb members

Microsoft.SharePoint namespace

ImportUserResources(CultureInfo, Stream)

SPList.UserResources

SPWeb.UserResources