Issue 305 broken link because of language fixes (#322)

* without having having to worry about site design.

Let me know if double having is intentional

* distinguish case of no translation and en lang

* prettier recommends

* distinguish case of no translation and en lang

* prettier recommends

* merge with latest origin/master changes

* typo

* link with language fixes

* do not show language dropdown if only one enabled

* check translation outside of LanguageDropDown.render
This commit is contained in:
Richard Zhang 2017-12-19 17:44:43 -08:00 committed by Joel Marcey
parent 4a3da1f30a
commit a5e963dba1
8 changed files with 177 additions and 175 deletions

66
lib/server/env.js Normal file
View file

@ -0,0 +1,66 @@
/**
* 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.
*/
const CWD = process.cwd();
const fs = require('fs-extra');
const path = require('path');
const join = path.join;
const languages_js = join(CWD, 'languages.js');
const versions_json = join(CWD, 'versions.json');
class Translation {
constructor() {
this.enabled = false;
this.languages = [
{
enabled: true,
name: 'English',
tag: 'en',
},
];
this._load();
}
enabledLanguages() {
return this.languages.filter(lang => lang.enabled);
}
_load() {
if (fs.existsSync(languages_js)) {
this.enabled = true;
this.languages = require(languages_js);
}
}
}
class Versioning {
constructor() {
this.enabled = false;
this.latestVersion = null;
this.versions = [];
this._load();
}
_load() {
if (fs.existsSync(versions_json)) {
this.enabled = true;
this.versions = JSON.parse(fs.readFileSync(versions_json, 'utf8'));
this.latestVersion = this.versions[0];
}
}
}
const env = {
translation: new Translation(),
versioning: new Versioning(),
};
module.exports = env;