protected override ResourceLiteralDictionary readAllFromPlistFile(string file) { if (IPhoneUtils.GetInstance().ResourcesZipped) { // if resource is zipped, we will need to parse the file as an xml file (done in abstract class) return(base.readAllFromPlistFile(file)); } else { ResourceLiteralDictionary result = null; if (this.FileExists(file)) { result = new ResourceLiteralDictionary(); NSDictionary literalDictionary = loadResourcesLiteral(file); foreach (NSObject key in literalDictionary.Keys) { result.Add(key.ToString(), literalDictionary[key].ToString()); } return(result); } else { // if file does not exists, means that requested locale is not supported by application // try then to get default locale string return(this.GetResourceLiterals()); } } }
protected override ResourceLiteralDictionary readAllFromPlistFile(string file) { if(IPhoneUtils.GetInstance().ResourcesZipped) { // if resource is zipped, we will need to parse the file as an xml file (done in abstract class) return base.readAllFromPlistFile(file); } else { ResourceLiteralDictionary result = null; if (this.FileExists (file)) { result = new ResourceLiteralDictionary(); NSDictionary literalDictionary = loadResourcesLiteral(file); foreach(NSObject key in literalDictionary.Keys) { result.Add(key.ToString(),literalDictionary[key].ToString()); } return result; } else { // if file does not exists, means that requested locale is not supported by application // try then to get default locale string return this.GetResourceLiterals(); } } }
protected override ResourceLiteralDictionary readAllFromPlistFile (string file) { if(IPhoneUtils.GetInstance().ResourcesZipped) { // if resource is zipped, we will need to parse the file as an xml file (done in abstract class) return base.readAllFromPlistFile(file); } else { try { ResourceLiteralDictionary result = null; if (this.FileExists (file)) { result = new ResourceLiteralDictionary(); NSDictionary literalDictionary = loadResourcesLiteral(file); foreach(NSObject key in literalDictionary.Keys) { result.Add(key.ToString(),literalDictionary[key].ToString()); } return result; } else { // if file does not exists, means that requested locale is not supported by application // try then to get default locale string return this.GetResourceLiterals(); } } catch(Exception ex) { #if DEBUG SystemLogger.Log(SystemLogger.Module.PLATFORM, "reading PLIST file (" + file + ")in iPhonei18N: Exception message:" + ex.Message); #endif return null; } } }
protected virtual ResourceLiteralDictionary readAllFromPlistFile(string file) { ResourceLiteralDictionary result = null; if (File.Exists (file)) { result = new ResourceLiteralDictionary (); try { using (XmlTextReader reader = new XmlTextReader (file)) { reader.XmlResolver = null; XmlDocument XmlDoc = new XmlDocument (); XmlDoc.Load (reader); XmlNodeList keys = XmlDoc.SelectNodes ("plist/dict/key"); XmlNodeList values = XmlDoc.SelectSingleNode ("plist/dict").ChildNodes; for (int value = 0; value <= keys.Count - 1; value++) { if (result.ContainsKey (keys [value].InnerText)) { result [keys [value].InnerText] = values [value * 2 + 1].InnerText; } else { result.Add (keys [value].InnerText, values [value * 2 + 1].InnerText); } } } } catch (Exception) { result = null; } } else { // if file does not exists, means that requested locale is not supported by application // try then to get default locale string return GetResourceLiterals (); } return result; }
private async Task FillLanguagesDictionary() { var configFolder = await Package.Current.InstalledLocation.GetFolderAsync(AppConfigPath); var files = (await configFolder.GetFilesAsync()).Where(x => x.FileType.Equals(PlistExtension) && _i18NConfiguration.SupportedLanguages.Select(language => language.Language).ToList().Contains(x.DisplayName)).ToList(); Parallel.ForEach(files, async languageFile => { var languageFileContentDictionary = new ResourceLiteralDictionary(); using (var fileStream = await languageFile.OpenStreamForReadAsync()) { var xDoc = XDocument.Load(fileStream); if (xDoc.Root != null && xDoc.Root.HasElements) { var dict = xDoc.Root.Element(XName.Get(DictTag)); if (dict != null && dict.HasElements) { var elementList = dict.Descendants().ToList(); if (elementList.Count % 2 == 0) { for (var i = 0; i < elementList.Count; i += 2) { var keyElement = elementList[i]; var valueElement = elementList[i + 1]; if ( !keyElement.Name.LocalName.Equals(KeyTag, StringComparison.CurrentCultureIgnoreCase)) continue; if (!languageFileContentDictionary.ContainsKey(keyElement.Value.ToUpper())) { languageFileContentDictionary.Add(keyElement.Value.ToUpper(), valueElement.Value); } } } } } } lock (LockObj) { _languageFilesDictionary.Add(languageFile.DisplayName.ToLower(), languageFileContentDictionary); } }); }