语言SharePoint2013与SharePoint2016言语切换原理以及哪些采纳代码举行语言切换

因此把要加载的文件作为一个“功能”而不是一个文本,require对于用Ruby编写的扩大和用C语言编写的恢弘都用同一的办法。其余,.rb增添名的公文与其他扩充名为.so、.dll或.bundle的文件使用形式也是一模一样的。需要留意的是,require不可以识别出如今的劳作目录(.)。用户可以显式地指定它,例如:require
“./loadee.rb”或者可以运用数组添加运算符“<<”把当前目录添加到加载路径中:$:
<<
“.”。这样就不用在调用require的时候显式地指定工作目录了。也得以给require指定完全限定的途径,和使用load一样,把公文或者功效加载进来。

1、前言

在SharePoint
2010本子,在首页面直接”拔取呈现语言”的菜单(如下图所示),如下图 :

语言 1

在sharepoint2013和sharepoint2016并非如此。

  1. 此间首先需要安装语言包,SharePoint2016语言包下载地址:

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

SharePoint2013语言包下载地址:

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

 

瞩目:下载安装完毕后都要进行重新配置

 

  1. 在【网站设置】-【语言设置】设置备用语言,这里为英语,如下图
    语言 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、原理

下面说到SharePoint2010的语言切换依照记录cookie的主意得以很快拓展切换,只要记录cookie的值lcid值,对于SharePoint2013和SharePoint2016的言语应用此情势要命,依据IE语言版本来确定呈现哪个语言?,因而大家这边运用Fiddler工具举行http头文件的收获分析,重要分析:Accept-Language

说明:

Accept-Language:浏览器所企盼的语言连串,当服务器能够提供一种以上的言语版本时要用到;依据http头的意况,用代码修改Accept-Language的装置来效仿设置语言版本的切换

  1. 俺们开辟英文站点:http://sp2016
    用Fiddler抓取分析,如下图:

    语言 4

    剖析结果:

![](https://images2015.cnblogs.com/blog/115581/201704/115581-20170411212946860-1533374866.png)
  1. 俺们开拓中文站点:http://sp2016(切换后)的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

切换后,我们走访下http://sp2016 为华语效果,如下图:

语言 6

  1. 测试切换效果,先测试切换来英文,如下:

语言 7

切换后,大家访问下http://sp2016 为英文效果,如下图:

语言 8

源码可以去我QQ群下载:203613636 谢谢

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图