mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 10:48:05 +02:00
* added a note about needing more than one language to be enabled to allow for a drop down * Removing debug statements * Add 'Help Translate' to translatable strings, improves error messages around missing translated strings, calls write-translations on some routes * Adds sitemap.xml to live server and build. Versioning not supported. -- Also did some file name and module cache cleanups.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
// translation object contains all translations for each string in 18n/en.json
|
|
|
|
const CWD = process.cwd();
|
|
const fs = require("fs");
|
|
const glob = require("glob");
|
|
const path = require("path");
|
|
|
|
let languages;
|
|
if (fs.existsSync(CWD + "/languages.js")) {
|
|
languages = require(CWD + "/languages.js");
|
|
} else {
|
|
languages = [
|
|
{
|
|
enabled: true,
|
|
name: "English",
|
|
tag: "en"
|
|
}
|
|
];
|
|
}
|
|
|
|
const enabledLanguages = languages.filter(lang => lang.enabled);
|
|
|
|
const translation = { languages: enabledLanguages };
|
|
|
|
const files = glob.sync(CWD + "/i18n/**");
|
|
const langRegex = /\/i18n\/(.*)\.json$/;
|
|
|
|
console.log("Loading translation files...");
|
|
|
|
files.forEach(file => {
|
|
const extension = path.extname(file);
|
|
if (extension === ".json") {
|
|
const match = langRegex.exec(file);
|
|
const language = match[1];
|
|
translation[language] = require(file);
|
|
}
|
|
});
|
|
|
|
module.exports = translation;
|