Copied to clipboard

Flag this post as spam?

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


  • Yannick Smits 321 posts 718 karma points
    Feb 01, 2013 @ 21:54
    Yannick Smits
    1

    V6: LocalizationService.GetDictionaryItemByKey

    I'm trying to insert dictionary items from code using the new API's.

    What I've got so far is:

    ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey("Phone").ToString()

    which returns: "Sequence contains no elements". Which doens't make sense as I do have a "Phone" key in my Dictionary items.

    Hope somebody can shed some light / write some documentation.

  • Yannick Smits 321 posts 718 karma points
    Feb 04, 2013 @ 11:33
    Yannick Smits
    0

    ok than back to using umbraco.library.GetDictionaryItem("Phone")

  • julius 107 posts 289 karma points
    Nov 14, 2013 @ 17:55
    julius
    1

    I have tried 

    IDictionaryItem item = ApplicationContext.Current.Services.LocalizationService.GetRootDictionaryItems().First(x => x.ItemKey.Equals(key));

    as an alternative, but I get the same sequence contains no elements error.

    And I tried

     bool exists = ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists("Jaar");

    and I also get the sequence contains no elements error.

    And I tried

    IDictionaryItem item = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(21);

    and I again get the sequence contains no elements error.

    Am I missing something? I have a dictionary with actual words and translations.

    This does work:

    UmbracoHelper helper = new UmbracoHelper(umbracoContext);
    var dictionaryValue = helper.GetDictionaryValue("Jaar");

    ..but I want to programatically get translations for different languages and this solution won't let me do that. It always returns the translation of the "current" language (probably based on the umbracoContext).

     

     

     

  • julius 107 posts 289 karma points
    Nov 14, 2013 @ 20:39
    julius
    1

    I ended up writing this to get Dictionart Items based on key and ISO code

    public static String ItemForKeyAndLanguage(String key, String languageCode)
    {
               ILanguage language = ApplicationContext.Current.Services.LocalizationService.GetAllLanguages().First(x => x.IsoCode.Equals(languageCode));
               Dictionary.DictionaryItem dictionaryItem = new Dictionary.DictionaryItem(key);
               return dictionaryItem.Value(language.Id);
    }
  • xumix 17 posts 109 karma points c-trib
    Mar 12, 2014 @ 14:27
    xumix
    0

    Same here. LocalizationService just keep giving me "sequence contains no elements"

    Umbraco 6.1.6

     
  • Ove Andersen 435 posts 1541 karma points c-trib
    May 01, 2014 @ 11:20
    Ove Andersen
    0

    The bug has been aknowledged, here's to hoping it will be fixed soon :-)

    http://issues.umbraco.org/issue/U4-2640

Please Sign in or register to post replies

Write your reply to:

Draft