Hello,
This article assumes you are already familiar with Part 1 and the post preceding it.
Here, we discuss how to localize the content of the SharePoint custom web site project you already have created.
Normally, your ASPX page content would be similar to the following:

We want those 'hardcoded' strings to be localization enabled.
1. Create your default resource file.
You can create a subfolder 'Resources' in your project and put it there. Give it a specific name, in our case it is SampleLocalization.resx
2. Extract the strings we want to localize, into a resource file.
Let's assume we want to have the page title, button text and greeting message localized. We need to create a resource entry for each one of them. Your resource file should look similarly to:

3. Modify the Page attribute to contain Culture and UICulture tags.
It should be similar to:
<%@ Page="" Language="C#" MasterPageFile="~/_layouts/application.master" %>
Inherits="SampleCode.Localized, SampleCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[Public Key Token]" Culture="auto" UICulture="auto" %>
4. Modify your page to refer to the resources, rather than the hardcoded strings

5. Make a copy of your resource file. This will be our second language. Let's make it Bulgarian.
Name it 'SampleLocalization.bg.resx'. Open it for editing and translate the text. For your convenience, here are the strings:
Button_Text - Бутон текст
Greeting - Здравейте, това е тест
Page_Title - Това е заглавието на страницата
Make sure you store it in the Resources folder, next to your SampleLocalization.resx file.
6. web.config modification
Open the web.config of the website that hosts your template page. Find (or add) your globalization node and modify it to contain Culture and UICulture attributes, equaling 'auto'.

7. Deployment
Do a full deploy of your project. Also, don't forget to copy your *.resx files (both of them) into the WSS VirtualDirectories App_GlobalResources. The path usually is:
C:\Inetpub\wwwroot\wss\VirtualDirectories\[Port Number]\App_GlobalResources
Open the web page in the browser and see the result. You can set language preference through the settings of your browser.
For IE:
Tools -> Internet Options -> General Tab -> Languages -> Add / Move Up / Move Down
For FF:
Tools -> Options -> Content tab -> Languages (bottom) Choose button -> Add / Move Up / Move Down
Add Bulgarian. Try how it works when Bulgarian is a first preference, or when it is last.
In English:

In Bulgarian:

Hope this is helpful,
Hristo Yankov
5 comments:
it is a great article, But here i want to know that how u can perform automated deploy for the .resx files using VseWss1.3.Waitng to listen from u.. :)
Hi,
Please take a look at those two blog posts:
http://www.mikhaildikov.com/2007/03/sharepoint-resources-types-use-and_2163.html
http://www.mikhaildikov.com/2007/09/sharepoint-resources-types-use-and.html
Hi,
What do u mean by Deploy recx file?It just mean adding it to the ..../wss/VirtualDirectories/site/App_GlobalResources?
I am not able to see see the changes.
Regards,
Prathibha
Hi
I learnt about localization of custom wep-parts using resource file.
But now the wuestion is how the dynamic contents ( contents from
web services/SQL Databases /Sharepoint lists etc) can be localised on run-
time depending on the language selected.
Please do let me know any inputs in this regard.
Thanks in Advance
Prathibha
Hi Prathibha,
Well, if you are having predefined strings (for example, error messages that never change) you can store them as a code. Then just before you display them to the user, you use some kind of a lookup table to translate the code to the appropriate language.
Example of such lookup table:
ERR1 - "Error 1" - "Грешка 1"
Then, let's say you need to display ERR1 to the user. Depending on your current locale you will either 'translate' it to "Error 1", or to "Грешка 1".
I hope this makes sense to you.
Post a Comment