Пример #1
0
        public virtual (IEnumerable <LanguageResourceModel> languageResourceModels, int totalCount) PrepareLanguageResourceModel(LanguageResourceFilterModel model, string languageId, int pageIndex, int pageSize)
        {
            var language = _languageService.GetLanguageById(languageId);

            var resources = _localizationService
                            .GetAllResources(languageId)
                            .OrderBy(x => x.ResourceName)
                            .Select(x => new LanguageResourceModel
            {
                LanguageId = languageId,
                Id         = x.Id,
                Name       = x.ResourceName,
                Value      = x.ResourceValue,
            });

            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.ResourceName))
                {
                    resources = resources.Where(x => x.Name.ToLowerInvariant().Contains(model.ResourceName.ToLowerInvariant()));
                }
                if (!string.IsNullOrEmpty(model.ResourceValue))
                {
                    resources = resources.Where(x => x.Value.ToLowerInvariant().Contains(model.ResourceValue.ToLowerInvariant()));
                }
            }
            resources = resources.AsQueryable();
            return(resources.Skip((pageIndex - 1) * pageSize).Take(pageSize), resources.Count());
        }
Пример #2
0
        public JsonResult configGetTranslations()
        {
            if (Response.StatusCode == 304)
            {
                return(Json(new{ }, JsonRequestBehavior.AllowGet));
            }

            int langId = EngineContext.Current.Resolve <IWorkContext>().WorkingLanguage.Id;
            IList <LocaleStringResource> localStrings = _localizationService.GetAllResources(langId);

            Dictionary <string, string> lcStrings = localStrings.Where(i => i.ResourceName.StartsWith("qa.", true, ci)).Select(l => new {
                name = l.ResourceName, value = l.ResourceValue
            }).ToDictionary(g => g.name, g => g.value);

            //tst o see if cache works
            //var cs = new DataSettingsManager().LoadSettings().DataConnectionString;
            //using (SqlConnection conn = new SqlConnection(cs))
            //{
            //    using (SqlCommand cmd = new SqlCommand("dbo.P_QAGet", conn))
            //    {
            //        cmd.CommandType = CommandType.StoredProcedure;
            //        cmd.Parameters.Add("@LanguageId", SqlDbType.Int).Value = 10;

            //        SqlDataReader rdr;
            //        conn.Open();
            //        rdr = cmd.ExecuteReader();
            //        rdr.Close();
            //    }
            //}

            return(Json(new { time = DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt"), lcStrings = lcStrings }, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
 private void DeleteLocaleResources()
 {
     foreach (var lang in _languageService.GetAllLanguages(true))
     {
         var localeStringResources = _localizationService.GetAllResources(lang.Id)
                                     .Where(x => x.ResourceName.StartsWith("Plugins.Misc.Watermark."));
         foreach (LocaleStringResource lsr in localeStringResources)
         {
             _localizationService.DeleteLocaleStringResource(lsr);
         }
     }
 }
Пример #4
0
        protected NoteListModel PrepareModel()
        {
            var model = new NoteListModel();

            var notes = new List <NoteModel>();

            foreach (var lang in _languageService.GetAllLanguages())
            {
                var resources = _localizationService.GetAllResources(lang.Id)
                                .Where(x => x.ResourceName.StartsWith("Content.Notes."));
                foreach (var resource in resources)
                {
                    var note = notes.Where(x => x.Name == resource.ResourceName).FirstOrDefault();
                    if (note == null)
                    {
                        notes.Add(new NoteModel()
                        {
                            Name    = resource.ResourceName,
                            Text    = resource.ResourceValue,
                            Locales = new List <NoteLocalizedModel>()
                            {
                                new NoteLocalizedModel()
                                {
                                    TextValue  = resource.ResourceValue,
                                    LanguageId = resource.LanguageId
                                }
                            }
                        });
                    }
                    else
                    {
                        note.Locales.Add(new NoteLocalizedModel()
                        {
                            TextValue  = resource.ResourceValue,
                            LanguageId = resource.LanguageId
                        });
                    }
                }
            }

            model.Notes = new GridModel <NoteModel>(notes);
            return(model);
        }
Пример #5
0
        public IActionResult Resources(string languageId, DataSourceRequest command,
                                       LanguageResourceFilterModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            var language = _languageService.GetLanguageById(languageId);

            var resources = _localizationService
                            .GetAllResources(languageId)
                            .OrderBy(x => x.ResourceName)
                            .Select(x => new LanguageResourceModel
            {
                LanguageId = languageId,
                Id         = x.Id,
                Name       = x.ResourceName,
                Value      = x.ResourceValue,
            });

            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.ResourceName))
                {
                    resources = resources.Where(x => x.Name.ToLowerInvariant().Contains(model.ResourceName.ToLowerInvariant()));
                }
                if (!string.IsNullOrEmpty(model.ResourceValue))
                {
                    resources = resources.Where(x => x.Value.ToLowerInvariant().Contains(model.ResourceValue.ToLowerInvariant()));
                }
            }
            resources = resources.AsQueryable();

            var gridModel = new DataSourceResult
            {
                Data  = resources.PagedForCommand(command),
                Total = resources.Count()
            };

            return(Json(gridModel));
        }
Пример #6
0
 /// <summary>
 /// Gets all locale string resources by language identifier
 /// </summary>
 /// <param name="languageId">Language identifier</param>
 /// <returns>Locale string resources</returns>
 public IList <LocaleStringResource> GetAllResources(int languageId)
 {
     return(_localizationService.GetAllResources(languageId));
 }