Example #1
0
        /// <summary>
        /// Parses a locale string from the site path and checks if
        /// it is an active locale, returning the ActiveLocale object if
        /// found.
        /// </summary>
        public async Task <ActiveLocale> ParseLocaleAsync(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            ActiveLocale locale = null;
            string       localeStr;

            if (path.Contains("/"))
            {
                localeStr = path.Split('/').First();
            }
            else
            {
                localeStr = path;
            }

            // Check the first part of the string matches the format for a locale
            if (Regex.Match(localeStr, @"^[a-zA-Z]{2}(-[a-zA-Z]{2})?$", RegexOptions.IgnoreCase).Success)
            {
                var query = new GetActiveLocaleByIETFLanguageTagQuery(localeStr);
                locale = await _queryExecutor.ExecuteAsync(query);
            }

            return(locale);
        }
Example #2
0
        public async Task <ActiveLocale> ExecuteAsync(GetCurrentActiveLocaleQuery query, IExecutionContext executionContext)
        {
            var tag = _cultureContextService.GetCurrent()?.Name;

            if (string.IsNullOrWhiteSpace(tag))
            {
                return(null);
            }

            var byTagQuery = new GetActiveLocaleByIETFLanguageTagQuery(tag);
            var result     = await _queryExecutor.ExecuteAsync(byTagQuery, executionContext);

            return(result);
        }