Ejemplo n.º 1
0
 private static void LoadBuiltinLocale()
 {
     FLocale        = new XmlDocument();
     FBuiltinLocale = FLocale;
     using (Stream stream = ResourceLoader.GetStream("en.xml"))
     {
         FLocale.Load(stream);
         CultureInfo enCulture = CultureInfo.GetCultureInfo("en");
         if (!LocalesCache.ContainsKey(enCulture))
         {
             LocalesCache.Add(enCulture, FLocale);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads and caches the locale from <see cref="CultureInfo"/> information.
        /// Notes: *.frl the localization file is looked for in <see cref="LocaleFolder"/>
        /// To work correctly, it is recommended to install FastReport.Localization package
        /// </summary>
        /// <param name="culture"></param>
        public static void LoadLocale(CultureInfo culture)
        {
            if (culture == CultureInfo.InvariantCulture)
            {
                FLocale = FBuiltinLocale;
                return;
            }

            if (LocalesCache.ContainsKey(culture))
            {
                FLocale = LocalesCache[culture];
                return;
            }

            // if culture not found, we try find parent culture
            var parent = culture.Parent;

            if (parent != CultureInfo.InvariantCulture)
            {
                if (LocalesCache.ContainsKey(parent))
                {
                    FLocale = LocalesCache[parent];
                    return;
                }

                // in some cultures, parent have self parent
                if (parent.Parent != CultureInfo.InvariantCulture)
                {
                    if (LocalesCache.ContainsKey(parent.Parent))
                    {
                        FLocale = LocalesCache[parent.Parent];
                        return;
                    }
                }
            }

            string localeFolder = LocaleFolder;
            string localeFile   = string.Empty;

            if (Directory.Exists(localeFolder))
            {
                localeFile = FindLocaleFile(ref culture, localeFolder);
            }

            // Find 'Localization' directory from FastReport.Localization package
            if (string.IsNullOrEmpty(localeFile))
            {
                localeFolder = Path.Combine(Config.ApplicationFolder, "Localization");
                if (Directory.Exists(localeFolder))
                {
                    localeFile = FindLocaleFile(ref culture, localeFolder);
                }
            }

            if (!string.IsNullOrEmpty(localeFile))
            {
                Report.EnsureInit();

                var newLocale = new XmlDocument();
                newLocale.Load(localeFile);
                FLocale = newLocale;
                LocalesCache.Add(culture, newLocale);
            }
        }