Copied to clipboard

Flag this post as spam?

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


  • shinsuke nakayama 109 posts 250 karma points
    Sep 09, 2015 @ 13:38
    shinsuke nakayama
    1

    Saving Translation Dictionary via API

    Hi guys,

    I have a CSV file which contains list of words and translated words in different language.

    I looked into Services.LocalizationService service, and found a method call Save();

    But i can't seems to get it to work, do you guys have any example i can use? or any other way of storing translation dictionary?

    Thank you Shinsuke Nakayama

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Oct 04, 2015 @ 00:54
    Marc Goodson
    3

    Hi Shinsuke

    There is some documentation on the Localization service here:

    https://our.umbraco.org/documentation/reference/management/services/localizationservice

    In terms of an example, I use it in my DictionaryItemKeySearch dashboard, to save an updated dictionary item translation:

    https://github.com/marcemarc/tooorangey.DictionaryItemKeySearch/blob/master/tooorangey.DictionaryItemKeySearch/tooorangey.DictionaryItemSearch.Api/Controllers/DictionarySearchController.cs

    but also If you are creating dictionary items from scratch for an import then the following should work as an example:

     var ls = ApplicationContext.Current.Services.LocalizationService;    
    
    //create a holder for the item's DictionaryTranslations
    
    List<DictionaryTranslation> _translations = new List<DictionaryTranslation>();
    
     //the constructor for a DictionaryItem requires the Umbraco language object and value of the translated text                       
     //so get the language object, eg from Iso Code                            
    var language = ls.GetLanguageByIsoCode("fr-FR");
    
    // here we create a french translation for our item and add it to the list    
    DictionaryTranslation dt = new DictionaryTranslation(language, "bonjour le monde");                           
     _translations.Add(dt);
    
         //get or create a DictionaryItem, (passing in the Dictionary Key)                           
    IDictionaryItem di = ls.DictionaryItemExists("HelloWorld") ? ls.GetDictionaryItemByKey("HelloWorld") : new DictionaryItem("HelloWorld");
    
     // set the translations created above    
    di.Translations = _translations;
    
     //now save the dictionary item and translations to Umbraco    
    ls.Save(di);
    

    enter image description here

  • Steve 140 posts 321 karma points
    Dec 09, 2017 @ 16:15
    Steve
    0

    Hello Marc,
    Thanks for this post! I found this incredibly helpful.
    BR / Steve

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies