Example #1
0
        //Used to start the translation process
        public void Go()
        {
            XElement TargetRoot;

            //Get the Translation API
            TranslateAPI.TranslateAPIBase translator = null;
            switch (_service.ToLower())
            {
            case "microsoft":
                translator = new TranslateAPI.MicrosoftAPI(this._APIKey, this._SourceLanguage, this._TargetLanguage);
                break;

            default:
                translator = new TranslateAPI.GoogleAPI(this._APIKey, this._SourceLanguage, this._TargetLanguage);
                break;
            }


            //First thing go out and try to open the source file and start processing
            using (TextReader tr = File.OpenText(_SourcePath))
            {
                XDocument xdoc = XDocument.Load(tr);
                XElement  root = xdoc.Element("resources");
                TargetRoot = new XElement("resources");

                foreach (XElement e in root.Elements())
                {
                    if (e.Name.LocalName.Equals("string", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //Normal String Element
                        TargetRoot.Add(ProcessString(translator, e));
                    }
                    else if (e.Name.LocalName.Equals("string-array", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //String Array
                        TargetRoot.Add(ProcessStringArray(translator, e));
                    }
                    else
                    {
                        //Unknown element, just pass it thru
                        TargetRoot.Add(e);
                    }
                }
            }

            //Now that the translation is done we can output the result
            XmlTextWriter tw = new XmlTextWriter(this._TargetPath, Encoding.UTF8);

            tw.Formatting = Formatting.Indented;
            TargetRoot.WriteTo(tw);
            tw.Close();
            Console.WriteLine("Done.");
        }
        //Used to start the translation process
        public void Go()
        {
            XElement TargetRoot;

            //Get the Translation API
            TranslateAPI.TranslateAPIBase translator = null;
            switch (_service.ToLower())
            {
                case "microsoft":
                    translator = new TranslateAPI.MicrosoftAPI(this._APIKey, this._SourceLanguage, this._TargetLanguage);
                    break;
                default:
                    translator = new TranslateAPI.GoogleAPI(this._APIKey, this._SourceLanguage, this._TargetLanguage);
                    break;
            }

            //First thing go out and try to open the source file and start processing
            using (TextReader tr = File.OpenText(_SourcePath))
            {
                XDocument xdoc = XDocument.Load(tr);
                XElement root = xdoc.Element("resources");
                TargetRoot = new XElement("resources");

                foreach (XElement e in root.Elements())
                {
                    if (e.Name.LocalName.Equals("string", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //Normal String Element
                        TargetRoot.Add(ProcessString(translator, e));
                    }
                    else if (e.Name.LocalName.Equals("string-array", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //String Array
                        TargetRoot.Add(ProcessStringArray(translator, e));
                    }
                    else
                    {
                        //Unknown element, just pass it thru
                        TargetRoot.Add(e);
                    }
                }
            }

            //Now that the translation is done we can output the result
            XmlTextWriter tw = new XmlTextWriter(this._TargetPath, Encoding.UTF8);
            tw.Formatting = Formatting.Indented;
            TargetRoot.WriteTo(tw);
            tw.Close();
            Console.WriteLine("Done.");
        }