Ejemplo n.º 1
0
        /// <summary>Returns the CultureInfo object corresponding to language code given</summary>
        /// <param name="cultureName">String representation of CultureInfo as language tag.</param>
        /// <param name="onlyBracketsAtEndOfString">
        ///     Will default back to false if no matching brackets are found.
        /// </param>
        /// <exception cref="CultureNotFoundException">
        ///     Thrown if language tag cannot be found within list of languages supported by .NET.
        /// </exception>
        /// <exception cref="ArgumentNullException">Thrown if culture string given is null.</exception>
        public static CultureInfo GetCultureInfo(string cultureName, bool onlyBracketsAtEndOfString)
        {
            ExceptionLoggingUtils.ThrowIfNull(Logger, nameof(GetCultureInfo), (object)cultureName,
                                              nameof(cultureName), "Unable to generate CultureInfo object from null sting.");

            var culture = GetCultureInfoOrDefaultInternal(cultureName, onlyBracketsAtEndOfString, out var searched);

            ExceptionLoggingUtils.ThrowIf(culture == null, Logger,
                                          new CultureNotFoundException(cultureName, searched,
                                                                       "Unable to generate CultureInfo object from string."),
                                          "GetCultureInfo received invalid culture name.");

            return(culture);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Returns ResourcesManager of <see cref="GlobalSettings.ResourcesAssembly" /> or the current entry assembly,
        ///     if not set.
        /// </summary>
        /// <exception cref="ResourcesNotFoundException">
        ///     Thrown, if both <see cref="GlobalSettings.ResourcesAssembly" /> is not set and the entry assembly
        ///     cannot be accesed.
        /// </exception>
        public static ResourceManager GetResourcesManager()
        {
            if (GlobalSettings.ResourcesAssembly == null)
            {
                GlobalSettings.ResourcesAssembly = Assembly.GetEntryAssembly();
                ExceptionLoggingUtils.ThrowIf <ResourcesNotFoundException>(
                    GlobalSettings.ResourcesAssembly == null, Logger,
                    "GlobalSettings.ResourcesAssembly was not set and entry assembly cannot be accessed.");
            }

            var nameOfAppToBeTranslated = GlobalSettings.ResourcesAssembly.FullName.Split(',')[0];

            return(new ResourceManager(nameOfAppToBeTranslated + ".Properties.Resources",
                                       GlobalSettings.ResourcesAssembly));
        }