Remove lint warnings
This commit is contained in:
parent
2367cd574e
commit
9f64c39f8c
2 changed files with 20 additions and 14 deletions
|
@ -200,5 +200,5 @@ exports.injectTo = function (extensionId, isBackgroundPage, context) {
|
|||
getPopup () {}
|
||||
}
|
||||
|
||||
chrome.i18n = require('./extensions/i18n.js')
|
||||
chrome.i18n = require('./extensions/i18n.js').setup(extensionId)
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@ const path = require('path')
|
|||
|
||||
let metadata
|
||||
|
||||
const getExtensionMetadata = () => {
|
||||
const getExtensionMetadata = (extensionId) => {
|
||||
if (!metadata) {
|
||||
metadata = ipcRenderer.sendSync('CHROME_I18N_MANIFEST', chrome.runtime.id)
|
||||
metadata = ipcRenderer.sendSync('CHROME_I18N_MANIFEST', extensionId)
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
const getMessagesPath = (language) => {
|
||||
const {srcDirectory, default_locale} = getExtensionMetadata()
|
||||
const getMessagesPath = (extensionId, language) => {
|
||||
const {srcDirectory, default_locale} = getExtensionMetadata(extensionId)
|
||||
const localesDirectory = path.join(srcDirectory, '_locales')
|
||||
let messagesPath = path.join(localesDirectory, language, 'messages.json')
|
||||
if (!fs.statSyncNoException(messagesPath)) {
|
||||
|
@ -27,9 +27,10 @@ const getMessagesPath = (language) => {
|
|||
return messagesPath
|
||||
}
|
||||
|
||||
const getMessages = (language) => {
|
||||
const getMessages = (extensionId, language) => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(getMessagesPath(language))) || {}
|
||||
const messagesPath = getMessagesPath(extensionId, language)
|
||||
return JSON.parse(fs.readFileSync(messagesPath)) || {}
|
||||
} catch (error) {
|
||||
return {}
|
||||
}
|
||||
|
@ -65,13 +66,18 @@ const replacePlaceholders = (message, placeholders, substitutions) => {
|
|||
return replaceNumberedSubstitutions(message, substitutions)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getMessage (messageName, substitutions) {
|
||||
const language = getLanguage()
|
||||
const messages = getMessages(language)
|
||||
const getMessage = (extensionId, messageName, substitutions) => {
|
||||
const messages = getMessages(extensionId, getLanguage())
|
||||
if (messages.hasOwnProperty(messageName)) {
|
||||
const {message, placeholders} = messages[messageName]
|
||||
return replacePlaceholders(message, placeholders, substitutions)
|
||||
}
|
||||
}
|
||||
|
||||
exports.setup = (extensionId) => {
|
||||
return {
|
||||
getMessage (messageName, substitutions) {
|
||||
return getMessage(extensionId, messageName, substitutions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue