Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
first support for alternative translations
Browse files Browse the repository at this point in the history
  • Loading branch information
anon0230 committed May 14, 2015
1 parent 4641dd8 commit 6e5538e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ const initMenu = (win, languages) => {

fromMenus.forEach(menu => fromPopup.appendChild(menu))

const updateResult = translation => {
result.setAttribute('tooltiptext', translation || '')
const updateResult = (translation, dict) => {
result.setAttribute('tooltiptext', translation + '\n' + dict)
result.setAttribute('label', translation || LABEL_LOADING)
}

Expand Down Expand Up @@ -197,8 +197,8 @@ const initMenu = (win, languages) => {
const showResultsMenu = event => {
const selection = getSelectionFromWin(win)

translate(currentFrom(languages).code, currentTo(languages).code, selection, res => {
updateResult(res.translation)
translate(currentFrom(languages).code, currentTo(languages).code, selection, res => {
updateResult(res.translation, res.dictionary)
if (sp.prefs.lang_from === 'auto') {
updateLangMenuLabel(res.detectedSource)
}
Expand Down
8 changes: 6 additions & 2 deletions providers/google-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ function translationResult(str) {
} catch(e) {
// do nothing on parse error
}

const translation = (
const translation = (
result[0] && result[0].map(chunk => chunk[0]).join(' ')
) || null

const dict = (
result[1] && result[1].map(chunk => chunk[0] + ':\n' + chunk[2].map(chunk => chunk[0] + ': ' + Array((20 - chunk[0].length) > 0 ? 20 - chunk[0].length : 0).join(' ') + chunk[1].join(', ')).join('\n')).join('\n\n')
) || null

return {
detectedSource: result[2],
translation: translation? translation.trim() : null,
dictionary: dict? dict.trim() : null,
}
}

Expand Down

0 comments on commit 6e5538e

Please sign in to comment.