From ee7cdf1276ab529e48ed657643c20b7842b79c80 Mon Sep 17 00:00:00 2001 From: Akal-Ustat Singh Date: Sat, 16 Nov 2019 06:39:46 -0800 Subject: [PATCH] Translation + Transliteration for Dhan Slides and Mool mantar (#763) * legend.md errors * updating legend.md * legend.md errors * set up * fixed and working * strings.js to strings.json * Revert "legend.md errors" This reverts commit 04fcd4c4257c36672d34d36faa1c74c311df86de. * at this point legend.md is annoying * windows = macos shortcuts * mistakes when moved to strings.json * fix bug where slide wouldn't empty * Change dhan to 'Great is' in translation * added 'sri' * Change 'das' to 'daas' * remove testing code * code review implemented but viewer isnt recieving the thing anymore * extend to shortcut tray * remove testing statements * tried adding to menu.js but not work * Typo fix while resolving conflicts. * Dhan Guru slide fixes * Dhan Guru slide fixes * final code rev --- app.js | 17 +++++++- www/js/controller.js | 6 +++ www/js/index.js | 6 +-- www/js/insert-slide.js | 21 ++++++++-- www/js/menu.js | 50 +++++++++++++++-------- www/js/shortcut_tray.js | 2 + www/js/shortcut_tray.json | 51 +++++++++++++----------- www/js/strings.js | 57 --------------------------- www/js/strings.json | 83 +++++++++++++++++++++++++++++++++++++++ www/js/viewer.js | 28 ++++++++++++- 10 files changed, 215 insertions(+), 106 deletions(-) delete mode 100644 www/js/strings.js create mode 100644 www/js/strings.json diff --git a/app.js b/app.js index ff6aa681e..6fae181da 100644 --- a/app.js +++ b/app.js @@ -198,6 +198,7 @@ function createViewer(ipcData) { backgroundColor: '#000000', }); viewerWindow.loadURL(`file://${__dirname}/www/viewer.html`); + viewerWindow.openDevTools(); viewerWindow.webContents.on('did-finish-load', () => { viewerWindow.show(); const [width, height] = viewerWindow.getSize(); @@ -458,7 +459,21 @@ ipcMain.on('show-line', (event, arg) => { createBroadcastFiles(arg); } }); - +ipcMain.on('show-text-with-translations', (event, arg) => { + lastLine = arg; + showLine(arg); + if (viewerWindow) { + viewerWindow.webContents.send('show-text-with-translations', arg); + } else { + createViewer({ + send: 'show-text-with-translations', + data: arg, + }); + } + if (arg.live) { + createBroadcastFiles(arg); + } +}); ipcMain.on('show-empty-slide', () => { emptyOverlay(); }); diff --git a/www/js/controller.js b/www/js/controller.js index 48dee4634..e2dea1b4f 100644 --- a/www/js/controller.js +++ b/www/js/controller.js @@ -575,6 +575,12 @@ module.exports = { global.platform.ipc.send('show-empty-slide'); global.platform.ipc.send('show-text', { text, isGurmukhi, isAnnouncement }); }, + sendTextWithTranslations(textWithTranslations) { + global.webview.send('show-empty-slide'); + global.webview.send('show-text-with-translations', { textWithTranslations }); + global.platform.ipc.send('show-empty-slide'); + global.platform.ipc.send('show-text-with-translations', { textWithTranslations }); + }, sendScroll(pos) { global.platform.ipc.send('send-scroll', { pos }); }, diff --git a/www/js/index.js b/www/js/index.js index 2e9543579..6c76757ec 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -6,7 +6,7 @@ const main = remote.require('./app'); const copy = require('./copy'); const search = require('./search'); -const strings = require('./strings'); +const strings = require('./strings.json'); const dhanGuruModal = require('./insert-slide'); const menu = require('./menu'); const themeEditor = require('./theme_editor'); @@ -33,7 +33,7 @@ function escKey() { const slideShortcuts = { waheguru: () => { - global.controller.sendText(strings.slideStrings.waheguru, true); + global.controller.sendText(strings.waheguru, true); isInsertedSlide = true; }, empty: () => { @@ -41,7 +41,7 @@ const slideShortcuts = { isInsertedSlide = true; }, moolMantra: () => { - global.controller.sendText(strings.slideStrings.moolMantra, true); + global.controller.sendTextWithTranslations(strings.moolMantra); isInsertedSlide = true; }, }; diff --git a/www/js/insert-slide.js b/www/js/insert-slide.js index 38b936a4e..3573828cd 100644 --- a/www/js/insert-slide.js +++ b/www/js/insert-slide.js @@ -3,13 +3,28 @@ const electron = require('electron'); const analytics = electron.remote.getGlobal('analytics'); const tingle = require('./vendor/tingle'); -const strings = require('./strings'); +const strings = require('./strings.json'); const settings = require('./settings'); const { store } = electron.remote.require('./app'); // allowed html tags inside announcement -const allowedTags = strings.allowedAnnouncementTags; +// eslint-disable-next-line prefer-destructuring +const allowedTags = [ + 'b', + 'i', + 'em', + 'u', + 'pre', + 'strong', + 'div', + 'code', + 'br', + 'p', + 'ul', + 'li', + 'ol', +]; /** * boolean to check what modal page is asctive @@ -99,7 +114,7 @@ function buttonOnClick() { if (!isAnnouncementTab) { for (let i = 1; i <= 11; i += 1) { document.getElementById(`guru${i}`).onclick = () => { - global.controller.sendText(strings.slideStrings.dhanguruStrings[i - 1], true, false); + global.controller.sendTextWithTranslations(strings.dhanSlides[i - 1]); global.core.updateInsertedSlide(true); modal.close(); }; diff --git a/www/js/menu.js b/www/js/menu.js index bea7e484a..19a02f4e2 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -4,7 +4,7 @@ const request = require('request'); const moment = require('moment'); const electron = require('electron'); const sanitizeHtml = require('sanitize-html'); -const strings = require('./strings'); +const strings = require('./strings.json'); const { randomShabad } = require('./banidb'); const settings = require('./settings'); @@ -14,7 +14,21 @@ const search = require('./search'); const { store } = electron.remote.require('./app'); const analytics = electron.remote.getGlobal('analytics'); -const allowedTags = strings.allowedAnnouncementTags; +const allowedTags = [ + 'b', + 'i', + 'em', + 'u', + 'pre', + 'strong', + 'div', + 'code', + 'br', + 'p', + 'ul', + 'li', + 'ol', +]; const modal = new tingle.Modal({ footer: true, @@ -222,9 +236,11 @@ const dhanGuruSlideButton = h( 'a.dhanguru-slide-button', { onclick: () => { - const guruJi = document.querySelector('#dhan-guru').value; + const guruJi = document.querySelector('#dhan-guru').selectedIndex; analytics.trackEvent('display', 'dhanguru-slide', guruJi); - global.controller.sendText(guruJi, true); + if (guruJi - 1 >= 0) { + global.controller.sendTextWithTranslations(strings.dhanSlides[guruJi - 1]); + } }, }, h('i.fa.fa-circle-o.list-icon'), @@ -232,17 +248,17 @@ const dhanGuruSlideButton = h( h('label', { htmlFor: 'dhan-guru' }, 'Add Dhan Guru '), h('select#dhan-guru', { value: ' ' }, [ h('option', { value: ' ' }, 'Select'), - h('option', { value: 'DMn gurU nwnk dyv jI' }, 'Nanak Dev Ji'), - h('option', { value: 'DMn gurU AMgd dyv jI' }, 'Angad Dev Ji'), - h('option', { value: 'DMn gurU Amrdwsu swihb jI' }, 'Amardas Sahib Ji'), - h('option', { value: 'DMn gurU rwmdws swihb jI' }, 'Ramdas Sahib Ji'), - h('option', { value: 'DMn gurU Arjun dyv jI' }, 'Arjun Dev Ji'), - h('option', { value: 'DMn gurU hir goibMd swihb jI' }, 'Har Gobind Sahib Ji'), - h('option', { value: 'DMn gurU hir rwie swihb jI' }, 'Har Rai Sahib Ji'), - h('option', { value: 'DMn gurU hir ikRSx swihb jI' }, 'Har Krishan Sahib Ji'), - h('option', { value: 'DMn gurU qyg bhwdr swihb jI' }, 'Teg Bahadur Sahib Ji'), - h('option', { value: 'DMn gurU goibMd isMG swihb jI' }, 'Gobind Singh Sahib Ji'), - h('option', { value: 'DMn gurU gRMQ swihb jI' }, 'Granth Sahib Ji'), + h('option', { value: `${strings.dhanSlides[0]}` }, 'Nanak Dev Ji'), + h('option', { value: `${strings.dhanSlides[1]}` }, 'Angad Dev Ji'), + h('option', { value: `${strings.dhanSlides[2]}` }, 'Amardas Sahib Ji'), + h('option', { value: `${strings.dhanSlides[3]}` }, 'Ramdas Sahib Ji'), + h('option', { value: `${strings.dhanSlides[4]}` }, 'Arjun Dev Ji'), + h('option', { value: `${strings.dhanSlides[5]}` }, 'Har Gobind Sahib Ji'), + h('option', { value: `${strings.dhanSlides[6]}` }, 'Har Rai Sahib Ji'), + h('option', { value: `${strings.dhanSlides[7]}` }, 'Har Krishan Sahib Ji'), + h('option', { value: `${strings.dhanSlides[8]}` }, 'Teg Bahadur Sahib Ji'), + h('option', { value: `${strings.dhanSlides[9]}` }, 'Gobind Singh Sahib Ji'), + h('option', { value: `${strings.dhanSlides[10]}` }, 'Granth Sahib Ji'), ]), ], ), @@ -279,8 +295,8 @@ const announcementSlideButton = h( onclick: () => { const isGurmukhi = document.querySelector('#announcement-language').checked; const placeholderText = isGurmukhi - ? strings.announcemenetPlaceholder.gurmukhi - : strings.announcemenetPlaceholder.english; + ? strings.announcement.placeholder.gurmukhi + : strings.announcement.placeholder.english; const $announcementText = document.querySelector('.announcement-text'); $announcementText.classList.toggle('gurmukhi', isGurmukhi); diff --git a/www/js/shortcut_tray.js b/www/js/shortcut_tray.js index 39fca06f9..beb70f41c 100644 --- a/www/js/shortcut_tray.js +++ b/www/js/shortcut_tray.js @@ -25,6 +25,8 @@ const trayItemFactory = (trayItemKey, trayItem) => global.core.search.loadCeremony(trayItem.ref).catch(error => { analytics.trackEvent('ceremonyFailed', trayItem.ref, error); }); + } else if (trayItem.type === 'textWithTranslations') { + global.controller.sendTextWithTranslations(trayItem.ref); } }, }, diff --git a/www/js/shortcut_tray.json b/www/js/shortcut_tray.json index 5630f4250..4a7860ccc 100644 --- a/www/js/shortcut_tray.json +++ b/www/js/shortcut_tray.json @@ -1,26 +1,31 @@ { - "anandSahib": { - "label": "Anand Sahib (Bhog)", - "labelType": "roman", - "type": "ceremony", - "ref": 3 - }, - "moolMantra": { - "label": "Mool Mantra", - "labelType": "roman", - "type": "text", - "ref": "<> siq nwmu krqw purKu inrBau inrvYru Akwl mUriq AjUnI sYBM gur pRswid ]" - }, - "waheguru": { - "label": "vwihgurU", - "labelType": "gurmukhi", - "type": "text", - "ref": "vwihgurU" - }, - "blank": { - "label": "Blank", - "labelType": "roman", - "type": "text", - "ref": "" + "anandSahib": { + "label": "Anand Sahib (Bhog)", + "labelType": "roman", + "type": "ceremony", + "ref": 3 + }, + "moolMantra": { + "label": "Mool Mantra", + "labelType": "roman", + "type": "textWithTranslations", + "ref": { + "gurmukhi": "<> siq nwmu krqw purKu inrBau inrvYru Akwl mUriq AjUnI sYBM gur pRswid ]", + "english": "One Universal Creator God. The Name Is Truth. Creative Being Personified. No Fear. No Hatred. Image Of The Undying, Beyond Birth, Self-Existent. By Guru's Grace ~", + "punjabi": "ਅਕਾਲ ਪੁਰਖ ਇੱਕ ਹੈ, ਜਿਸ ਦਾ ਨਾਮ 'ਹੋਂਦ ਵਾਲਾ' ਹੈ ਜੋ ਸ੍ਰਿਸ਼ਟੀ ਦਾ ਰਚਨਹਾਰ ਹੈ, ਜੋ ਸਭ ਵਿਚ ਵਿਆਪਕ ਹੈ, ਭੈ ਤੋਂ ਰਹਿਤ ਹੈ, ਵੈਰ-ਰਹਿਤ ਹੈ, ਜਿਸ ਦਾ ਸਰੂਪ ਕਾਲ ਤੋਂ ਪਰੇ ਹੈ, (ਭਾਵ, ਜਿਸ ਦਾ ਸਰੀਰ ਨਾਸ-ਰਹਿਤ ਹੈ), ਜੋ ਜੂਨਾਂ ਵਿਚ ਨਹੀਂ ਆਉਂਦਾ, ਜਿਸ ਦਾ ਪ੍ਰਕਾਸ਼ ਆਪਣੇ ਆਪ ਤੋਂ ਹੋਇਆ ਹੈ ਅਤੇ ਜੋ ਸਤਿਗੁਰੂ ਦੀ ਕਿਰਪਾ ਨਾਲ ਮਿਲਦਾ ਹੈ।", + "translit": " ikOankaar sat naam karataa purakh nirabhau niravair akaal moorat ajoonee saibha(n) gur prasaadh ||" } + }, + "waheguru": { + "label": "vwihgurU", + "labelType": "gurmukhi", + "type": "text", + "ref": "vwihgurU" + }, + "blank": { + "label": "Blank", + "labelType": "roman", + "type": "text", + "ref": "" + } } diff --git a/www/js/strings.js b/www/js/strings.js deleted file mode 100644 index 18d8ea285..000000000 --- a/www/js/strings.js +++ /dev/null @@ -1,57 +0,0 @@ -const slideStrings = { - waheguru: 'vwihgurU', - moolMantra: '<> siq nwmu krqw purKu inrBau inrvYru Akwl mUriq AjUnI sYBM gur pRswid ]', - dhanguruStrings: [ - 'DMn gurU nwnk dyv jI', - 'DMn gurU AMgd dyv jI', - 'DMn gurU Amrdwsu swihb jI', - 'DMn gurU rwmdws swihb jI', - 'DMn gurU Arjun dyv jI', - 'DMn gurU hir goibMd swihb jI', - 'DMn gurU hir rwie swihb jI', - 'DMn gurU hir ikRSx swihb jI', - 'DMn gurU qyg bhwdr swihb jI', - 'DMn gurU goibMd isMG swihb jI', - 'DMn gurU gRMQ swihb jI', - ], -}; -const dropdownStrings = { - gurus: [ - 'Guru Nanak Dev Ji', - 'Guru Angad Dev Ji', - 'Guru Amar Das Ji', - 'Guru Ram Das Ji', - 'Guru Arjan Dev Ji', - 'Guru Hargobind Sahib Ji', - 'Guru Har Rai Sahib Ji', - 'Guru Har Krishan Sahib Ji', - 'Guru Teg Bhadur Sahib Ji', - 'Guru Gobind Singh Ji', - 'Guru Granth Sahib Ji', - ], -}; -const announcemenetPlaceholder = { - english: 'Add announcement text here ..', - gurmukhi: 'GoSxw ie`Qy ilKo ...', -}; -const allowedAnnouncementTags = [ - 'b', - 'i', - 'em', - 'u', - 'pre', - 'strong', - 'div', - 'code', - 'br', - 'p', - 'ul', - 'li', - 'ol', -]; -module.exports = { - slideStrings, - dropdownStrings, - announcemenetPlaceholder, - allowedAnnouncementTags, -}; diff --git a/www/js/strings.json b/www/js/strings.json new file mode 100644 index 000000000..22dd93cbc --- /dev/null +++ b/www/js/strings.json @@ -0,0 +1,83 @@ +{ + "moolMantra": { + "gurmukhi": "<> siq nwmu krqw purKu inrBau inrvYru Akwl mUriq AjUnI sYBM gur pRswid ]", + "english": "One Universal Creator God. The Name Is Truth. Creative Being Personified. No Fear. No Hatred. Image Of The Undying, Beyond Birth, Self-Existent. By Guru's Grace ~", + "punjabi": "ਅਕਾਲ ਪੁਰਖ ਇੱਕ ਹੈ, ਜਿਸ ਦਾ ਨਾਮ 'ਹੋਂਦ ਵਾਲਾ' ਹੈ ਜੋ ਸ੍ਰਿਸ਼ਟੀ ਦਾ ਰਚਨਹਾਰ ਹੈ, ਜੋ ਸਭ ਵਿਚ ਵਿਆਪਕ ਹੈ, ਭੈ ਤੋਂ ਰਹਿਤ ਹੈ, ਵੈਰ-ਰਹਿਤ ਹੈ, ਜਿਸ ਦਾ ਸਰੂਪ ਕਾਲ ਤੋਂ ਪਰੇ ਹੈ, (ਭਾਵ, ਜਿਸ ਦਾ ਸਰੀਰ ਨਾਸ-ਰਹਿਤ ਹੈ), ਜੋ ਜੂਨਾਂ ਵਿਚ ਨਹੀਂ ਆਉਂਦਾ, ਜਿਸ ਦਾ ਪ੍ਰਕਾਸ਼ ਆਪਣੇ ਆਪ ਤੋਂ ਹੋਇਆ ਹੈ ਅਤੇ ਜੋ ਸਤਿਗੁਰੂ ਦੀ ਕਿਰਪਾ ਨਾਲ ਮਿਲਦਾ ਹੈ।", + "translit": " ikOankaar sat naam karataa purakh nirabhau niravair akaal moorat ajoonee saibha(n) gur prasaadh ||" + }, + "waheguru": "vwihgurU", + "dhanSlides": [ + { + "gurmukhi": "DMn gurU nwnk dyv swihb jI", + "english": "Great is Guru Nanak Dev Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU AMgd dyv swihb jI", + "english": "Great is Guru Angad Dev Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU Amrdwsu swihb jI", + "english": "Great is Guru Amar Daas Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU rwmdws swihb jI", + "english": "Great is Guru Ram Daas Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU Arjun dyv swihb jI", + "english": "Great is Guru Arjun Dev Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU hir goibMd swihb jI", + "english": "Great is Guru Har Gobind Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU hir rwie swihb jI", + "english": "Great is Guru Har Rai Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU hir ikRSx swihb jI", + "english": "Great is Guru Har Krishan Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU qyg bhwdr swihb jI", + "english": "Great is Guru Teg Bahadur Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn gurU goibMd isMG swihb jI", + "english": "Great is Guru Goind Singh Sahib Ji", + "punjabi": "", + "translit": "" + }, + { + "gurmukhi": "DMn SRI gurU gRMQ swihb jI", + "english": "Great is Guru Granth Sahib Ji", + "punjabi": "", + "translit": "" + } + ], + "announcement": { + "placeholder": { + "english": "Add announcement text here ..", + "gurmukhi": "GoSxw ie`Qy ilKo ..." + } + } +} diff --git a/www/js/viewer.js b/www/js/viewer.js index 802a9ce97..b50f4b70e 100644 --- a/www/js/viewer.js +++ b/www/js/viewer.js @@ -10,6 +10,7 @@ const h = require('hyperscript'); const scroll = require('scroll'); const { remote } = require('electron'); const { store } = require('electron').remote.require('./app'); +const anvaad = require('anvaad-js'); const slash = require('./js/slash'); const core = require('./js/index'); const themes = require('./js/themes.json'); @@ -37,7 +38,6 @@ const $scroll = window; $body.classList.add(process.platform); core.menu.settings.applySettings(prefs); - // Synchronize scrolling to presenter window $scroll.addEventListener( 'wheel', @@ -169,6 +169,10 @@ global.platform.ipc.on('show-text', (event, data) => { document.querySelector('.viewer-controls').innerHTML = ''; showText(data.text, data.isGurmukhi); }); +global.platform.ipc.on('show-text-with-translations', (event, data) => { + apv = document.body.classList.contains('akhandpaatt'); + textWithTranslations(data); +}); global.platform.ipc.on('send-scroll', (event, pos) => { $scroll.scrollTo( @@ -413,7 +417,7 @@ const showLine = (ShabadID, LineID, rows, mode) => { Object.assign(decks[ShabadID], shabad); break; case 'click': - /* if you click on verse when message is open (announcement, blank, waheguru) + /* if you click on verse when message is open (announcement, blank, waheguru) it should hide the message deck and show the shabad deck */ if ($message.classList.contains('active')) { $message.classList.remove('active'); @@ -426,7 +430,27 @@ const showLine = (ShabadID, LineID, rows, mode) => { } } }; +const textWithTranslations = obj => { + hideDecks(); + const line = obj.textWithTranslations; + let deck; + if (line.punjabi) { + deck = h('div#shabad.textTranslations.deck.active', [ + h('h1.gurbani.gurmukhi', line.gurmukhi), + h('h2.translation', line.english), + h('h2.teeka', line.punjabi || ''), + h('h2.transliteration', line.translit || anvaad.translit(line.gurmukhi)), + ]); + } else { + deck = h('div#shabad.textTranslations.deck.active', [ + h('h1.gurbani.gurmukhi', line.gurmukhi), + h('h2.translation', line.english), + h('h2.transliteration', line.translit || anvaad.translit(line.gurmukhi)), + ]); + } + $viewer.appendChild(deck); +}; const showText = (text, isGurmukhi = false) => { hideDecks();