Beispiel #1
0
        /// <summary>
        /// Creates an XML file with the given name and writes the given string data to that file.</summary>
        /// <param name="outputFile">the name and path of the XML file to be created</param>
        /// <param name="stringData">the localizable string data to write to the XML file</param>
        public void WriteLocalizationFile(string outputFile, IEnumerable <LocalizableString> stringData)
        {
            // Prepare the document in memory.
            var xmlDoc = new XmlDocument();

            xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", System.Text.Encoding.UTF8.WebName, "yes"));

            XmlElement root = xmlDoc.CreateElement("StringLocalizationTable");

            xmlDoc.AppendChild(root);

            var sisulizer = new SisulizerWorkaround(m_log);

            foreach (LocalizableString stringItem in stringData)
            {
                XmlElement stringElement = xmlDoc.CreateElement("StringItem");
                root.AppendChild(stringElement);

                string workaroundContext;
                sisulizer.FixContext(stringItem.Text, stringItem.Context, out workaroundContext);

                // id -- the English string that is used as a key at run-time to look-up the translation.
                stringElement.SetAttribute("id", stringItem.Text);

                // context -- will be read by some other means and given to translation company.
                stringElement.SetAttribute("context", workaroundContext);

                // translation -- starts out as English but will be replaced by actual translation
                //  by Sisulizer, for example.
                stringElement.SetAttribute("translation", stringItem.Text);
            }

            // Write out the document.
            using (var writer = new XmlTextWriter(outputFile, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                xmlDoc.WriteTo(writer);
                writer.Flush();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates an XML file with the given name and writes the given string data to that file.</summary>
        /// <param name="stream">Writable stream of the target Localization.xml file</param>
        /// <param name="stringData">Localizable string data to write to the XML file. Duplicates
        /// should have been removed and the desired sorting should have been decided.</param>
        public void WriteLocalizationFile(Stream stream, IEnumerable<LocalizableString> stringData)
        {
            // Prepare new document in memory.
            var xmlDoc = new XmlDocument();
            xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", System.Text.Encoding.UTF8.WebName, "yes"));

            XmlElement root = xmlDoc.CreateElement("StringLocalizationTable");
            xmlDoc.AppendChild(root);

            var sisulizer = new SisulizerWorkaround(m_log);

            foreach (LocalizableString stringItem in stringData)
            {
                XmlElement stringElement = xmlDoc.CreateElement("StringItem");
                root.AppendChild(stringElement);

                string workaroundContext;
                sisulizer.FixContext(stringItem.Text, stringItem.Context, out workaroundContext);

                // id -- the English string that is used as a key at run-time to look-up the translation.
                stringElement.SetAttribute("id", stringItem.Text);

                // context -- will be read by some other means and given to translation company.
                stringElement.SetAttribute("context", workaroundContext);

                // translation -- starts out as English but will be replaced by actual translation
                //  by Sisulizer, for example.
                stringElement.SetAttribute("translation", stringItem.Translation);
            }

            // Write out the document.
            using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                xmlDoc.WriteTo(writer);
                writer.Flush();
            }
        }