SharePoint online Multilingual support - Development(1)
部落格地址:http://blog.csdn.net/FoxDave
上一節講了SharePoint Online網站多語言的實現原理機制,本節主要從程式設計的角度來談一下如何進行相關的設定。
下面列出的程式碼函式方法在命令列中執行即可。至於Context如何獲取可以參考我以前的blog。
Site和List級別的國際化
首先我們們先建立一個測試List,如下程式碼:
private static void CreateCustomList(ClientContext ctx, Web web)
{
ListCollection listCollection = ctx.Web.Lists;
ctx.Load(listCollection, lists => lists.Include(list => list.Title).
Where(list => list.Title == "LocalizeMe"));
ctx.ExecuteQuery();
// Create the list, if it's not there...
if (listCollection.Count == 0)
{
ListCreationInformation newList = new ListCreationInformation();
newList.Title = "LocalizeMe";
newList.QuickLaunchOption = QuickLaunchOptions.On;
newList.TemplateType = (int)ListTemplateType.GenericList;
newList.Description = "LocalizeMe sample list";
List list = web.Lists.Add(newList);
ctx.ExecuteQuery();
}
}
上面的程式碼很簡單,不做過多解釋了,就是建立一個名為LocalizeMe的List。
接下來的程式碼演示瞭如何設定多語言的屬性。
private static void LocalizeSiteAndList(ClientContext cc, Web web)
{
// Localize site title
web.TitleResource.SetValueForUICulture("en-US", "Localize Me");
web.TitleResource.SetValueForUICulture("fi-FI", "Kielikäännä minut");
web.TitleResource.SetValueForUICulture("fr-FR", "Localize Me to French");
// Site description
web.DescriptionResource.SetValueForUICulture("en-US",
"Localize Me site sample");
web.DescriptionResource.SetValueForUICulture("fi-FI",
"Kielikäännetty saitti");
web.DescriptionResource.SetValueForUICulture("fr-FR",
"Localize to French in description");
web.Update();
cc.ExecuteQuery();
// Localize custom list which was created previously
List list = cc.Web.Lists.GetByTitle("LocalizeMe");
cc.Load(list);
cc.ExecuteQuery();
list.TitleResource.SetValueForUICulture("en-US", "Localize Me");
list.TitleResource.SetValueForUICulture("fi-FI", "Kielikäännä minut");
list.TitleResource.SetValueForUICulture("fr-FR", "French text for title");
// Description
list.DescriptionResource.SetValueForUICulture("en-US",
"This is localization CSOM usage example list.");
list.DescriptionResource.SetValueForUICulture("fi-FI",
"Tämä esimerkki näyttää miten voit kielikääntää listoja.");
list.DescriptionResource.SetValueForUICulture("fr-FR",
"I have no idea how to translate this to French.");
list.Update();
cc.ExecuteQuery();
}
簡單說明一下,對於需要國際化的內容,我們需要獲取對應的SharePoint Object之後,操作相應的XXResource屬性,如上所示,對Site和List的Title和Description進行了國際化。執行完程式碼之後,根據當前使用者的prefer language,就可以顯示不同的語言了。
相關文章
- SharePoint online Multilingual support - Development(2)dev
- 從SharePoint 2013遷移到SharePoint Online - 評估工具
- SharePoint Online 自定義Modern UI表單UI
- SharePoint Online 為Modern Page新增指令碼指令碼
- Development log - red & black (1) (轉)dev
- SharePoint Online 觸發 Outlook 郵件內審批
- SharePoint Online 站點模板中許可權的設定
- Python Geospatial Development reading note(1)Pythondev
- Perceptron, Support Vector Machine and Dual Optimization Problem (1)Mac
- Dynamics 365 Online 利用Microsoft Flow實現自動建立Sharepoint LocationROS
- SharePoint Online共享連結的引數是做什麼的?
- Veritas Backup Exec™ 21.3 Multilingual (Windows)Windows
- JLink Support for the Nuvoton NUC1xx devicesdev
- Game Development Methodology for Small Development Teams (轉)GAMdev
- game development -- flowGAMdev
- Oracle OCP 1Z0-053 Q396(Support Workbench)Oracle
- macOS Development - Auto LayoutMacdev
- office365 developmentdev
- What is strategy development process?dev
- BW: 80% of development costsdev
- Web Development Job in 4Webdev
- Support Vector MachinesMac
- alter index ind1 rebuild 和alter index ind1 rebuild onlineIndexRebuild
- Apache JMeter 5.4.1 Build DevelopmentApacheJMeterUIdev
- STM32 Hardware Developmentdev
- PL/SQL development skill testSQLdev
- Java Development Without SpringJavadevSpring
- SharePoint REST API - 同步SharePoint列表項RESTAPI
- WARNING: datafile #1 was not in online backup mode 出現的原因
- LCA Online Query with O(N) Memory and O(1) Time Complexity
- iOS Technical Support For AlliOS
- Types of SAP Support PackagesPackage
- langchain multi modal supportLangChain
- SAP Certified Development Consultant SAP NetWeaver 2004 - Application Development Focus ABAPdevAPP
- 10分鐘精通SharePoint-SharePoint定位
- webpack 開發模式管理 DevelopmentWeb模式dev
- Development Studio 2021,dev
- C/C++ Development LibraryC++dev