cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject docs commit: CB-8318 Add tool for validating translation (close #260)
Date Fri, 16 Jan 2015 19:47:42 GMT
Repository: cordova-docs
Updated Branches:
  refs/heads/master bb76363c4 -> 386fffdb7


CB-8318 Add tool for validating translation (close #260)


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/386fffdb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/386fffdb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/386fffdb

Branch: refs/heads/master
Commit: 386fffdb78d851637b76cf5af04f5507ee30346d
Parents: bb76363
Author: Andrey Kurdyumov <kant2002@gmailc.om>
Authored: Fri Jan 16 20:47:09 2015 +0600
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jan 16 14:47:19 2015 -0500

----------------------------------------------------------------------
 bin/translationreport     |  61 +++++++++++++++++
 bin/translationreport.bat |  26 ++++++++
 lib/docs_validator.js     | 146 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 233 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/386fffdb/bin/translationreport
----------------------------------------------------------------------
diff --git a/bin/translationreport b/bin/translationreport
new file mode 100755
index 0000000..8a805be
--- /dev/null
+++ b/bin/translationreport
@@ -0,0 +1,61 @@
+#!/usr/bin/env node
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+/*jslint node:true, nomen: true */
+
+var yargs = require('yargs')
+    .describe('edge', 'Compare version of English docs with translated version')
+    .count("verbose")
+    .alias('v', 'verbose')
+    .describe('verbose', 'Increase verbosity level of produced output')
+    .describe('source', 'Path to the documentation sources. Default: public')
+    .usage('Usage: $0 [-v] [lang] [version] [--edge]\n' +
+        '    <lang>: Language for which generate docs. If not specified then generate
for all languages.\n' +
+        '    <version>: Version for which generate docs. If not specified then generate
all versions.\n');
+var argv = yargs.argv;
+
+if (argv.help) {
+    yargs.showHelp();
+    process.exit(1);
+}
+
+var language = null;
+var version = null;
+if (argv.edge) {
+    language = null;
+    version = "edge";
+} else {
+    var argumentsCount = argv._.length;
+    if (argumentsCount !== 0) {
+        if (argumentsCount === 2) {
+            language = argv._[0];
+            version = argv._[1];
+        } else {
+            var data = argv._[0];
+            if (data.length === 2) {
+                language = data;
+            } else {
+                version = data;
+            }
+        }
+    }
+}
+
+var validator = require('../lib/docs_validator');
+new validator().validateTranslation(argv.source, language, version, argv.verbose);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/386fffdb/bin/translationreport.bat
----------------------------------------------------------------------
diff --git a/bin/translationreport.bat b/bin/translationreport.bat
new file mode 100644
index 0000000..564f4e1
--- /dev/null
+++ b/bin/translationreport.bat
@@ -0,0 +1,26 @@
+:: Licensed to the Apache Software Foundation (ASF) under one
+:: or more contributor license agreements.  See the NOTICE file
+:: distributed with this work for additional information
+:: regarding copyright ownership.  The ASF licenses this file
+:: to you under the Apache License, Version 2.0 (the
+:: "License"); you may not use this file except in compliance
+:: with the License.  You may obtain a copy of the License at
+:: 
+:: http://www.apache.org/licenses/LICENSE-2.0
+:: 
+:: Unless required by applicable law or agreed to in writing,
+:: software distributed under the License is distributed on an
+:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+:: KIND, either express or implied.  See the License for the
+:: specific language governing permissions and limitations
+:: under the License.
+
+@ECHO OFF
+SET script_path="%~dp0translationreport"
+IF EXIST %script_path% (
+        node "%script_path%" %*
+) ELSE (
+    ECHO.
+    ECHO ERROR: Could not find 'translationreport' script in 'bin' folder, aborting...>&2
+    EXIT /B 1
+)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/386fffdb/lib/docs_validator.js
----------------------------------------------------------------------
diff --git a/lib/docs_validator.js b/lib/docs_validator.js
index 10b9e3a..c680b48 100644
--- a/lib/docs_validator.js
+++ b/lib/docs_validator.js
@@ -150,6 +150,103 @@ var DocsValidator = (function () {
             });
         });
     };
+    
+
+    /**
+    * Validates the specific version of documentation
+    * @param outputDirectory Directory where documentation is stored.
+    * @param language Language which has to be validated.
+    * @param version Version which files has to be validated.
+    * @param verbose_mode Verbosity level.
+    */
+    DocsValidator.prototype.validateTranslation = function (docsDirectory, language, version,
verbose_mode) {
+        var self = this,
+            outputDirectory = path.resolve(docsDirectory || FileHelpers.getDefaultOutputDirectory()),
+            ignore_list = ['.', '..', '.DS_Store', 'test'];
+        
+        verbose_mode = verbose_mode || 0;
+        if (verbose_mode > 0) {
+            console.log("Comparing docs for lang " + language + " and version " + version);
+            console.log("Clearing output directory");
+        }
+
+        fs.readdirSync(outputDirectory).forEach(function (language_dir) {
+            if (ignore_list.indexOf(language_dir) !== -1) {
+                return;
+            }
+
+            if (language && language_dir !== language) {
+                return;
+            }
+
+            var language_path = path.join(outputDirectory, language_dir);
+
+            fs.readdirSync(language_path).forEach(function (version_dir) {
+                if (ignore_list.indexOf(version_dir) !== -1) {
+                    return;
+                }
+
+                if (version && version_dir !== version) {
+                    return;
+                }
+
+                var input_path = path.join(outputDirectory, language_dir, version_dir),
+                    source_path = path.join(outputDirectory, "en", version_dir),
+                    options = {
+                        lang: language_dir,
+                        version: version_dir,
+                        verbose: verbose_mode
+                    };
+
+                console.log(" => Validating translation for version " + version_dir +
" on language " + language_dir + "...");
+                self.doValidateTranslation(source_path, input_path, options);
+            });
+        });
+    };
+    DocsValidator.prototype.doValidateTranslation = function (original_directory, comparing_directory,
options) {
+        var self = this,
+            compareFiles,
+            completed;
+        console.log("Comparing " + original_directory);
+        console.log("with " + comparing_directory);
+        completed = false;
+        dir.readFiles(original_directory,
+            { match: /\.html/ },
+            function (err, content, filename, next) {
+                if (err) {
+                    throw err;
+                }
+
+                var relativePath = path.relative(original_directory, filename),
+                    alternativeFile = path.join(comparing_directory, relativePath),
+                    $ = cheerio.load(alternativeFile);
+                fs.readFile(alternativeFile, function (err, data) {
+                    if (err) {
+                        throw err;
+                    }
+
+                    var target = cheerio.load(data),
+                        source = cheerio.load(content);
+            
+                    self.validateLinksStructure(relativePath, source, target, options);
+                    next();
+                });
+            },
+            function (err, files) {
+                if (err) {
+                    throw err;
+                }
+
+                completed = true;
+            });
+        function waitCompletition() {
+            if (!completed) {
+                setImmediate(waitCompletition);
+            }
+        }
+
+        setImmediate(waitCompletition);
+    };
     DocsValidator.prototype.process = function (original_directory, options) {
         var self = this,
             compareFiles,
@@ -185,6 +282,55 @@ var DocsValidator = (function () {
         setImmediate(waitCompletition);
     };
 
+    DocsValidator.prototype.validateLinksStructure = function (relativePath, source, target,
options) {
+        // Skip _index.html since it will have links in the different
+        // order, not as in the original docs, since each word 
+        // will be translated to different languages.
+        if (relativePath === "_index.html") {
+            return;
+        }
+        
+        var sourceLinks = source("#content a"),
+            targetLinks = target("#content a"),
+            sourceLinksList = "",
+            targetLinksList = "",
+            changes,
+            changed = false;
+        sourceLinks.each(function (i, a) {
+            var link = a.attribs.href || "";
+            link = link.split('#')[0];
+            if (link) {
+                sourceLinksList += link + "\n";
+            }
+        });
+        targetLinks.each(function (i, a) {
+            var link = a.attribs.href || "";
+            link = link.split('#')[0];
+            if (link) {
+                targetLinksList += link + "\n";
+            }
+        });
+        changes = jsdiff.diffLines(sourceLinksList, targetLinksList);
+        changes.forEach(function (part) {
+            changed = part.added || part.removed;
+        });
+        if (changed) {
+            console.error("Path " + relativePath + " is different.");
+            if (options.verbose > 0) {
+                changes.forEach(function (part) {
+                    // green for additions, red for deletions
+                    // grey for common parts
+                    var color = part.added ? 'green' : (part.removed ? 'red' : 'grey');
+                    //if (part.added || part.removed) {
+                        process.stderr.write(part.value[color]);
+                    //}
+                });
+
+                console.log();
+            }
+        }
+    };
+    
     DocsValidator.prototype.validateYaml = function (sourceFile, content, options) {
         if (options.verbose > 0) {
             console.log("Validate " + sourceFile);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message