Ejemplo n.º 1
0
 public override void LoadLanguage(string language = null)
 {
     if (language == null)
     {
         language = TranslationLoader.CurrentLanguage;
     }
     if (AvailableLanguages.Contains(language) && !LoadedLanguages.Contains(language))
     {
         foreach (var assembly in Files.Keys)
         {
             var files = Files[assembly].Where(f => f.Contains($".{language}.")).ToList();
             files.ForEach(f => LoadFile(f, assembly, language));
         }
     }
     _loaded.Add(language);
     Translate.AddLoaded(language);
 }
Ejemplo n.º 2
0
        internal void Load(string filePath)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(filePath);

            var fileNamePart = filePath.Split('\\').Last().Split('.');
            var languageId   = fileNamePart.First().Split('_').Last().ToLowerInvariant();

            _currentFileNameNoExtension = fileNamePart.First().Split('_').First();
            if (!AvailableLanguages.Contains(languageId))
            {
                AvailableLanguages.Add(languageId);
            }

            var rootNode = xmlDocument.SelectSingleNode("Language");

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                ReadXmlNode(childNode, languageId, "Language", LangStrings);
            }
        }
        private CommonLanguageContextProvider SetDefaultLanguage(string value)
        {
            DefaultLanguage = AvailableLanguages.Contains(value) ? value : null;

            return(this);
        }
        private string LookForHttpSessionContext()
        {
            var sessionLanguageContext = HttpContext.Current.Session[SessionContextKey] as string;

            return(AvailableLanguages.Contains(sessionLanguageContext) ? sessionLanguageContext : null);
        }
Ejemplo n.º 5
0
        public TemplateDocumentationPage(string templateFile, string relativeTemplateDirectory, TemplateDirectory templateDir)
        {
            _relativeTemplateDirectory = relativeTemplateDirectory;
            TemplateFile = templateFile;
            TemplateDir  = templateDir;

            string templateXMLFile = Path.Combine(Path.GetDirectoryName(templateFile), Path.GetFileNameWithoutExtension(templateFile) + ".xml");

            if (!File.Exists(templateXMLFile))
            {
                throw new Exception(string.Format("Missing meta infos for template {0}!", templateFile));
            }

            TemplateXML = XElement.Load(templateXMLFile);

            BitmapFrame icon = null;

            if (TemplateXML.Element("icon") != null && TemplateXML.Element("icon").Attribute("file") != null)
            {
                var iconFile = Path.Combine(Path.GetDirectoryName(templateFile), TemplateXML.Element("icon").Attribute("file").Value);
                if (iconFile == null || !File.Exists(iconFile))
                {
                    iconFile = Path.Combine(Path.GetDirectoryName(templateFile), Path.GetFileNameWithoutExtension(templateFile) + ".png");
                }
                if (File.Exists(iconFile))
                {
                    try
                    {
                        icon = BitmapFrame.Create(new BitmapImage(new Uri(iconFile)));
                        Icon = iconFile;
                    }
                    catch (Exception)
                    {
                        icon = null;
                        Icon = "";
                    }
                }
            }

            var authorElement = XMLHelper.FindLocalizedChildElement(TemplateXML, "author");

            if (authorElement != null)
            {
                AuthorName = authorElement.Value;
            }

            var relevantPlugins = TemplateXML.Element("relevantPlugins");

            if (relevantPlugins != null)
            {
                RelevantPlugins = new List <string>();
                foreach (var plugin in relevantPlugins.Elements("plugin"))
                {
                    var name = plugin.Attribute("name");
                    if (name != null)
                    {
                        RelevantPlugins.Add(name.Value);
                    }
                }
            }

            foreach (var title in TemplateXML.Elements("title"))
            {
                var langAtt = title.Attribute("lang");
                if (langAtt != null && !AvailableLanguages.Contains(langAtt.Value))
                {
                    Localizations.Add(langAtt.Value, new LocalizedTemplateDocumentationPage(this, langAtt.Value, icon));
                }
            }
            if (!Localizations.ContainsKey("en"))
            {
                throw new Exception("Documentation should at least support english language!");
            }
        }