From e5d99ce271d09905e2118bd64839611f771879aa Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sun, 15 Nov 2015 08:16:55 -0600 Subject: [PATCH] Convert common files to es2015. --- common/script/content/faq.js | 20 +++--- common/script/content/translation.js | 19 ++--- common/script/count.js | 68 +++++++++--------- common/script/i18n.js | 100 +++++++++++++++------------ 4 files changed, 104 insertions(+), 103 deletions(-) diff --git a/common/script/content/faq.js b/common/script/content/faq.js index e65f8969e6..d55f461b89 100644 --- a/common/script/content/faq.js +++ b/common/script/content/faq.js @@ -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; diff --git a/common/script/content/translation.js b/common/script/content/translation.js index da478c2546..eb6a39f8f0 100644 --- a/common/script/content/translation.js +++ b/common/script/content/translation.js @@ -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; +} diff --git a/common/script/count.js b/common/script/count.js index 77a2974c8a..6305646836 100644 --- a/common/script/count.js +++ b/common/script/count.js @@ -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, }; diff --git a/common/script/i18n.js b/common/script/i18n.js index 59e5e358da..908925e9e5 100644 --- a/common/script/i18n.js +++ b/common/script/i18n.js @@ -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;