Skip to content

Commit

Permalink
chore(locales): added english keys for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Apr 4, 2017
1 parent ce2c218 commit f2e3afc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 18 deletions.
54 changes: 54 additions & 0 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,59 @@
},
"contextMenu_uploadToIpfs": {
"message": "Upload to IPFS"
},
"notify_addonIssueTitle": {
"message": "IPFS Add-on Issue"
},
"notify_addonIssueMsg": {
"message": "See Browser Console for more details"
},
"notify_copiedPublicURLTitle": {
"message": "Copied Public URL"
},
"notify_copiedCanonicalAddressTitle": {
"message": "Copied Canonical Address"
},
"notify_pinnedIpfsResourceTitle": {
"message": "Pinned IPFS Resource"
},
"notify_unpinnedIpfsResourceTitle": {
"message": "Removed IPFS Pin"
},
"notify_pinErrorTitle": {
"message": "Error while pinning"
},
"notify_unpinErrorTitle": {
"message": "Error while removing pin"
},
"notify_apiOnlineTitle": {
"message": "IPFS API is Online"
},
"notify_apiOnlineAutomaticModeMsg": {
"message": "Automatic Mode: Custom Gateway Redirect is active"
},
"notify_apiOfflineTitle": {
"message": "IPFS API is Offline"
},
"notify_apiOfflineAutomaticModeMsg": {
"message": "Automatic Mode: Public Gateway will be used as a fallback"
},
"notify_uploadErrorTitle": {
"message": "Unable to upload via IPFS API"
},
"notify_uploadTrackingProtectionErrorMsg": {
"message": "Try disabling Tracking Protection (press ctrl+shift+j for more details)"
},
"notify_inlineMsg": {
"message": "$msg$",
"placeholders": {
"msg": "$1"
}
},
"notify_inlineErrorMsg": {
"message": "$errorMsg$ (press ctrl+shift+j for more details)",
"placeholders": {
"errorMsg": "$1"
}
}
}
25 changes: 16 additions & 9 deletions add-on/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function init () {
await storeMissingOptions(options, optionDefaults)
} catch (error) {
console.error('Unable to initialize addon due to error', error)
notify('IPFS Add-on Issue', 'See Browser Console for more details')
notify('notify_addonIssueTitle', 'notify_addonIssueMsg')
}
}

Expand Down Expand Up @@ -247,18 +247,25 @@ async function getSwarmPeerCount () {
// GUI
// ===================================================================

function notify (title, message) {
function notify (titleKey, messageKey, messageParam) {
let message
if (messageKey.startsWith('notify_')) {
message = messageParam ? browser.i18n.getMessage(messageKey, messageParam) : browser.i18n.getMessage(messageKey)
} else {
message = messageKey
}

browser.notifications.create({
'type': 'basic',
'iconUrl': browser.extension.getURL('icons/ipfs-logo-on.svg'),
'title': title,
'title': browser.i18n.getMessage(titleKey),
'message': message
})
}

// contextMenus
// -------------------------------------------------------------------
const contextMenuUploadToIpfs = 'contextMenuUploadToIpfs'
const contextMenuUploadToIpfs = 'contextMenu_UploadToIpfs'

browser.contextMenus.create({
id: contextMenuUploadToIpfs,
Expand Down Expand Up @@ -287,21 +294,21 @@ async function addFromURL (info) {
} catch (error) {
console.error(`Error for ${contextMenuUploadToIpfs}`, error)
if (error.message === 'NetworkError when attempting to fetch resource.') {
notify('Unable to upload to IPFS', 'Try disabling Tracking Protection (press ctrl+shift+j for more details)')
notify('notify_uploadErrorTitle', 'notify_uploadTrackingProtectionErrorMsg')
console.warn('IPFS upload often fails because remote file can not be downloaded due to Tracking Protection. See details at: https://github.com/lidel/ipfs-firefox-addon/issues/227')
browser.tabs.create({
'url': 'https://github.com/lidel/ipfs-firefox-addon/issues/227'
})
} else {
notify('Unable to upload to IPFS', `${error.message} (press ctrl+shift+j for more details)`)
notify('notify_uploadErrorTitle', 'notify_inlineErrorMsg', `${error.message}`)
}
}
}

function uploadResultHandler (err, result) {
if (err || !result) {
console.error('ipfs add error', err, result)
notify('Unable to upload to IPFS API', `${err}`)
notify('notify_uploadErrorTitle', 'notify_inlineErrorMsg', `${err}`)
return
}
result.forEach(function (file) {
Expand Down Expand Up @@ -395,10 +402,10 @@ function updateAutomaticModeRedirectState () {
if (state.automaticMode) {
if (state.peerCount > 0 && !state.redirect) { // enable if disabled
browser.storage.local.set({useCustomGateway: true})
.then(() => notify('IPFS API is Online', 'Automatic Mode: Custom Gateway Redirect is active'))
.then(() => notify('notify_apiOnlineTitle', 'notify_apiOnlineAutomaticModeMsg'))
} else if (state.peerCount < 1 && state.redirect) { // disable if enabled
browser.storage.local.set({useCustomGateway: false})
.then(() => notify('IPFS API is Offline', 'Automatic Mode: Public Gateway will be used as a fallback'))
.then(() => notify('notify_apiOfflineTitle', 'notify_apiOfflineAutomaticModeMsg'))
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions add-on/src/popup/page-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function copyCurrentPublicGwAddress () {
const currentTab = await getCurrentTab()
const publicGwAddress = new URL(currentTab.url.replace(bg.state.gwURLString, 'https://ipfs.io/')).toString()
copyTextToClipboard(publicGwAddress)
bg.notify('Copied Public URL', publicGwAddress) // TODO: i18
bg.notify('notify_copiedPublicURLTitle', publicGwAddress)
window.close()
}

Expand All @@ -41,7 +41,7 @@ async function copyCurrentCanonicalAddress () {
const currentTab = await getCurrentTab()
const rawIpfsAddress = currentTab.url.replace(/^.+(\/ip(f|n)s\/.+)/, '$1')
copyTextToClipboard(rawIpfsAddress)
bg.notify('Copied Canonical Address', rawIpfsAddress) // TODO: i18
bg.notify('notify_copiedCanonicalAddressTitle', rawIpfsAddress)
window.close()
}

Expand All @@ -64,9 +64,9 @@ async function pinCurrentResource () {
const currentPath = await resolveToIPFS(new URL(currentTab.url).pathname)
const pinResult = await bg.ipfs.pin.add(currentPath, { recursive: true })
console.log('ipfs.pin.add result', pinResult)
bg.notify('Pinned IPFS Resource', currentPath) // TODO: i18
bg.notify('notify_pinnedIpfsResourceTitle', currentPath)
} catch (error) {
handlePinError('Error while pinning', error)
handlePinError('notify_pinErrorTitle', error)
}
window.close()
}
Expand All @@ -79,9 +79,9 @@ async function unpinCurrentResource () {
const currentPath = await resolveToIPFS(new URL(currentTab.url).pathname)
const result = await bg.ipfs.pin.rm(currentPath, {recursive: true})
console.log('ipfs.pin.rm result', result)
bg.notify('Removed IPFS Pin', currentPath) // TODO: i18
bg.notify('notify_unpinnedIpfsResourceTitle', currentPath)
} catch (error) {
handlePinError('Error while unpinning', error)
handlePinError('notify_unpinErrorTitle', error)
}
window.close()
}
Expand All @@ -107,12 +107,12 @@ function deactivatePinButton () {
hide(unpinResourceButton)
}

async function handlePinError (errorMessage, error) {
console.error(errorMessage, error)
async function handlePinError (errorMessageKey, error) {
console.error(browser.i18n.getMessage(errorMessageKey), error)
deactivatePinButton()
try {
const bg = await getBackgroundPage()
bg.notify(errorMessage, error.message) // TODO: i18
bg.notify(errorMessageKey, error.message)
} catch (error) {
console.error('unable to access background page', error)
}
Expand Down

0 comments on commit f2e3afc

Please sign in to comment.