Showing posts with label Multilingual. Show all posts
Showing posts with label Multilingual. Show all posts

Monday, June 10, 2013

Multilingual markups in aspx pages

You can use the below tag to have a multilingual texts in aspx pages

Text="<%$Resources:testresourcefile, lbltest; %>"

Where testresourcefile is the default resource file name and lbltest is a key in all the resource files .

you got to have Resource files

  •  testresourcefile.resx
  • testresourcefile.en-US.resx
  • testresourcefile.de-DE.resx
  • etc
in Mappaed foledr called "RESOURCES" in your visual studio project.



for other multinguals

Infopath forms
Visual Webparts
Site columns,Content types and lists

Wednesday, June 5, 2013

Create Multilingual Sharepoint Site Columns,Content types and Lists from Visual studio programatically




·         Create resource file Eg: test.resx ; test.en-US.resx for English and  test.de-DE.resx for German
·         Add the key values Eg: Stringtest = Documan
·         Create site columns
·         Change the display name of site columns in element.xml as DisplayName="$Resources:Stringtest" Note:Stringtest should be in all the above resource files.
·         Now since your site columns are create in multilingual.
·         Create content type using these columns.
·         In the content types element.xml also do the same leave the FieldRef “id” “name” same but change the displayname as Eg ( DisplayName="$Resources:Stringtest ")
·         Now create the list using the content type .You the change the list definition and instance also in the same way as specified above
·         You can now deploy and check everything will be multilingual.


But Please note that these resource files should be added to the sharepoint MAPPED RESOURCE folder and also open you feature property and change the “default resource file “ to “test”
As our default resource file name in test

Monday, April 1, 2013

SharePoint-13 Multilingual for visual webparts

I had a requirement to create a multilingual visual webpart.The webpart has to be displayed in the language which is described by the browser.

Here is the way to achieve it in sharepoint 13 using the VS12

1)Create a empty sharepoint 13 solution Farm solution .
2) Add a sharepoin 13 project into it .
3)Add a mapped foder "Resources" to the project .
4)Now you gonna add three resources one for english "testMutliLing.en-US.resx" and one for german
    "testMutliLing.de-DE.resx" and one default  "testMutliLing.resx into the mapped folder.
5)In the designer of resource file add the key and value for both english and german resource file .

6)Now open the ascx file and add "label"
7)In the page load event add the following code

int id=1033;
//to get the default broweser language either "en-US" or "de-DE" etc etc


string a = HttpContext.Current.Request.UserLanguages[0].ToString();
if (a.Contains("en-US")){
id = 1033;
}

else{
id = 1031;
}
//german =1031 //english =1033
Label.Text =
SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)id);
}


The en-Us is equal to 1033 you get the different language codes for different languages if you browse for it in internet.

or you can even use

Label.Text = SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)CultureInfo.CurrentUICulture.LCID);


Deploy the solution add the webpart to the page .

It shows the english version picking the value for "String1"  from english resource file.

to check for german .In IE goto internet options-->Languages-->add german de-DE and make it as default language by moving it to the top .say ok and refresh the page

Now the text for Lable is picked by "String1"  from the german resource file.


Also if you want to have multilingual markups you can use as below

<asp:Label ID="lbltest" runat="server" Text="<%$Resources:testMutliLing, String1; %>"></asp:Label>

Friday, March 29, 2013

Get Browser default Language-C#

To find the browser's default language through C# you can use the below code


string [] arrayVariable = HttpContext.Current.Request.UserLanguages;

It returns an array .Since the browser might be having more than one language as preferences .
To get the default preference just pick the first entry of the array

string defaultLangauage = a[0].ToString();