示例#1
0
        private void Init(string theme)
        {
            theme = theme.ToLower();

            //ищем полное совпадение
            ThemeCultureInfo selectedCulture = Cultures.FirstOrDefault(x => x.Name.ToLower() == theme);

            if (selectedCulture != null)
            {
                CurrentCulture = selectedCulture;
                return;
            }

            //если не находим полное совпадение культуры, то ищем совпадение с более общей культурой
            if (theme.IndexOf('-') != -1)
            {
                theme = theme.Remove(theme.IndexOf('-'));
            }

            selectedCulture = Cultures.FirstOrDefault(x => x.Name.ToLower() == theme);
            if (selectedCulture != null)
            {
                CurrentCulture = selectedCulture;
            }
            else
            {
                //если не нашли ни одного совпадение - назначаем дефолтную культуру(первую)
                CurrentCulture = Cultures.First();
            }
        }
示例#2
0
        private static void AddRegions(string parentCulture)
        {
            var regions = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(x => x.Parent.Name == parentCulture);

            foreach (var regionInstance in regions)
            {
                Cultures.Add(new CCulture {
                    DisplayName = regionInstance.DisplayName, Parent = Cultures.First(culture => culture.ISO == regionInstance.Parent.Name), ISO = regionInstance.Name
                });
            }
        }
 /// <summary>
 /// Tries to get the culture from two letter iso code if not found default will returned.
 /// </summary>
 /// <param name="twoLetterISOLanguageName">Name of the two letter iso language.</param>
 /// <returns></returns>
 internal static CultureInfo TryGetCultureFromTwoLetterIsoCode(string twoLetterISOLanguageName)
 {
     if (IsValidLanguage(twoLetterISOLanguageName))
     {
         return(Cultures.First(o => o.Name.StartsWith(twoLetterISOLanguageName)));
     }
     else
     {
         return(DefaultCulture);
     }
 }
示例#4
0
        internal static string GetCulture(string culture)
        {
            foreach (var cultureInfo in Cultures)
            {
                if (cultureInfo.Name.ToLower().Contains(culture.ToLower()))
                {
                    return(cultureInfo.Name);
                }
            }

            return(Cultures.First().Name);
        }
示例#5
0
        private static async Task AddAdditionalCultures()
        {
            var isSuccessful = true;

            try
            {
                var additionalCulturesTextData = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"data\additionalCultures.txt"));
                if (additionalCulturesTextData.Any())
                {
                    foreach (var additionalCultureInfo in additionalCulturesTextData)
                    {
                        var additionalCultureSplitted = new[] { additionalCultureInfo.Substring(0, additionalCultureInfo.IndexOf(" ", StringComparison.Ordinal)), additionalCultureInfo.Substring(additionalCultureInfo.IndexOf(" ", StringComparison.Ordinal) + 1) };
                        var isoSplitted       = additionalCultureSplitted[0].Split('-');
                        var parentCultureIso  = isoSplitted[0];
                        var additionalCulture = new CCulture {
                            ISO = additionalCultureSplitted[0]
                        };
                        if (Cultures.FirstOrDefault(culture => culture.ISO == parentCultureIso) != null)
                        {
                            additionalCulture.Parent      = Cultures.First(culture => culture.ISO == parentCultureIso);
                            additionalCulture.DisplayName = string.Join(" ", additionalCulture.Parent.DisplayName, additionalCultureSplitted[1]);
                        }
                        else
                        {
                            additionalCulture.DisplayName = additionalCultureSplitted[1];
                        }
                        Cultures.Add(additionalCulture);
                    }
                }
                else
                {
                    WriteToConsole("File with additional cultures is empty", MessageType.Error);
                    isSuccessful = false;
                }
            }
            catch (Exception ex)
            {
                WriteToConsole(ex.Message, MessageType.Error);
                isSuccessful = false;
            }
            if (!isSuccessful)
            {
                await ShowError("Additional cultures are not loaded. See console for details.");
            }
        }
示例#6
0
        /// <summary>
        /// Asynchronously gets the associated event timeline for single culture
        /// </summary>
        /// <param name="culture">The languages to which the returned instance should be translated</param>
        /// <remarks>Recommended to be used when only <see cref="IEventTimeline"/> is needed for this <see cref="IMatch"/></remarks>
        /// <returns>A <see cref="Task{IEventTimeline}"/> representing the retrieval operation</returns>
        public async Task<IEventTimeline> GetEventTimelineAsync(CultureInfo culture)
        {
            var matchCI = (IMatchCI)SportEventCache.GetEventCacheItem(Id);
            if (matchCI == null)
            {
                ExecutionLog.Debug($"Missing data. No match cache item for id={Id}.");
                return null;
            }

            var oneCulture = new List<CultureInfo> {culture ?? Cultures.First()};
            var eventTimelineCI = ExceptionStrategy == ExceptionHandlingStrategy.THROW
                ? await matchCI.GetEventTimelineAsync(oneCulture).ConfigureAwait(false)
                : await new Func<IEnumerable<CultureInfo>, Task<EventTimelineCI>>(matchCI.GetEventTimelineAsync).SafeInvokeAsync(oneCulture, ExecutionLog, GetFetchErrorMessage("EventTimeline")).ConfigureAwait(false);

            return eventTimelineCI == null
                ? null
                : new EventTimeline(eventTimelineCI);
        }