Convert common files to es2015.

This commit is contained in:
Blade Barringer
2015-11-15 08:16:55 -06:00
parent ddeb0e7b23
commit e5d99ce271
4 changed files with 104 additions and 103 deletions

View File

@@ -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;
var faq = {};
let faq = {};
faq.questions = [];
for (var i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
var question = {
question: t('faqQuestion' + i),
ios: t('iosFaqAnswer' + i),
web: t('webFaqAnswer' + i)
for (let i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
let question = {
question: t(`faqQuestion${i}`),
ios: t(`iosFaqAnswer${i}`),
web: t(`webFaqAnswer${i}`),
};
faq.questions.push(question);
@@ -20,7 +18,7 @@ for (var i = 0; i <= NUMBER_OF_QUESTIONS; i++) {
faq.stillNeedHelp = {
ios: t('iosFaqStillNeedHelp'),
web: t('webFaqStillNeedHelp')
web: t('webFaqStillNeedHelp'),
};
module.exports = faq;

View File

@@ -1,20 +1,11 @@
'use strict';
import i18n from '../i18n';
var i18n = require('../i18n');
var t = function(string, vars) {
var func = function(lang) {
if (vars == null) {
vars = {
a: 'a'
};
}
export default function translator (string, vars = { a: 'a' }) {
function func (lang) {
return i18n.t(string, vars, lang);
};
}
func.i18nLangFunc = true; // Trick to recognize this type of function
return func;
};
module.exports = t;
}

View File

@@ -1,71 +1,71 @@
'use strict';
import _ from 'lodash';
import content from './content/index';
var _ = require('lodash');
var content = require('./content/index');
const DROP_ANIMALS = _.keys(content.pets);
var DROP_ANIMALS = _.keys(content.pets);
function beastMasterProgress (pets) {
let count = 0;
function beastMasterProgress(pets) {
var count = 0;
_(DROP_ANIMALS).each(function(animal) {
if(pets[animal] > 0 || pets[animal] == -1)
count++
_(DROP_ANIMALS).each((animal) => {
if (pets[animal] > 0 || pets[animal] === -1)
count++;
});
return count;
}
function dropPetsCurrentlyOwned(pets) {
var count = 0;
function dropPetsCurrentlyOwned (pets) {
let count = 0;
_(DROP_ANIMALS).each(function(animal) {
if(pets[animal] > 0)
count++
_(DROP_ANIMALS).each((animal) => {
if (pets[animal] > 0)
count++;
});
return count;
}
function mountMasterProgress(mounts) {
var count = 0;
_(DROP_ANIMALS).each(function(animal) {
function mountMasterProgress (mounts) {
let count = 0;
_(DROP_ANIMALS).each((animal) => {
if (mounts[animal])
count++
count++;
});
return count;
}
function remainingGearInSet(userGear, set) {
var gear = _.filter(content.gear.flat, function(item) {
var setMatches = item.klass === set;
var hasItem = userGear[item.key];
function remainingGearInSet (userGear, set) {
let gear = _.filter(content.gear.flat, (item) => {
let setMatches = item.klass === set;
let hasItem = userGear[item.key];
return setMatches && !hasItem;
});
var count = _.size(gear);
let count = _.size(gear);
return count;
}
function questsOfCategory(userQuests, category) {
var quests = _.filter(content.quests, function(quest) {
var categoryMatches = quest.category === category;
var hasQuest = userQuests[quest.key];
function questsOfCategory (userQuests, category) {
let quests = _.filter(content.quests, (quest) => {
let categoryMatches = quest.category === category;
let hasQuest = userQuests[quest.key];
return categoryMatches && hasQuest;
});
var count = _.size(quests);
let count = _.size(quests);
return count;
}
module.exports = {
beastMasterProgress: beastMasterProgress,
dropPetsCurrentlyOwned: dropPetsCurrentlyOwned,
mountMasterProgress: mountMasterProgress,
remainingGearInSet: remainingGearInSet,
questsOfCategory: questsOfCategory
export default {
beastMasterProgress,
dropPetsCurrentlyOwned,
mountMasterProgress,
remainingGearInSet,
questsOfCategory,
};

View File

@@ -1,51 +1,63 @@
var _;
import _ from 'lodash';
_ = require('lodash');
module.exports = {
let i18n = {
strings: null,
translations: {},
t: function(stringName) {
var clonedVars, e, locale, string, stringNotFound, vars;
vars = arguments[1];
if (_.isString(arguments[1])) {
vars = null;
locale = arguments[1];
} else if (arguments[2] != null) {
vars = arguments[1];
locale = arguments[2];
t, // eslint-disable-line no-use-before-define
};
function t (stringName) {
let vars = arguments[1];
let locale;
if (_.isString(arguments[1])) {
vars = null;
locale = arguments[1];
} else if (arguments[2]) {
locale = arguments[2];
}
let i18nNotSetup = !i18n.strings && !i18n.translations[locale];
if (!locale || i18nNotSetup) {
locale = 'en';
}
let string;
if (i18n.strings) {
string = i18n.strings[stringName];
} else {
string = i18n.translations[locale] && i18n.translations[locale][stringName];
}
let clonedVars = _.clone(vars) || {};
clonedVars.locale = locale;
if (string) {
try {
return _.template(string, clonedVars);
} catch (_error) {
return 'Error processing the string. Please see Help > Report a Bug.';
}
if ((locale == null) || (!module.exports.strings && !module.exports.translations[locale])) {
locale = 'en';
} else {
let stringNotFound;
if (i18n.strings) {
stringNotFound = i18n.strings.stringNotFound;
} else if (i18n.translations[locale]) {
stringNotFound = i18n.translations[locale] && i18n.translations[locale].stringNotFound;
}
if (module.exports.strings) {
string = module.exports.strings[stringName];
} else {
string = module.exports.translations[locale] && module.exports.translations[locale][stringName];
}
clonedVars = _.clone(vars) || {};
clonedVars.locale = locale;
if (string) {
try {
return _.template(string, clonedVars);
} catch (_error) {
e = _error;
return 'Error processing the string. Please see Help > Report a Bug.';
}
} else {
if (module.exports.strings) {
stringNotFound = module.exports.strings.stringNotFound;
} else if (module.exports.translations[locale]) {
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
}
try {
return _.template(stringNotFound, {
string: stringName
});
} catch (_error) {
e = _error;
return 'Error processing the string. Please see Help > Report a Bug.';
}
try {
return _.template(stringNotFound, {
string: stringName,
});
} catch (_error) {
return 'Error processing the string. Please see Help > Report a Bug.';
}
}
};
}
export default i18n;