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);
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
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:
Hello Marc,
Thanks for this post! I found this incredibly helpful.
BR / Steve
is working on a reply...