var _ = require('underscore'),
async = require('async'),
buildDatabase = require("./build_database"),
+ buildDictionary = require("./build_dictionary"),
buildClient = require("./build_client").buildClient,
defaultExtensions = require("./util/default_extensions").extensions,
dataSource = require('../../node-datasource/lib/ext/datasource').dataSource,
});
done(null, "Build succeeded." + returnMessage);
});
+ },
+ function (done) {
+ // step 4: import all dictionary files
+ if (specs[0].clientOnly || specs[0].databaseOnly) {
+ // don't build dictionaries if the user doesn't want us to
+ console.log("Not importing the dictionaries");
+ return done();
+ }
+ var databases = _.map(specs, function (spec) {
+ return spec.database;
+ });
+ async.map(databases, buildDictionary.importAllDictionaries, done);
}
], function (err, results) {
- buildAllCallback(err, results && results[results.length - 1]);
+ buildAllCallback(err, results && results[results.length - 2]);
});
};
source: stringObj.value,
target: preExistingTranslation
});
- } else if ( destinationLang.indexOf('en') === 0 ) {
- // if locale is en_AU en_GB copy the en_US source: strings to target:
- stringCallback(null, {
- key: stringObj.key,
- source: stringObj.value,
- target: stringObj.value
- });
- } else {
+ } else if ( destinationLang.indexOf('en') === 0 ) {
+ // if locale is en_AU en_GB copy the en_US source: strings to target:
+ stringCallback(null, {
+ key: stringObj.key,
+ source: stringObj.value,
+ target: stringObj.value
+ });
+ } else {
// ask google (or not)
autoTranslate(stringObj.value, apiKey, destinationLang, function (err, target) {
stringCallback(null, {
target: target
});
});
- };
+ }
};
async.map(stringsArray, processString, function (err, strings) {
extensionCallback(null, {
/**
Takes a dictionary definition file and inserts the data into the database
*/
- exports.importDictionary = function (database, filename, masterCallback) {
+ var importDictionary = exports.importDictionary = function (database, filename, masterCallback) {
var creds = require("../../node-datasource/config").databaseServer;
creds.database = database;
- // the filename relative unless it starts with a slash
- if (filename.substring(0, 1) !== '/') {
- filename = path.join(process.cwd(), filename);
- }
+ filename = path.resolve(process.cwd(), filename);
if (path.extname(filename) !== '.js') {
console.log("Skipping non-dictionary file", filename);
masterCallback();
});
};
+ exports.importAllDictionaries = function (database, callback) {
+ var translationsDir = path.join(__dirname, "../../node_modules/xtuple-linguist/translations");
+ if (!fs.existsSync(translationsDir)) {
+ console.log("No translations directory found. Ignoring linguist.");
+ return callback();
+ }
+ var importOne = function (dictionary, next) {
+ importDictionary(database, dictionary, next);
+ };
+ var allDictionaries = _.map(fs.readdirSync(translationsDir), function (filename) {
+ return path.join(translationsDir, filename);
+ });
+ async.map(allDictionaries, importOne, callback);
+ };
+
+
}());