예제 #1
0
        public CldrLoader(string rootPath, CldrLoadOptions loadOptions = CldrLoadOptions.Normal)
        {
            if (File.Exists(rootPath))
            {
                _zip = ZipFile.OpenRead(rootPath);
            }
            else
            {
                DirectoryInfo info = new DirectoryInfo(rootPath);
                if (!info.Exists)
                {
                    throw new DirectoryNotFoundException(info.FullName);
                }
                rootPath = info.FullName;
                if (!Directory.Exists(Path.Combine(rootPath, "main")))
                {
                    rootPath = Path.Combine(rootPath, "common");
                    if (!Directory.Exists(Path.Combine(rootPath, "main")))
                    {
                        throw new FileLoadException("Not a valid CLDR folder");
                    }
                }
                Root = rootPath;
            }
            _scripts = XUtil.GetScriptMap();
            MetaDataLoader loader = new MetaDataLoader(this);

            using (XmlReader reader = OpenXmlFile("supplemental", "supplementalMetadata")) {
                loader.LoadMetaData(reader);
            }

            if ((loadOptions & CldrLoadOptions.Subdivision) != 0)
            {
                using (XmlReader reader = TryOpenXmlFile("supplemental", "subdivisions")) {
                    if (reader != null)
                    {
                        loader.LoadSubdivisions(reader);
                    }
                    else
                    {
                        loadOptions &= ~CldrLoadOptions.Subdivision;
                    }
                }
            }
            LoadOptions = loadOptions;

            using (XmlReader reader = OpenXmlFile("supplemental", "supplementalData")) {
                loader.Load(reader);
            }
            foreach (string name in GetAllLocaleNames())
            {
                GetLocaleInfo(name).HasFile = true;
            }
        }