none
TitleResources SetValueForUICulture for default language RRS feed

  • Question

  • Hello all,

    please can you advise, how to set translations to SP resurce title file ? Everything looks fine, but trnaslations for default culture (1033) are not saved, and no exception is trown.

    - I have SP with 2 cultures : 1033, 1051

    - I prepared visual web part, where user can change :  list fields names

    - in my code I iterate thru cultures and thru SPFields list according selected SPList and check on page load, if som values were changed

    - example : (I include printscreen of my web part)

    SPLanguageCollection lancol = SPRegionalSettings.GlobalInstalledLanguages;
    //iterate Cultures
    foreach (SPLanguage lan in lancol)
    {
      List<SPField> liFields = new List<SPField>();
      //iterate fields
      foreach (SPField field in list.Fields)
      {
        string idORig = "FieldRO_" + field.Id + "_" + lan.LCID.ToString();
        string idNew = "Field_" + field.Id + "_" + lan.LCID.ToString();
        string valOrig = "";
        string ValNew = "";
        if (Request.Params[idORig] != null)
            valOrig = Request.Params[idORig];
        if (Request.Params[idNew] != null)
            ValNew = Request.Params[idNew];
        if (string.IsNullOrEmpty(valOrig) ||  string.IsNullOrEmpty(ValNew))
            continue;
        if (valOrig == ValNew)
             continue;
          //translation
        field.TitleResource.SetValueForUICulture(new CultureInfo(lan.LCID), ValNew);
        liFields.Add(field);
     }
      //update field
    for (int i = 0; i < liFields.Count; i++)
           liFields[i].Update();
    }

    Whyweb part visualisation

    Please, why to English trnaslations arent saved OK ?

    I know, the error is on my side, please, can you show me the right way to do this feature ?

    Thank you

    Marian


    Marian

    Monday, June 4, 2012 8:37 AM

Answers

  • Hi Marian,

    From the information I found (here), it seems there is a problem when you use "SetValueForUICulture" method for the default language.

    Here is a workaround:

    IEnumerable<CultureInfo> cultures = web.SupportedUICultures;
    foreach (CultureInfo culture in cultures)
    {
      Thread.CurrentThread.CurrentUICulture = culture;
      field.Title = ValNew;
      field.Update();
    }


    Cordialement/Regards,

    Ludovic Caffin
    .NET/SharePoint Consultant for A3IS.

    • Marked as answer by Marian__ Monday, June 4, 2012 2:03 PM
    Monday, June 4, 2012 1:22 PM

All replies

  • Hi Marian,

    From the information I found (here), it seems there is a problem when you use "SetValueForUICulture" method for the default language.

    Here is a workaround:

    IEnumerable<CultureInfo> cultures = web.SupportedUICultures;
    foreach (CultureInfo culture in cultures)
    {
      Thread.CurrentThread.CurrentUICulture = culture;
      field.Title = ValNew;
      field.Update();
    }


    Cordialement/Regards,

    Ludovic Caffin
    .NET/SharePoint Consultant for A3IS.

    • Marked as answer by Marian__ Monday, June 4, 2012 2:03 PM
    Monday, June 4, 2012 1:22 PM
  • Ludovic,

    Your solution works fine, thank you very much and have a nice day.

    Marian


    Marian

    Monday, June 4, 2012 2:03 PM