public SaveResponse Update(TranslationUpdateRequest request)
        {
            if (request.Translations == null)
            {
                throw new ArgumentNullException("translations");
            }

            var translations = List(new TranslationListRequest
            {
                SourceLanguageID = request.TargetLanguageID,
            }).Entities.ToDictionary(x => x.Key, x => x.CustomText);

            foreach (var item in request.Translations)
            {
                translations[item.Key] = item.Value;
            }

            var result = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var pair in translations)
            {
                if (!pair.Value.IsEmptyOrNull())
                {
                    result.Add(pair.Key, pair.Value);
                }
            }

            string json = JSON.StringifyIndented(result, indentation: 2);

            var textsFilePath = GetUserTextsFilePath(request.TargetLanguageID);

            Directory.CreateDirectory(Path.GetDirectoryName(textsFilePath));
            File.WriteAllText(textsFilePath, json);

            var localTextRegistry = Dependency.Resolve <ILocalTextRegistry>();

            (localTextRegistry as IRemoveAll)?.RemoveAll();
            Startup.InitializeLocalTexts(localTextRegistry, Dependency.Resolve <IWebHostEnvironment>());

            TwoLevelCache.ExpireGroupItems(UserRow.Fields.GenerationKey);
            DynamicScriptManager.Reset();

            return(new SaveResponse());
        }
Example #2
0
 public SaveResponse Update(TranslationUpdateRequest request)
 {
     return(new MyRepository().Update(request));
 }
        public SaveResponse Update(TranslationUpdateRequest request)
        {
            if (request.Translations == null)
                throw new ArgumentNullException("translations");

            var translations = List(new TranslationListRequest
            {
                SourceLanguageID = request.TargetLanguageID,
            }).Entities.ToDictionary(x => x.Key, x => x.CustomText);

            foreach (var item in request.Translations)
                translations[item.Key] = item.Value;

            var result = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            foreach (var pair in translations)
                if (!pair.Value.IsEmptyOrNull())
                    result.Add(pair.Key, pair.Value);

            string json = JSON.StringifyIndented(result);

            var textsFilePath = GetUserTextsFilePath(request.TargetLanguageID);
            File.WriteAllText(textsFilePath, json);

            Dependency.Resolve<IDependencyRegistrar>().RegisterInstance<ILocalTextRegistry>(new LocalTextRegistry());
            CommonInitialization.InitializeLocalTexts();
            TwoLevelCache.ExpireGroupItems(UserRow.Fields.GenerationKey);
            DynamicScriptManager.Reset();

            return new SaveResponse();
        }
 public SaveResponse Update(TranslationUpdateRequest request)
 {
     return new MyRepository().Update(request);
 }
Example #5
0
 public SaveResponse Update(TranslationUpdateRequest request)
 {
     return(NewRepository().Update(request, HttpContext.RequestServices));
 }