public JsonResult Create(AuditDictionaryItem item)
        {
            var languages    = localizationService.GetAllLanguages();
            var mainLanguage = localizationService.GetDefaultLanguageIsoCode();
            var ok           = false;

            var mainLanguageDictionary = new ImportExportDictionaryItem
            {
                Key          = item.Key,
                ParentKey    = item.ParentKey,
                Value        = string.Empty,
                LanguageCode = mainLanguage
            };

            mainLanguageDictionary.Translations = new Dictionary <string, string>();

            if (!languageDictionaryService.ParentExists(item.ParentKey))
            {
                var parentDictionaryItem = new ImportExportDictionaryItem
                {
                    Key          = item.ParentKey,
                    Value        = item.Key,
                    LanguageCode = mainLanguage,
                    Translations = new Dictionary <string, string>()
                };
                languageDictionaryService.CreateDictionaryItem(parentDictionaryItem);
            }

            foreach (var language in languages)
            {
                if (language.IsoCode != mainLanguage)
                {
                    mainLanguageDictionary.Translations.Add(language.IsoCode, string.Empty);
                }
            }
            var result = languageDictionaryService.CreateDictionaryItem(mainLanguageDictionary);

            if (result.Item2)
            {
                ok = true;
            }
            else
            {
                ok = false;
            }
            return(base.Json(new { Created = ok }, JsonRequestBehavior.DenyGet));
        }
예제 #2
0
        public JsonResult UpdateDictionaries()
        {
            string nspace          = "Umbraco.Plugins.Connector.Dictionaries";
            var    idictionary     = typeof(Umbraco.Plugins.Connector.Interfaces.IDictionaryItem);
            var    dictionaryTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                                     where t.IsClass && t.Namespace == nspace && idictionary.IsAssignableFrom(t)
                                     select t;

            var updatedDictionaries = new List <string>();

            foreach (var dictionaryType in dictionaryTypes)
            {
                var keyString = dictionaryType.GetProperty("Key").Value <string>();
                if (!_localizationService.DictionaryItemExists(keyString))
                {
                    _languageDictionaryService.CreateDictionaryItem(dictionaryType);
                    updatedDictionaries.Add(keyString);
                }
            }

            return(Json(updatedDictionaries));
        }