银河网投[网址]www.308877.com-官网首页

您的位置:银河网投 > www.308877.com > SharePoint2013与SharePoint2016语言切换原理以及如何使

SharePoint2013与SharePoint2016语言切换原理以及如何使

2019-10-10 17:24

1、前言

在SharePoint 二零零六版本,在首页面直接"选用展现语言"的美食指南(如下图所示),如下图 :

图片 1

在sharepoint二〇一一和sharepoint二〇一六并不是那样。

  1. 那边首先需求设置语言包,SharePoint二〇一六语言包下载地址:

https://www.microsoft.com/en-us/download/details.aspx?id=51492

SharePoint二〇一二语言包下载地址:

https://www.microsoft.com/zh-cn/download/details.aspx?id=37140

 

留心:下载安装完成后都要开展重新配置

 

  1. 在【网址设置】-【语言设置】设置备用语言,这里为克罗地亚(Croatia)语,如下图
    图片 2

     

    图片 3

  2. 扩充【关于小编】进行【语言区域安装】如下图:

![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212943985-1659030794.png)

 

![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212944422-432151143.png)

 

![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212945532-1904207329.png)

 

2、原理

上边提及SharePoint2008的言语切换依照记录cookie的方法得以十分的快进展切换,只要记录cookie的值lcid值,对于SharePoint贰零壹贰和SharePoint二零一五的言语应用此形式非常,依据IE语言版本来明确彰显哪个语言?,由此我们那边运用Fiddler工具进行http头文件的收获剖析,首要深入分析:Accept-Language

说明:

Accept-Language:浏览器所企望的语言种类,当服务器能够提供一种以上的言语版本时要用到;遵照http头的动静,用代码修改Accept-Language的装置来模拟设置语言版本的切换

  1. 作者们开采塞尔维亚(Република Србија)语站点: 用Fiddler抓取深入分析,如下图:

    图片 4

    浅析结果:

![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212946860-1533374866.png)
  1. 我们开荒汉语站点:(切换后)的Fiddler抓取图,如下图:
![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212948047-376480886.png)

既然知道那一个规律,切换代码把每便要切换的言语版本保存到cookie值里,那么我们首先次系统用代码切换前cookie值为空设置二个默以为华语,使用httpModule形式来剖判http头的Accept-Language的值,就算带有en-US就设置为意国语版本,假如含有zh-CN就安装为华语。理解原理写代码就有帮助多了。

3、代码

  1. HttpModule.cs源码如下:

       

using System;

using System.Web;

using System.Web.UI;

using Microsoft.SharePoint;

using System.Threading;

using Microsoft.SharePoint.Utilities;



namespace CSSharePointLangSwitcher.LangSwitcherPage

{

public class HTTPSwitcherModule : IHttpModule

{

/// <summary>

/// You will need to configure this module in the web.config file of your

/// web and register it with IIS before being able to use it. For more information

/// see the following link: http://go.microsoft.com/?linkid=8101007

/// </summary>

#region IHttpModule Members



public void Dispose()

{

//clean-up code here.

}



/// <summary>

/// Init event

/// </summary>

/// <param name="context"></param>

public void Init(HttpApplication context)

{

// Below is an example of how you can handle Request event and provide

// custom logging implementation for it

context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;

}



#endregion



/// <summary>

/// Assuming the selected language is stored in a cookie. Firstly, get the selected

/// language from cookie. Then add the selected language to the request header.

/// Finally, use the selected language for the current culture.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

void context_PreRequestHandlerExecute(object sender, EventArgs e)

{

// Get current application.

HttpApplication httpApp = sender as HttpApplication;



// Get all HTTP-specific information about current HTTP request.

HttpContext context = httpApp.Context;



// Current language.

string strLanguage = string.Empty;



// The key of current selected language in the cookies.

string strKeyName = "LangSwitcher_Setting";



try

{

// Set the current language.

if (httpApp.Request.Cookies[strKeyName] != null)

{

strLanguage = httpApp.Request.Cookies[strKeyName].Value;

}

else

{

strLanguage = "zh-cn";

}



var lang = context.Request.Headers["Accept-Language"];

if (lang != null)

{

if (!lang.Contains(strLanguage))

context.Request.Headers["Accept-Language"] = strLanguage + "," + context.Request.Headers["Accept-Language"];



var culture = new System.Globalization.CultureInfo(strLanguage);



// Apply the culture.

SPUtility.SetThreadCulture(culture, culture);

}

}

catch (Exception ex)

{

System.Diagnostics.Debug.WriteLine(ex.Message);

}

}

}

}

 

 

 

  1. 切换代码如下:

    /// <summary>
    
    /// Save current selected language to cookie.
    
    /// </summary>
    
    /// <param name="sender"></param>
    
    /// <param name="e"></param>
    
    protected void btnSave_Click(object sender, EventArgs e)
    
    {
    
    if (ddlLanguages.SelectedIndex > 0)
    
    {
    
    // Selected language.
    
    string strLanguage = ddlLanguages.SelectedValue;
    
    // Set the Cookies.

    HttpCookie acookie = new HttpCookie(strKeyName);

    acookie.Value = strLanguage;

    acookie.Expires = DateTime.MaxValue;

    Response.Cookies.Add(acookie);



    Response.Redirect(Request.RawUrl);

    }

    }

 

4、效果

  1. 测量试验切换效果,先测量试验切换到中文,如下:

图片 5

切换后,大家访谈下 为华语效果,如下图:

图片 6

  1. 测量检验切换效果,先测验切换来日语,如下:

图片 7

切换后,我们访谈下 为葡萄牙语效果,如下图:

图片 8

源码能够去自个儿QQ群下载:203613636 谢谢

 

本文由银河网投发布于www.308877.com,转载请注明出处:SharePoint2013与SharePoint2016语言切换原理以及如何使

关键词: