* DEV: Use custom tags rather than handlebars server side These will be skipped if they are ever rendered in a document. The handlebars really messes stuff up. * DEV: Build our own locale file for testing purposes We can't practically proxy everything in test mode, but we can approximate the logic and build our own locale file for testing purposes that works quite well. This allows us to run tests without a proxy. * DEV: Support for testem runner for ember cli tests
94 lines
2.1 KiB
JavaScript
94 lines
2.1 KiB
JavaScript
const Plugin = require("broccoli-plugin");
|
|
const Yaml = require("js-yaml");
|
|
const fs = require("fs");
|
|
const concat = require("broccoli-concat");
|
|
const mergeTrees = require("broccoli-merge-trees");
|
|
|
|
let built = false;
|
|
|
|
class TranslationPlugin extends Plugin {
|
|
constructor(inputNodes, inputFile, options) {
|
|
super(inputNodes, {
|
|
...options,
|
|
persistentOutput: true,
|
|
});
|
|
|
|
this.inputFile = inputFile;
|
|
}
|
|
|
|
build() {
|
|
// We could get fancy eventually and do this based on whether the yaml
|
|
// or vendor files change but in practice we should't need exact up to date
|
|
// translations in admin.
|
|
if (built) {
|
|
return;
|
|
}
|
|
|
|
let file = this.inputPaths[0] + "/" + this.inputFile;
|
|
|
|
let yaml = fs.readFileSync(file, { encoding: "UTF-8" });
|
|
let parsed = Yaml.load(yaml);
|
|
|
|
let extras = {
|
|
en: {
|
|
admin: parsed.en.admin_js.admin,
|
|
},
|
|
};
|
|
|
|
delete parsed.en.admin_js;
|
|
delete parsed.en.wizard_js;
|
|
|
|
let contents = `
|
|
I18n.locale = 'en';
|
|
I18n.translations = ${JSON.stringify(parsed)};
|
|
I18n.extras = ${JSON.stringify(extras)};
|
|
I18n._compiledMFs = {};
|
|
`;
|
|
|
|
fs.writeFileSync(
|
|
`${this.outputPath}/` + this.inputFile.replace(".yml", ".js"),
|
|
contents
|
|
);
|
|
built = true;
|
|
}
|
|
}
|
|
|
|
module.exports = function translatePlugin(...params) {
|
|
return new TranslationPlugin(...params);
|
|
};
|
|
|
|
module.exports.createI18nTree = function (discourseRoot, vendorJs) {
|
|
let en = new TranslationPlugin(
|
|
[discourseRoot + "/config/locales"],
|
|
"client.en.yml"
|
|
);
|
|
|
|
return concat(
|
|
mergeTrees([
|
|
vendorJs,
|
|
discourseRoot + "/app/assets/javascripts/locales",
|
|
discourseRoot + "/lib/javascripts",
|
|
en,
|
|
]),
|
|
{
|
|
inputFiles: [
|
|
"i18n.js",
|
|
"moment.js",
|
|
"moment-timezone-with-data.js",
|
|
"messageformat-lookup.js",
|
|
"client.en.js",
|
|
],
|
|
headerFiles: [
|
|
"i18n.js",
|
|
"moment.js",
|
|
"moment-timezone-with-data.js",
|
|
"messageformat-lookup.js",
|
|
],
|
|
footerFiles: ["client.en.js"],
|
|
outputFile: `assets/test-i18n.js`,
|
|
}
|
|
);
|
|
};
|
|
|
|
module.exports.TranslationPlugin = TranslationPlugin;
|