Example #1
0
        public static void LoadLanguage(OutputLanguage language)
        {
            lock (LanguageLock)
            {
                if (CurrentLanguage != language && language != OutputLanguage.enUS)
                {
                    string        languageFile = Path.Combine(Program.ExeFolder, "Languages", "i18n-" + language.ToString() + ".xml");
                    XmlSerializer serializer   = new XmlSerializer(typeof(I18nLanguage));

                    using (var fileStream = File.OpenRead(languageFile))
                        Language = (I18nLanguage)serializer.Deserialize(fileStream);
                }
                CurrentLanguage = language;
            }
        }
        public static void Generate(string[] args)
        {
            string datatoolPath  = args.ElementAtOrDefault(1);
            string keyLinkFile   = args.ElementAtOrDefault(2);
            string outputFile    = args.ElementAtOrDefault(3);
            string overwatchPath = args.ElementAtOrDefault(4);

            // Return if one of the required arguments is missing.
            if (datatoolPath == null || outputFile == null)
            {
                Log.Write(LogLevel.Normal, syntax);
                return;
            }
            // Get the overwatch path.
            if (overwatchPath == null)
            {
                overwatchPath = "C:/Program Files (x86)/Overwatch";

                if (!Directory.Exists(overwatchPath))
                {
                    Log.Write(LogLevel.Normal, "Could not find a folder at the default Overwatch install location.");
                    Log.Write(LogLevel.Normal, syntax);
                    return;
                }
            }
            else if (!Directory.Exists(overwatchPath))
            {
                Log.Write(LogLevel.Normal, "Could not find a folder at " + overwatchPath + ".");
                Log.Write(LogLevel.Normal, syntax);
                return;
            }

            var datatool = new Dump.DataTool(datatoolPath, overwatchPath);

            XmlSerializer linkSerializer = new XmlSerializer(typeof(KeyLinkList));

            KeyLink[] keyLinks;
            using (var fileStream = File.OpenRead(keyLinkFile))
                keyLinks = ((KeyLinkList)linkSerializer.Deserialize(fileStream)).Methods;

            XmlSerializer serializer = new XmlSerializer(typeof(I18nLanguage));

            foreach (string lang in ProcLanguages)
            {
                // Dump the strings for the language.
                StringKeyGroup strings = new StringKeyGroup();
                strings.DumpStrings(datatool, lang, true, Log);

                I18nLanguage xml = new I18nLanguage();

                // Translate
                foreach (var keyword in Keywords())
                {
                    xml.Methods.Add(new I18nMethod(
                                        keyword,
                                        strings.ValueFromKeyAndLang(keyLinks.First(m => m.MethodName.ToLower() == keyword.ToLower()).Key, lang)
                                        ));
                }

                // Get the file
                string file = Path.Combine(outputFile, "i18n-" + lang + ".xml");

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                // Serialize
                using (var fileStream = File.Create(file))
                    using (StreamWriter writer = new StreamWriter(fileStream))
                        serializer.Serialize(writer, xml);

                Log.Write(LogLevel.Normal, "Finished " + lang + ".");
            }
        }