Remove lint warnings

This commit is contained in:
Kevin Sawicki 2016-06-07 17:00:53 -07:00
parent 2367cd574e
commit 9f64c39f8c
2 changed files with 20 additions and 14 deletions

View file

@ -200,5 +200,5 @@ exports.injectTo = function (extensionId, isBackgroundPage, context) {
getPopup () {} getPopup () {}
} }
chrome.i18n = require('./extensions/i18n.js') chrome.i18n = require('./extensions/i18n.js').setup(extensionId)
} }

View file

@ -10,15 +10,15 @@ const path = require('path')
let metadata let metadata
const getExtensionMetadata = () => { const getExtensionMetadata = (extensionId) => {
if (!metadata) { if (!metadata) {
metadata = ipcRenderer.sendSync('CHROME_I18N_MANIFEST', chrome.runtime.id) metadata = ipcRenderer.sendSync('CHROME_I18N_MANIFEST', extensionId)
} }
return metadata return metadata
} }
const getMessagesPath = (language) => { const getMessagesPath = (extensionId, language) => {
const {srcDirectory, default_locale} = getExtensionMetadata() const {srcDirectory, default_locale} = getExtensionMetadata(extensionId)
const localesDirectory = path.join(srcDirectory, '_locales') const localesDirectory = path.join(srcDirectory, '_locales')
let messagesPath = path.join(localesDirectory, language, 'messages.json') let messagesPath = path.join(localesDirectory, language, 'messages.json')
if (!fs.statSyncNoException(messagesPath)) { if (!fs.statSyncNoException(messagesPath)) {
@ -27,9 +27,10 @@ const getMessagesPath = (language) => {
return messagesPath return messagesPath
} }
const getMessages = (language) => { const getMessages = (extensionId, language) => {
try { try {
return JSON.parse(fs.readFileSync(getMessagesPath(language))) || {} const messagesPath = getMessagesPath(extensionId, language)
return JSON.parse(fs.readFileSync(messagesPath)) || {}
} catch (error) { } catch (error) {
return {} return {}
} }
@ -65,13 +66,18 @@ const replacePlaceholders = (message, placeholders, substitutions) => {
return replaceNumberedSubstitutions(message, substitutions) return replaceNumberedSubstitutions(message, substitutions)
} }
module.exports = { const getMessage = (extensionId, messageName, substitutions) => {
getMessage (messageName, substitutions) { const messages = getMessages(extensionId, getLanguage())
const language = getLanguage()
const messages = getMessages(language)
if (messages.hasOwnProperty(messageName)) { if (messages.hasOwnProperty(messageName)) {
const {message, placeholders} = messages[messageName] const {message, placeholders} = messages[messageName]
return replacePlaceholders(message, placeholders, substitutions) return replacePlaceholders(message, placeholders, substitutions)
} }
} }
exports.setup = (extensionId) => {
return {
getMessage (messageName, substitutions) {
return getMessage(extensionId, messageName, substitutions)
}
}
} }