diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 3d23083f..82af8101 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -331,7 +331,7 @@ const browserPrefersDark = () => { const mailto = (address) => window.location.href = 'mailto:' + address; // build OpenLyrics XML for given song -const openLyricsXML = (song, version, locales = [], allTags = null) => { +const openLyricsXML = (song, version, translatedSong = null, locales = [], allTags = null) => { const timestamp = (new Date()).toISOString().slice(0, -5); const title = `${song.title}`; const subtitle = song.subtitle ? `${song.subtitle}` : ''; @@ -348,13 +348,18 @@ const openLyricsXML = (song, version, locales = [], allTags = null) => { tag => locales.map(l =>`${allTags[tag][l] ?? tag.key}`).join('') ).join('') + '' : ''; - const lyrics = parsedContent(song.content, song.tuning, false, false).map(p => { + const format = translatedSong ? `<em></em>False<span style='-webkit-text-fill-color:#c2c2a3'></span>False` : ''; + const tParts = translatedSong ? parsedContent(translatedSong.content, 0, false, false) : []; + const lyrics = parsedContent(song.content, 0, false, false).map((p, i) => { const type = p.type ? p.type.toUpperCase() : 'V'; const num = p.number > 0 ? p.number : '1'; - return `` + p.content.replace(/\n/g, "
") + '
' + const tContent = (i in tParts) + ? `

${tParts[i].content.replace(/\n/g, "
")}
` + : ''; + return `${p.content.replace(/\n/g, "
")}${tContent}
`; }).join(''); - return `${title}${subtitle}${copyright}${year}${ccli}${authors}${tags}${lyrics}`; + return `${title}${subtitle}${copyright}${year}${ccli}${authors}${tags}${format}${lyrics}`; }; export { diff --git a/frontend/src/views/SetlistShow.vue b/frontend/src/views/SetlistShow.vue index 669c97d2..fdcf6be4 100644 --- a/frontend/src/views/SetlistShow.vue +++ b/frontend/src/views/SetlistShow.vue @@ -545,13 +545,13 @@ const emit = defineEmits(['editSong', 'editSetlist']); // component properties const props = defineProps({ - languages: Object, - ready: Object, - role: Number, - setlists: Object, - songs: Object, - user: String, - users: Object, + languages: Object, + ready: Object, + role: Number, + setlists: Object, + songs: Object, + user: String, + users: Object, }); // reactive data @@ -981,12 +981,20 @@ const exportOsz = async () => { if (setlist.value.songs.hasOwnProperty(key) && setlist.value.songs[key].id in props.songs) { // get song object const song = props.songs[setlist.value.songs[key].id]; + // check for translations + const lang = !('lang' in localStorage) ? locale.value : localStorage.getItem('lang'); + let tSong = null; + if (lang !== song.language && song.translations.length > 0) { + const tKey = song.translations.find((t) => t.endsWith(`-${lang}`)); + tSong = props.songs[tKey]; + } // handle song content parts - let itemData = []; - let parts = parsedContent(song.content, 0, false, false); - parts.forEach((part) => { + const itemData = []; + const parts = parsedContent(song.content, 0, false, false); + const tParts = tSong ? parsedContent(tSong.content, 0, false, false) : []; + parts.forEach((part, i) => { itemData.push({ - 'raw_slide': part.content, + 'raw_slide': (i in tParts) ? part.content + "\n\n" + tParts[i].content : part.content, 'verseTag': (part.type ? part.type.toUpperCase() : 'V') + (part.number > 0 ? part.number.toString() : '1'), }); }); @@ -1014,7 +1022,7 @@ const exportOsz = async () => { 'ccli_number': song.ccli, 'copyright': song.publisher }, - 'xml_version': openLyricsXML(song, version), + 'xml_version': openLyricsXML(song, version, tSong), 'auto_play_slides_once': false, 'auto_play_slides_loop': false, 'timed_slide_interval': 0, diff --git a/frontend/src/views/SongShow.vue b/frontend/src/views/SongShow.vue index 5ead76c1..2beae47b 100644 --- a/frontend/src/views/SongShow.vue +++ b/frontend/src/views/SongShow.vue @@ -525,7 +525,7 @@ const exportSng = () => { // export song in OpenLyrics XML format const exportXml = () => { // start download - download(openLyricsXML(song.value, version, availableLocales, props.tags), songId + '.xml'); + download(openLyricsXML(song.value, version, null, availableLocales, props.tags), songId + '.xml'); // toast success message notify({ title: t('toast.exportedXml'),