Check English translation if language doesn't exist (#361)

Need this because of https://github.com/facebook/Docusaurus/pull/316
This commit is contained in:
Joel Marcey 2017-12-27 15:18:58 -08:00 committed by GitHub
parent 5805149eff
commit 5a77f186b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,22 +26,26 @@ function setLanguage(lang) {
language = lang;
}
function doesTranslationExist(str, lang) {
return (
translation[lang] &&
translation[lang]['pages-strings'] &&
translation[lang]['pages-strings'][str]
);
}
function translate(str) {
if (!language || language === '') {
// Check English, just in case; otherwise, just return the raw string back
if (doesTranslationExist(str, 'en')) {
return parseEscapeSequences(translation['en']['pages-strings'][str]);
}
return str;
}
if (
!translation[language] ||
!translation[language]['pages-strings'] ||
!translation[language]['pages-strings'][str]
) {
if (!doesTranslationExist(str, language)) {
// if a translated string doesn't exist, but english does then fallback
if (
translation['en'] &&
translation['en']['pages-strings'] &&
translation['en']['pages-strings'][str]
) {
if (doesTranslationExist(str, 'en')) {
console.error(
"Could not find a string translation in '" +
language +