Ejemplo n.º 1
0
        private void TranslateOneDocument(string file, string language, bool deletePrior)
        {
            string newFile = file.Replace(".en.md", "." + language + ".md");

            if (File.Exists(newFile) && deletePrior)
            {
                File.Delete(newFile);
            }


            if (!File.Exists(newFile))
            {
                string contents     = GMFileAccess.Readfile(file);
                var    htmlContents = CommonMark.CommonMarkConverter.Convert(contents);
                //string htmlFile = f.Replace(".en.md", ".en.html");
                //File.WriteAllText(htmlFile, htmlContents);

                string translated = translateInCloud.TranslateHtml(htmlContents, language);
                //string htmlNewFile = f.Replace(".en.md", "." + language + ".html");
                //File.WriteAllText(htmlNewFile, translated);

                string replaced = ReplaceSomeStrings(translated);
                File.WriteAllText(newFile, replaced);

                // Wait 10 seconds. GCP didn't like me running a close loop.
                Task.Delay(10000).Wait();
            }
        }
Ejemplo n.º 2
0
        // The purpose of deletePrior is to facilitate resuming translation if we abort and restart.
        // Normally, this is set to true, since we always delete the prior translations.
        // If we set it to false and manually delete the translations before starting,
        // then if we abort the process, we can restart it and it will only translate those
        // which haven't been done yet.
        private void TranslateDocument(string document, string language, bool deletePrior)
        {
            string file = GetEnglishDocumentPath(document);
            string newFile = GetTranslatedDocumentPath(document, language);

            if (File.Exists(newFile) && deletePrior)
            {
                File.Delete(newFile);
            }

            if (!File.Exists(newFile))
            {
                string contents = GMFileAccess.Readfile(file);
                var htmlContents = CommonMark.CommonMarkConverter.Convert(contents);
                //string htmlFile = file.Replace(".md", ".html");
                //File.WriteAllText(htmlFile, htmlContents);

                string doNotEdit = "<!-- Do not edit this file. It was translated by Google. -->\n";

                contents = doNotEdit + contents;

                string translated = translateInCloud.TranslateHtml(htmlContents, language);
                //string htmlNewFile = newfile.Replace(".md", ".html");
                //File.WriteAllText(htmlNewFile, translated);

                string replaced = ReplaceSomeStrings(translated);

                File.WriteAllText(newFile, doNotEdit + replaced);

                // Wait 30 seconds. GCP didn't like me running a close loop.
                Task.Delay(30000).Wait();
            }
        }
Ejemplo n.º 3
0
        //public bool SaveLatest(string stringValue)
        //{
        //    return true;
        //}

        string GetByPath(string path)
        {
            try
            {
                string fixasrString = GMFileAccess.Readfile(path);
                if (fixasrString != null)
                {
                    return(fixasrString);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void DoSomethingToAllFiles(string lang)
        {
            var files = from f in Directory.EnumerateFiles(folder)
                        where f.EndsWith("." + lang + ".md")
                        select f;

            foreach (string file in files)
            {
                if (!File.Exists(file))
                {
                    Console.WriteLine("ERROR: file does not exist: " + file);
                    continue;
                }

                string contents = GMFileAccess.Readfile(file);

                // Do something
            }
        }