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 30, 2010 @ 02:32
    Eran
    0

    wrong dictionary is loaded (from webservice dll)

    hi,

    i developed an asmx webservice that uses dictionary items like that:

     strEmailBody = umbraco.library.GetDictionaryItem("RV.emailBody");

    after i compile i put the dll in the umbraco bin folder and everything is working well.
    for the site i define host name and new language as i did few times before.
    the problem is that it gets only the english values from the dictionary, although the host name are defined as different culture.

    other things are not making the problem, for example in one of the macro i'm also getting dictionary like this:

     var errMessage = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV.message")' />";

    and it takes the RIGHT dictionary values.

    i looked at the umbraco.library.GetDictionary function and the language defined in the code like this:

    Language byCultureCode = Language.GetByCultureCode(Thread.CurrentThread.CurrentUICulture.Name);

    so i guess that everything is because that the CurrentUICulture is defined as english.
    maybe because my OS is in english? or maybe because my umbraco backend is in english?

    i will be happy to hear ideas.

    Thanks!

    Eran.

  • Eran 292 posts 436 karma points
    Dec 30, 2010 @ 16:29
    Eran
    0

    anyone?..

  • Martin 48 posts 69 karma points
    Dec 30, 2010 @ 18:12
    Martin
    0

    I was looking to see if you were online to try and grab some help with the RVContactForm and here you are! :-)

    Have you looked at the disassembled source for GetDictionaryItem() ?

    Public Shared Function GetDictionaryItem(ByVal Key As String) As String
        Try 
            Dim byCultureCode As Language = Language.GetByCultureCode(Thread.CurrentThread.CurrentUICulture.Name)
            Return New DictionaryItem(Key).Value(byCultureCode.id)
        Catch exception As Exception
            HttpContext.Current.Trace.Warn("library", ("Error returning dictionary item '" & Key & "'"), exception)
            Return String.Empty
        End Try
    End Function
    

    I'm a bit too new to Umbraco to know how to set a currentUICulture, but perhaps you could extend the library and add a method which allows a culture to be passed in?

    Martin

  • Eran 292 posts 436 karma points
    Dec 30, 2010 @ 18:21
    Eran
    0

    about the RVContactForm - please post a messge in the forum of the package and i will help as much as i can.

    about this problem - i guess i can extend the method and send a culture, but the whole idea is that the culture will not be hardcoded, and will be dynamic, so this kind of solution may work to my specific case, but not for others. i'm trying to avoid hard-coded culture assigments.

    Thanks.

  • Martin 48 posts 69 karma points
    Dec 30, 2010 @ 18:25
    Martin
    0

    Could you pull the culture from the current node using the NodeFactory perhaps?

    Re the RVContactForm, it might be me, but there doesn't seem to be a package forum like there normally is against a project?

    http://our.umbraco.org/projects/website-utilities/rvcontactform-multilingual-ajax-contact-form

    Thanks,

    Martin

  • Eran 292 posts 436 karma points
    Dec 30, 2010 @ 18:30
    Eran
    0

    this is the forum page of the RVCOntactForm Package:

    http://our.umbraco.org/projects/website-utilities/rvcontactform-multilingual-ajax-contact-form/bug-reports-and-questions

    maybe i can pull the culture from the current node, and then extend the umbraco source code and add culture parameter to the getDictionaryItem.

    but its looks like such a common problem so i want to make sure that there is no simpler solution to that, before i'm doing that.

  • Martin 48 posts 69 karma points
    Dec 30, 2010 @ 18:33
    Martin
    0

    Good to have that forum link thanks. I'll have a read and check my questions haven't been answered before posting.

    Are you using separate host names/node structures for the cultures?

    Martin

  • Eran 292 posts 436 karma points
    Dec 30, 2010 @ 18:36
    Eran
    0

    yes. i defined different host names for each content tree with different culture.

  • Martin 48 posts 69 karma points
    Dec 30, 2010 @ 20:24
    Martin
    0

    Interesting to have found this earlier. I'm now suffering with the same problem as you on the RVContactForm package.

    My nodes are all en-UK locale, but for some reason the call to

    umbraco.library.GetDictionaryItem("RV-ContactForm.emailBody");

    always looks for en-US (I've checked by outputting it into the email body).

    Looking at the actual source for Umbraco, rather than the disassembled version, the function call is actually using the following:

    System.Threading.Thread.CurrentThread.CurrentUICulture.Name

    So for some reason, the thread running on my UK machine is being forced into a US locale.

     

  • Eran 292 posts 436 karma points
    Dec 30, 2010 @ 22:53
    Eran
    0

    martin this is exactly my problem, maybe someone can have an idea?

  • Martin 48 posts 69 karma points
    Dec 31, 2010 @ 00:17
    Martin
    0

    I've fixed this as follows:

    /// <summary>

     

     

    /// Gets the dictionary item with the specified key.

     

     

    /// </summary>

     

     

    /// <param name="Key">The key.</param>

     

     

    /// <param name="LanguageId">The language ID.</param>

     

     

    /// <returns>A dictionary items value as a string.</returns>

     

     

    public static string GetDictionaryItemByCulture(string Key, int LanguageId)

    {

     

     

    try

    {

     

     

    return new Dictionary.DictionaryItem(Key).Value(LanguageId);

    }

     

     

    catch (Exception errDictionary)

    {

     

     

    HttpContext.Current.Trace.Warn("library", "Error returning dictionary item '" + Key + "'", errDictionary);

     

     

    return string.Empty;

    }

    }

     

     

    And in the RVContactForm class:

     

     

    Domain[] domains = umbraco.library.GetCurrentDomains(int.Parse(nodeId));

     

     

    int thisLanguage = 0;

     

     

    if (domains != null)

    {

     

     

    if (domains.Length > -1)

    {

    thisLanguage = domains[0].Language.id;

    }

    }

     

    I guess it must be something to do with a webservice not being able to know what node and language it relates to, so having a default somewhere.

    Obviously you have to amend the XSLT and .js to pass the nodeId in too..

    Martin

  • Eran 292 posts 436 karma points
    Dec 31, 2010 @ 00:27
    Eran
    0

    so you extended the umbraco.library source code?

    so maybe its better to send directly the current cultureID instead of the nodeID? (maybe using xslt extension)

    (again, its very strange that there is no easier way to do that).

    Thanks.

    Eran

     

  • Martin 48 posts 69 karma points
    Dec 31, 2010 @ 00:29
    Martin
    0

    Exactly that, yes.

    I'm not too worried about taking a shortcut for this project and you might be better off considering if there is a longer term solution. I want the NodeId to allow me to customise the email meta information depending on the node the macro is embedded in, which is why it makes a bit more sense for me to do it this way.

    Martin

  • Eran 292 posts 436 karma points
    Dec 31, 2010 @ 13:34
    Eran
    0

    in that case (you want meta information from the current node) your solution sounds good.

    did you test it? its working?

    the only problem that i see is on future update of umbraco, the umbraco.dll will be overwrite and the package will break.

    maybe we can offer the umbraco core to add this function overload to the umbraco.dll. what do you think?

  • Martin 48 posts 69 karma points
    Dec 31, 2010 @ 14:27
    Martin
    0

    Yes, all tested and working well thanks.

    I'm not planning on updating this version of Umbraco for some time to come as I have had to make other tweaks also, but it would certainly be good to merge this one into the core.

    Martin

  • Eran 292 posts 436 karma points
    Dec 31, 2010 @ 19:15
    Eran
    0

    so this is my conclusions and final solution:

    as far as i understand, the "CurrentThread.CurrentCulture" is defined by the hostname culture that you can configure from umbraco.

    the "CurrentThread.CurrentUICulture", is defined by the operation system of the user.

    the function umbraco.library.GetDictionaryItem is getting the dictionary item that match to the CurrentUICulture.

    this facts is the reason for my and probably yours - problem - i configure hostname as hebrew and my OS in english, so the dll alwayes bring the english dictionary items instead of the hebrew ones as expected.

    so, i'd prefer not to change the umbraco.library source code (for future comptibilaty). instead, i add it as a feature request to the umbraco team.
    in my package, i add at the beggining of the asmx code:

    var originalUICulture = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
    System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

    and at the end i add:

     System.Threading.Thread.CurrentThread.CurrentUICulture = originalUICulture;

    i test it and it works, so soon i will create new version of the package and upload it to the site.

    Thanks,

    Eran.

  • Eran 292 posts 436 karma points
    Dec 31, 2010 @ 19:39
    Eran
    0

    NOTE: in my local server its working but still problem in the live site. will update soon

  • Eran 292 posts 436 karma points
    Jan 02, 2011 @ 14:46
    Eran
    0

    the problem is solved in this post.

    Thanks Martin for all the help, the solution is actually similar to your approach - in order to access the correct dictionary items from the web service, we must get the umbraco language id from the XSLT (this  id is different from LCID - it comes from the umbraco table umbraco.languages).

    Thanks,

    Eran.

Please Sign in or register to post replies

Write your reply to:

Draft