/// <summary> /// Install locales /// </summary> protected virtual void InstallLocaleResources() { //'English' language var language = _languageRepository.Table.Single(l => l.Name == "English"); //save resources var directoryPath = _fileProvider.MapPath(GSInstallationDefaults.LocalizationResourcesPath); var pattern = $"*.{GSInstallationDefaults.LocalizationResourcesFileExtension}"; foreach (var filePath in _fileProvider.EnumerateFiles(directoryPath, pattern)) { var localesXml = _fileProvider.ReadAllText(filePath, Encoding.UTF8); var localizationService = EngineContext.Current.Resolve <ILocalizationService>(); localizationService.ImportResourcesFromXml(language, localesXml); } }
public virtual JsonResult GetAvailableFlagFileNames() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages)) { return(Json("Access denied")); } var flagNames = _fileProvider .EnumerateFiles(_fileProvider.GetAbsolutePath(FLAGS_PATH), "*.png") .Select(_fileProvider.GetFileName) .ToList(); var availableFlagFileNames = flagNames.Select(flagName => new SelectListItem { Text = flagName, Value = flagName }).ToList(); return(Json(availableFlagFileNames)); }
/// <summary> /// Get a list of available languages /// </summary> /// <returns>Available installation languages</returns> public virtual IList <InstallationLanguage> GetAvailableLanguages() { if (_availableLanguages != null) { return(_availableLanguages); } _availableLanguages = new List <InstallationLanguage>(); foreach (var filePath in _fileProvider.EnumerateFiles(_fileProvider.MapPath("~/App_Data/Localization/Installation/"), "*.xml")) { var xmlDocument = new XmlDocument(); xmlDocument.Load(filePath); //get language code var languageCode = ""; //we file name format: installation.{languagecode}.xml var r = new Regex(Regex.Escape("installation.") + "(.*?)" + Regex.Escape(".xml")); var matches = r.Matches(_fileProvider.GetFileName(filePath)); foreach (Match match in matches) { languageCode = match.Groups[1].Value; } var languageNode = xmlDocument.SelectSingleNode(@"//Language"); if (languageNode == null || languageNode.Attributes == null) { continue; } //get language friendly name var languageName = languageNode.Attributes["Name"].InnerText.Trim(); //is default var isDefaultAttribute = languageNode.Attributes["IsDefault"]; var isDefault = isDefaultAttribute != null && Convert.ToBoolean(isDefaultAttribute.InnerText.Trim()); //is default var isRightToLeftAttribute = languageNode.Attributes["IsRightToLeft"]; var isRightToLeft = isRightToLeftAttribute != null && Convert.ToBoolean(isRightToLeftAttribute.InnerText.Trim()); //create language var language = new InstallationLanguage { Code = languageCode, Name = languageName, IsDefault = isDefault, IsRightToLeft = isRightToLeft, }; //load resources var resources = xmlDocument.SelectNodes(@"//Language/LocaleResource"); if (resources == null) { continue; } foreach (XmlNode resNode in resources) { if (resNode.Attributes == null) { continue; } var resNameAttribute = resNode.Attributes["Name"]; var resValueNode = resNode.SelectSingleNode("Value"); if (resNameAttribute == null) { throw new GSException("All installation resources must have an attribute Name=\"Value\"."); } var resourceName = resNameAttribute.Value.Trim(); if (string.IsNullOrEmpty(resourceName)) { throw new GSException("All installation resource attributes 'Name' must have a value.'"); } if (resValueNode == null) { throw new GSException("All installation resources must have an element \"Value\"."); } var resourceValue = resValueNode.InnerText.Trim(); language.Resources.Add(new InstallationLocaleResource { Name = resourceName, Value = resourceValue }); } _availableLanguages.Add(language); _availableLanguages = _availableLanguages.OrderBy(l => l.Name).ToList(); } return(_availableLanguages); }