// todo: add caching or use ILocalizer
        public async Task <IDictionary <string, string> > Handle(GetAllLocaleStrings request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var searchRequest = new LocaleStringSearchRequest
            {
                Locale     = request.Locale,
                Module     = request.Module,
                SkipPaging = true
            };

            var searchResult = await _repository.Search(searchRequest, cancellationToken);

            return(searchResult.Rows.ToDictionary(row => row.Key, row => row.Value));
        }
Example #2
0
        public async Task <string> Get(string key, CancellationToken cancellationToken)
        {
            // todo: use fallback lang
            var lang = Thread.CurrentThread.CurrentCulture.Name;

            // todo: add module key to cache key
            var cacheKey = $"{typeof(DefaultLocalizer).FullName}_{lang}";

            var resources = await _cache.GetOrCreate(cacheKey, async() =>
            {
                var request = new LocaleStringSearchRequest
                {
                    Locale     = lang,
                    SkipPaging = true
                };

                var result = await _repository.Search(request, cancellationToken);

                return(result.Rows.ToDictionary(x => x.Key));
            }, cancellationToken);

            return(resources.GetValueOrDefault(key)?.Value /*?? key*/);
        }