Click here to Skip to main content
15,894,630 members
Articles / Desktop Programming / WPF

WPF Multi-Lingual at Runtime

Rate me:
Please Sign up or sign in to vote.
4.46/5 (17 votes)
14 Nov 2007CPOL7 min read 93.7K   1.7K   60  
WPF Multi-Lingual at Runtime
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace CrypTool.AppLogic
{
    public static class LanguageOptions
    {
        private static String selLang;
        private static String[] langFiles;

        static LanguageOptions()
        {
            readLangFiles();
            readSelLang();
        }

        public static void readLangFiles()
        {
          //  String langName;
            DirectoryInfo di = new DirectoryInfo("lng");
            FileInfo[] files = di.GetFiles("*.xml");

            langFiles = new String[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                langFiles[i] = files[i].Name;
                langFiles[i] = langFiles[i].Substring(0, langFiles[i].IndexOf(".xml"));
            }
        }
        public static void readSelLang()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("CrypTool.xml");

            XmlElement root = doc.DocumentElement;

            selLang = root.SelectSingleNode("./Language").InnerText;
        }
        public static String[] getLangFiles()
        {
            return langFiles;
        }
        public static String getSelLang()
        {
            return selLang;
        }
        public static String getSelLangFullPath()
        {
            String selLangFullPath;
            selLangFullPath  = "/lng/";
            selLangFullPath += selLang;
            selLangFullPath += ".xml";
            return selLangFullPath;
        }
        public static void setLang(String selectedLang)
        { 
            selLang = selectedLang;

            //save to CrypTool.xml
            XmlDocument doc = new XmlDocument();
            doc.Load("CrypTool.xml");

            XmlElement root = doc.DocumentElement;

            XmlNode node = root.SelectSingleNode("./Language");
            
            node.InnerText = selLang;

            doc.Save("CrypTool.xml");

           
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions