mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Convert common files to es2015.
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
'use strict';
|
let t = require('./translation.js');
|
||||||
|
|
||||||
var t = require('./translation.js');
|
let NUMBER_OF_QUESTIONS = 12;
|
||||||
|
|
||||||
var NUMBER_OF_QUESTIONS = 12;
|
let faq = {};
|
||||||
|
|
||||||
var faq = {};
|
|
||||||
|
|
||||||
faq.questions = [];
|
faq.questions = [];
|
||||||
|
|
||||||
for (var i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
|
for (let i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
|
||||||
var question = {
|
let question = {
|
||||||
question: t('faqQuestion' + i),
|
question: t(`faqQuestion${i}`),
|
||||||
ios: t('iosFaqAnswer' + i),
|
ios: t(`iosFaqAnswer${i}`),
|
||||||
web: t('webFaqAnswer' + i)
|
web: t(`webFaqAnswer${i}`),
|
||||||
};
|
};
|
||||||
|
|
||||||
faq.questions.push(question);
|
faq.questions.push(question);
|
||||||
@@ -20,7 +18,7 @@ for (var i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
|
|||||||
|
|
||||||
faq.stillNeedHelp = {
|
faq.stillNeedHelp = {
|
||||||
ios: t('iosFaqStillNeedHelp'),
|
ios: t('iosFaqStillNeedHelp'),
|
||||||
web: t('webFaqStillNeedHelp')
|
web: t('webFaqStillNeedHelp'),
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = faq;
|
module.exports = faq;
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
'use strict';
|
import i18n from '../i18n';
|
||||||
|
|
||||||
var i18n = require('../i18n');
|
export default function translator (string, vars = { a: 'a' }) {
|
||||||
|
function func (lang) {
|
||||||
var t = function(string, vars) {
|
|
||||||
var func = function(lang) {
|
|
||||||
if (vars == null) {
|
|
||||||
vars = {
|
|
||||||
a: 'a'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return i18n.t(string, vars, lang);
|
return i18n.t(string, vars, lang);
|
||||||
};
|
}
|
||||||
|
|
||||||
func.i18nLangFunc = true; // Trick to recognize this type of function
|
func.i18nLangFunc = true; // Trick to recognize this type of function
|
||||||
|
|
||||||
return func;
|
return func;
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = t;
|
|
||||||
|
|||||||
@@ -1,71 +1,71 @@
|
|||||||
'use strict';
|
import _ from 'lodash';
|
||||||
|
import content from './content/index';
|
||||||
|
|
||||||
var _ = require('lodash');
|
const DROP_ANIMALS = _.keys(content.pets);
|
||||||
var content = require('./content/index');
|
|
||||||
|
|
||||||
var DROP_ANIMALS = _.keys(content.pets);
|
function beastMasterProgress (pets) {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
function beastMasterProgress(pets) {
|
_(DROP_ANIMALS).each((animal) => {
|
||||||
var count = 0;
|
if (pets[animal] > 0 || pets[animal] === -1)
|
||||||
_(DROP_ANIMALS).each(function(animal) {
|
count++;
|
||||||
if(pets[animal] > 0 || pets[animal] == -1)
|
|
||||||
count++
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dropPetsCurrentlyOwned(pets) {
|
function dropPetsCurrentlyOwned (pets) {
|
||||||
var count = 0;
|
let count = 0;
|
||||||
|
|
||||||
_(DROP_ANIMALS).each(function(animal) {
|
_(DROP_ANIMALS).each((animal) => {
|
||||||
if(pets[animal] > 0)
|
if (pets[animal] > 0)
|
||||||
count++
|
count++;
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mountMasterProgress(mounts) {
|
function mountMasterProgress (mounts) {
|
||||||
var count = 0;
|
let count = 0;
|
||||||
_(DROP_ANIMALS).each(function(animal) {
|
|
||||||
|
_(DROP_ANIMALS).each((animal) => {
|
||||||
if (mounts[animal])
|
if (mounts[animal])
|
||||||
count++
|
count++;
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function remainingGearInSet(userGear, set) {
|
function remainingGearInSet (userGear, set) {
|
||||||
var gear = _.filter(content.gear.flat, function(item) {
|
let gear = _.filter(content.gear.flat, (item) => {
|
||||||
var setMatches = item.klass === set;
|
let setMatches = item.klass === set;
|
||||||
var hasItem = userGear[item.key];
|
let hasItem = userGear[item.key];
|
||||||
|
|
||||||
return setMatches && !hasItem;
|
return setMatches && !hasItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
var count = _.size(gear);
|
let count = _.size(gear);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function questsOfCategory(userQuests, category) {
|
function questsOfCategory (userQuests, category) {
|
||||||
var quests = _.filter(content.quests, function(quest) {
|
let quests = _.filter(content.quests, (quest) => {
|
||||||
var categoryMatches = quest.category === category;
|
let categoryMatches = quest.category === category;
|
||||||
var hasQuest = userQuests[quest.key];
|
let hasQuest = userQuests[quest.key];
|
||||||
|
|
||||||
return categoryMatches && hasQuest;
|
return categoryMatches && hasQuest;
|
||||||
});
|
});
|
||||||
|
|
||||||
var count = _.size(quests);
|
let count = _.size(quests);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
beastMasterProgress: beastMasterProgress,
|
beastMasterProgress,
|
||||||
dropPetsCurrentlyOwned: dropPetsCurrentlyOwned,
|
dropPetsCurrentlyOwned,
|
||||||
mountMasterProgress: mountMasterProgress,
|
mountMasterProgress,
|
||||||
remainingGearInSet: remainingGearInSet,
|
remainingGearInSet,
|
||||||
questsOfCategory: questsOfCategory
|
questsOfCategory,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,51 +1,63 @@
|
|||||||
var _;
|
import _ from 'lodash';
|
||||||
|
|
||||||
_ = require('lodash');
|
let i18n = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
strings: null,
|
strings: null,
|
||||||
translations: {},
|
translations: {},
|
||||||
t: function(stringName) {
|
t, // eslint-disable-line no-use-before-define
|
||||||
var clonedVars, e, locale, string, stringNotFound, vars;
|
};
|
||||||
vars = arguments[1];
|
|
||||||
|
function t (stringName) {
|
||||||
|
let vars = arguments[1];
|
||||||
|
let locale;
|
||||||
|
|
||||||
if (_.isString(arguments[1])) {
|
if (_.isString(arguments[1])) {
|
||||||
vars = null;
|
vars = null;
|
||||||
locale = arguments[1];
|
locale = arguments[1];
|
||||||
} else if (arguments[2] != null) {
|
} else if (arguments[2]) {
|
||||||
vars = arguments[1];
|
|
||||||
locale = arguments[2];
|
locale = arguments[2];
|
||||||
}
|
}
|
||||||
if ((locale == null) || (!module.exports.strings && !module.exports.translations[locale])) {
|
|
||||||
|
let i18nNotSetup = !i18n.strings && !i18n.translations[locale];
|
||||||
|
|
||||||
|
if (!locale || i18nNotSetup) {
|
||||||
locale = 'en';
|
locale = 'en';
|
||||||
}
|
}
|
||||||
if (module.exports.strings) {
|
|
||||||
string = module.exports.strings[stringName];
|
let string;
|
||||||
|
|
||||||
|
if (i18n.strings) {
|
||||||
|
string = i18n.strings[stringName];
|
||||||
} else {
|
} else {
|
||||||
string = module.exports.translations[locale] && module.exports.translations[locale][stringName];
|
string = i18n.translations[locale] && i18n.translations[locale][stringName];
|
||||||
}
|
}
|
||||||
clonedVars = _.clone(vars) || {};
|
|
||||||
|
let clonedVars = _.clone(vars) || {};
|
||||||
|
|
||||||
clonedVars.locale = locale;
|
clonedVars.locale = locale;
|
||||||
|
|
||||||
if (string) {
|
if (string) {
|
||||||
try {
|
try {
|
||||||
return _.template(string, clonedVars);
|
return _.template(string, clonedVars);
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
e = _error;
|
|
||||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (module.exports.strings) {
|
let stringNotFound;
|
||||||
stringNotFound = module.exports.strings.stringNotFound;
|
|
||||||
} else if (module.exports.translations[locale]) {
|
if (i18n.strings) {
|
||||||
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
|
stringNotFound = i18n.strings.stringNotFound;
|
||||||
|
} else if (i18n.translations[locale]) {
|
||||||
|
stringNotFound = i18n.translations[locale] && i18n.translations[locale].stringNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return _.template(stringNotFound, {
|
return _.template(stringNotFound, {
|
||||||
string: stringName
|
string: stringName,
|
||||||
});
|
});
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
e = _error;
|
|
||||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
export default i18n;
|
||||||
|
|||||||
Reference in New Issue
Block a user