Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eran 292 posts 436 karma points
    Dec 31, 2010 @ 20:01
    Eran
    0

    CurrentUICulture and CurrentCulture

    i created additional language (hebrew) and configured a host name for my content tree (to use the hebrew).

    my problem is that a dll that i developed still get the english values instead of the hebrew, as expected.

    i checked the umbraco.library.GetDictionaryItem source, and found that it takes it from the CurrentUICulture.

    when i debug my app, i found that both CurrentUICulture and CurrentCulture are defined as en-US. why?

    Thanks!

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 05:38
    Lee Kelleher
    0

    Hi Eran,

    From looking at the core code (in v4.5.2) - in umbraco.UmbracoDefault.initUmbracoPage() - if you have a culture/language set for the node/hostname, then that would be assigned to both the CurrentCulture and CurrentUICulture.

    Try adding the "umbDebugShowTrace=true" querystring to see if there is a comment starting with "Culture changed to"?

    If that comment doesn't appear, then there might be an issue with how the culture/language/hostname is being set? (Not sure what exactly though!)

    Cheers, Lee.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 05:56
    Lee Kelleher
    0

    Just noticed from one of your other topics... is this specifically related to access via the webservices?

    http://our.umbraco.org/forum/developers/api-questions/15906-wrong-dictionary-is-loaded-(from-webservice-dll)

  • Eran 292 posts 436 karma points
    Jan 01, 2011 @ 12:25
    Eran
    0

    Hi lee, thanks.

    using umbDebugShowTrace i see the comment "Culture changed to he-IL" so i guess this is not the problem.
    like you saw in the other post about my problem, the problem happens ony when i try to access dictionary item from my webservice dll.


  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 12:34
    Lee Kelleher
    0

    Hi Eran,

    The problem might be due to different context between your webservice code and Umbraco?

    Meaning that during the Umbraco page life-cycle, the CurrentUICulture is set to the associated hostname - yet in your webservice code, the culture is set to the default (most likely from your Web.config's globalization section?)

    Since the "umbraco.library.GetDictionaryItem" method was intended for use with XSLT (so it would have the correct culture context) ... you'd be better to access the dictionary items directly from the "umbraco.cms.businesslogic.Dictionary" API. Looking up the hostname/culture/language.

    Good luck!

    Cheers, Lee.

  • Eran 292 posts 436 karma points
    Jan 01, 2011 @ 12:42
    Eran
    0

    so according to your answer, in my webservice code,  i will try to get the right culture from the umbraco.cms.businesslogic.Dictionary and not from theumbraco.library.GetDictionary.

    you mention "the culture is set to the default (most likely from your Web.config's globalization section)" - do you mean umbraco web.config or my webservice web.config? i didnt change any settings regarding to this section. am i missing something?

    Thanks!

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 13:19
    Lee Kelleher
    0

    Hi Eran,

    Without knowing more about your code set-up, your webservice code would be getting the culture from its own Web.config.  You haven't missed anything, the issue should be due to context (e.g. the webservice code isn't aware of the hostname/culture being set by Umbraco code).

    Yes, you'll need to first get the culture/language via the API and then retrieve the DictionaryItem.

    Cheers, Lee.

  • Eran 292 posts 436 karma points
    Jan 01, 2011 @ 16:55
    Eran
    0

    Hi lee,

    in the webservice code, i'd tried to get the dictionary item using the API, like this:

    string strValidationErr = new umbraco.cms.businesslogic.Dictionary.DictionaryItem("RV-ContactForm.error.serverValidation").Value() ;

     

    but still - it gave me the english and not the hebrew. i thought that the only option that i have, is to send the webservice the pageID, and extract from it the language id.
    so i did a try using hardcode language id (of hebrew) just to see if it works:

    string strValidationErr = new umbraco.cms.businesslogic.Dictionary.DictionaryItem("RV-ContactForm.error.serverValidation").Value(1037);

    but unfortunately, it just give me empty value! (i checked and the dictionaryItem is filled correctly with hebrew value).i dont have any more ideas.. (except maybe to send from the xslt to the webservice the translated values, but it seems to me like a bad idea. i'm sure that there is a better way).
    do you have any idea what is wrong?
    Thanks.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 23:11
    Lee Kelleher
    0

    Hi Eran,

    I really want to help you resolve this too! :-D

    Where are you getting the value "1037" from?  It should be the Id of the language... which should be much lower than that? (Unless you have over a thousand languages in your install?)

    I did a quick test of this... English (United States) was Id #1 and Hebrew (Israel) was Id #2.

    If you need to get the culture/language from the PageId only, then I think you'll need some bespoke code - as I couldn't find anything relevant in the core APIs. Let me know if you need any help with that. ;-)

    Cheers, Lee.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 23:17
    Lee Kelleher
    2

    Hey Eran,

    Just remembered that we have an XSLT extension in uComponents that gets the Language (XML) data from a NodeId... I've reworked it slightly for you:

    public static int GetLanguageIdFromNodeId(int nodeId)
    {
        // get the domains for the node Id
        var domains = library.GetCurrentDomains(nodeId);
    
        // check that a domain exists
        if (domains != null && domains.Length > 0)
        {
            // return the language id from the first domain
            return domains[0].Language.id;
        }
    
        // otherwise return zero
        return 0;
    }

     

    Cheers, Lee.

  • Eran 292 posts 436 karma points
    Jan 01, 2011 @ 23:53
    Eran
    0

    Thanks lee so for your efforts, really appreciate that.
    the id numbers is comming from tests that i did in the web service code on my LOCAL computer:

    System.Threading.Thread.CurrentThread.CurrentUICulture.LCID.ToString() 

    and

    System.Threading.Thread.CurrentThread.CurrentCulture.LCID.ToString()

    and the results was 1033 and 1037 accordingly. i tried to use this values in my shared hosting without success, but when i re-think of that, maybe each machine has different LCID values. i'm going to ceck the DB now and and look for the LCID language ID. maybe its different values.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 01, 2011 @ 23:56
    Lee Kelleher
    0

    Yes, it's not the LCID that you need, it's the Id of the Language (from the Umbraco database) - which should be a much lower number - like "2"?

  • Eran 292 posts 436 karma points
    Jan 02, 2011 @ 00:34
    Eran
    2

    OK, i think that the problem is close to end..
    as you said, the LCID is not the language id.. i found the right language in the umbraco table "umbraco.Language" and there are like you said only two languages: 1=english, 2=hebrew.

    i did a short test again:

    string strValidationErr = new umbraco.cms.businesslogic.Dictionary.DictionaryItem("RV-ContactForm.error.serverValidation").Value(2);

    and.. its working!

    so, whats i'm going to do: using XSLT extension, i will extract the language id from the current page. after that, i will send this language id to the webservice using ajax (with all the other form info). in the webservice code i will get dictionary items using the current language id. thats it.. i hope..

    Thanks a lot lee for all the help, i will update here that everything is working as expected and we can close this post..

    cheers,

    Eran.

  • Eran 292 posts 436 karma points
    Jan 02, 2011 @ 14:34
    Eran
    1

    o.k -  i finish the work as planned in the above post, and everything is works as expected!

    (i just hope that domains[0].Language.id always brings the current language for the current host name..)

    Thanks a lot lee for your help.

    Eran.

  • Yannick Smits 321 posts 718 karma points
    Jan 05, 2011 @ 16:28
    Yannick Smits
    0

    Thanks so much for this thread. Used the same technique inside a Contour workflow, see:
    http://contourcontrib.codeplex.com/SourceControl/changeset/view/5244#60771

  • Eran 292 posts 436 karma points
    Jan 05, 2011 @ 21:28
    Eran
    0

    Yannick glad you found that usefull - by the way, in you contour code, although you handle the case that there is no translation to a given key, i think its better to add also try block - to handle the case the the key dont even exist (and that cause exception - its happend to me one time).
    for example:

     

    public static string GetDictionaryItem(string item, int lang)         
    {            
    string translation;
       try {  
    translation = new umbraco.cms.businesslogic.Dictionary.DictionaryItem(item).Value(lang);
       }            
    catch (Exception){
          translation = string.Empty;
      }
    // need to check for empty string to show keyname when item not translated
       if (string.IsNullOrEmpty(translation))        
           translation = item;       
       return translation;           
    }

     

     

Please Sign in or register to post replies

Write your reply to:

Draft