public ConsoleDisplayOutput(
     IConsole console,
     ILanguageResource languageResource)
 {
     Console          = console;
     LanguageResource = languageResource;
 }
Exemple #2
0
        public I18NOptions AddResource(Locale language, ILanguageResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }
            lock (__lock_resource) {
                if (TryRegisterLanguageOnce(language))
                {
                    var future = new FutureFillingPackage(language);
                    future.AddResource(resource);
                    AddPackageInternal(future);
                }
                else if (__languagePackages.TryGetValue(language, out var package))
                {
                    package.AddResource(resource);
                }
                else
                {
                    throw new InvalidOperationException($"Something broken when add new resource '{resource.Name}'.");
                }
            }

            return(this);
        }
 public LanguageResource(ILanguageResource resource)
 {
     this.CanShowTooltip = resource.CanShowTooltip;
     this.Category       = resource.Category;
     this.Code           = resource.Code;
     this.Key            = resource.Key;
     this.Text           = resource.Text;
     this.TooltipText    = resource.TooltipText;
 }
 public StatisticsOutput(
     IDisplayOutput displayOutput,
     ILanguageResource languageResource,
     ILanguageDecision languageDecision)
 {
     DisplayOutput    = displayOutput;
     LanguageResource = languageResource;
     LanguageDecision = languageDecision;
 }
Exemple #5
0
 public WordCountAnalyzerOutput(
     IDisplayOutput displayOutput,
     IStatisticsOutput statisticsOutput,
     ILanguageResource languageResource)
 {
     DisplayOutput    = displayOutput;
     StatisticsOutput = statisticsOutput;
     LanguageResource = languageResource;
 }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Gets a resource.
        /// </summary>
        ///
        /// <remarks>
        ///     Anwar Javed, 03/05/2014 4:03 PM.
        /// </remarks>
        ///
        /// <exception cref="ArgumentNullException">
        ///     Thrown when one or more required arguments are null.
        /// </exception>
        ///
        /// <param name="uiCulture">
        ///     The culture.
        /// </param>
        /// <param name="key">
        ///     The key.
        /// </param>
        ///
        /// <returns>
        ///     The resource.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public static ILanguageResource GetResource(CultureInfo uiCulture, string key)
        {
            try
            {
                if (uiCulture == null)
                {
                    throw new ArgumentNullException("uiCulture");
                }


                Dictionary <string, LanguageResource> dictionary = null;

                ICache cache = Container.TryGet <ICache>();

                if (cache != null && cache.Exists(LocalizationConstants.LocalizationKey))
                {
                    dictionary = cache.Get <Dictionary <string, LanguageResource> >(LocalizationConstants.LocalizationKey);
                }

                if (dictionary == null)
                {
                    dictionary = GetLanguageDictionary();

                    if (cache != null)
                    {
                        cache.Set(LocalizationConstants.LocalizationKey, dictionary, TimeSpan.FromMinutes(30));
                    }
                }

                string cultureKey        = GetLanguageCode(uiCulture).ToString("G").ToLowerInvariant() + "[" + key + "]";
                string defaultcultureKey = LanguageCode.English.ToString("G").ToLowerInvariant() + "[" + key + "]";

                ILanguageResource value = null;

                if (dictionary.ContainsKey(cultureKey))
                {
                    value = dictionary[cultureKey];
                }

                if (value == null)
                {
                    if (dictionary.ContainsKey(defaultcultureKey))
                    {
                        value = dictionary[defaultcultureKey];
                    }
                }

                return(value);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #7
0
 public void AddResource(ILanguageResource resource)
 {
     if (resource == null)
     {
         return;
     }
     lock (_lock) {
         if (_resources.ContainsKey(resource.Name))
         {
             return;
         }
         _resources.Add(resource.Name, resource);
     }
 }