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; } }
public ScriptMetadata[] LoadScriptMetadata() { var list = new List <ScriptMetadata>(); var scripts = XUtil.GetScriptMap(); using (var reader = OpenFile("properties", "scriptMetadata.txt")) using (var txt = new StreamReader(reader)) { string line; while ((line = txt.ReadLine()) != null) { if (!line.HasValue() || line[0] == '#') { continue; } string[] fields = line.Split(';'); string code = fields[0]?.Trim(); if (!code.HasValue()) { continue; } if (!scripts.TryGetValue(code, out WritingScript script)) { throw new FormatException("Id " + code); } var cur = new ScriptMetadata(); cur.Script = script; list.Add(cur); code = fields[1].Trim(); if (int.TryParse(code, out int rank)) { cur.Rank = rank; } code = fields[3].Trim(); if (code.HasValue()) { cur.Territory = GetTerritory(code); } code = fields[4].Trim(); if (int.TryParse(code, out rank)) { cur.Density = rank; } } } return(list.ToArray()); }
protected ScriptLoaderBase(UcdLoader owner) { _owner = owner; _scripts = XUtil.GetScriptMap(); }