locked
SPField.TranslationXml How does it work? RRS feed

  • Question

  • Ok here's the deal we have to make a multilingual application using Sharepoint.

    We've tried a few things and encountered a lot of bugs or strange behaviours.

    So now our problem :
    We've got a list (i.e Scheduled Courses) we want the fields title to be localized without having to make a custom form. We found a property named TranslationXml in the SPField type. But there's not documentation about it anywhere on the net.

    Oh and another problem is there a way to change entirely the locale of a Page from page or a webpart?
    We tried to override the InitializeCulture() to for example set the culture of the current thread to Fr instead of En
    It worked.. almost : We've got half the Sharepoint UI in english and half of it in French.
    But when we create a Site in French everything is in French so the resources are ok and it's just a matter of how to tell Sharepoint that we want it to be in French instead of english and when(during runtime).

    • Edited by Mike Walsh FIN Thursday, July 9, 2009 4:05 AM Schema? removed from Title.
    Wednesday, July 8, 2009 5:44 PM

Answers

  • Ok we found an interresting work-around

    So as said before if you have an English site, and on a page you override InitializeCulture() to modify the current thread culture, you'll end up having a mix of english and another language.

    We managed to fix it so that the whole User interface uses the current thread language.

    What we did is chance the SPWeb.Locale property of the website to French for exemple and SPWeb.Update() after.

    Now we have a website that was supposed to be English with a Locale property set to something else.
    It doesn't change anything to do that is what we thought, but then we tried our InitializeCulture() page again and ...  it worked so now by changing the current thread culture we change the whole interface instead of only half of it.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;
    using Microsoft.SharePoint.ApplicationRuntime;
    
    namespace FirstProject.CustomASPPage
    {
        public class LocalizableWebPartPage : WebPartPage
        {
            protected override void InitializeCulture()
            {
                try
                {
                    //base.InitializeCulture();
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(int.Parse(Request["lcid"]));
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(int.Parse(Request["lcid"]));
                }
                catch (Exception e)
                { }
            }
            protected override void OnPreInit(EventArgs e)
            {
                base.OnPreInit(e);
                InitializeCulture();
            }
        }
    }
    

     

     

    Ok so now we changed every aspx pages to inherit from the one above, and it works great :)

    (InitializeCulture() is never called by Moss for the WebPartPage, so we had to call it from PreInit)

    Wednesday, July 8, 2009 8:36 PM