Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement event listener for notifying when translations are ready #1772

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions resource/js/tab-alpha.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */
/* global partialPageLoad, getConceptURL, fetchWithAbort */

function startAlphaApp () {
Expand Down Expand Up @@ -245,12 +245,4 @@ function startAlphaApp () {
tabAlphaApp.mount('#tab-alphabetical')
}

const waitForTranslationServiceTabAlpha = () => {
if (typeof $t !== 'undefined') {
startAlphaApp()
} else {
setTimeout(waitForTranslationServiceTabAlpha, 50)
}
}

waitForTranslationServiceTabAlpha()
onTranslationReady(startAlphaApp)
12 changes: 2 additions & 10 deletions resource/js/tab-changes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */
/* global partialPageLoad, getConceptURL */

function startChangesApp () {
Expand Down Expand Up @@ -167,12 +167,4 @@ function startChangesApp () {
tabChangesApp.mount('#tab-changes')
}

const waitForTranslationServiceTabChanges = () => {
if (typeof $t !== 'undefined') {
startChangesApp()
} else {
setTimeout(waitForTranslationServiceTabChanges, 50)
}
}

waitForTranslationServiceTabChanges()
onTranslationReady(startChangesApp)
12 changes: 2 additions & 10 deletions resource/js/tab-hierarchy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */
/* global partialPageLoad, getConceptURL */

function startHierarchyApp () {
Expand Down Expand Up @@ -368,12 +368,4 @@ function startHierarchyApp () {
tabHierApp.mount('#tab-hierarchy')
}

const waitForTranslationServiceTabHierarchy = () => {
if (typeof $t !== 'undefined') {
startHierarchyApp()
} else {
setTimeout(waitForTranslationServiceTabHierarchy, 50)
}
}

waitForTranslationServiceTabHierarchy()
onTranslationReady(startHierarchyApp)
12 changes: 2 additions & 10 deletions resource/js/term-counts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */

function startTermCountsApp () {
const termCountsApp = Vue.createApp({
Expand Down Expand Up @@ -69,12 +69,4 @@ function startTermCountsApp () {
termCountsApp.mount('#term-counts')
}

function waitForTermTranslationService () {
if (typeof $t !== 'undefined') {
startTermCountsApp()
} else {
setTimeout(waitForTermTranslationService, 50)
}
}

waitForTermTranslationService()
onTranslationReady(startTermCountsApp)
11 changes: 9 additions & 2 deletions resource/js/translation-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* global $t:writable */
/* exported $t */
/* global $t:writable, onTranslationReady:writable */
/* exported $t, onTranslationReady */

(async function () {
const translationCallbacks = []

async function loadLocaleMessages (locale) {
const messages = {}
try {
Expand All @@ -20,6 +22,11 @@
$t = function (key) {
return translations[key] || key
}
translationCallbacks.forEach(callback => callback())
}

onTranslationReady = function (callback) {
translationCallbacks.push(callback)
}

await initializeTranslations(window.SKOSMOS.lang || 'en')
Expand Down
12 changes: 2 additions & 10 deletions resource/js/vocab-counts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */

function startResourceCountsApp () {
const resourceCountsApp = Vue.createApp({
Expand Down Expand Up @@ -76,12 +76,4 @@ function startResourceCountsApp () {
resourceCountsApp.mount('#resource-counts')
}

const waitForTranslationServiceVocabCounts = () => {
if (typeof $t !== 'undefined') {
startResourceCountsApp()
} else {
setTimeout(waitForTranslationServiceVocabCounts, 50)
}
}

waitForTranslationServiceVocabCounts()
onTranslationReady(startResourceCountsApp)
12 changes: 2 additions & 10 deletions resource/js/vocab-search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, $t */
/* global Vue, $t, onTranslationReady */

function startVocabSearchApp () {
const vocabSearch = Vue.createApp({
Expand Down Expand Up @@ -370,12 +370,4 @@ function startVocabSearchApp () {
vocabSearch.mount('#search-vocab')
}

const waitForTranslationServiceVocabSearch = () => {
if (typeof $t !== 'undefined') {
startVocabSearchApp()
} else {
setTimeout(waitForTranslationServiceVocabSearch, 50)
}
}

waitForTranslationServiceVocabSearch()
onTranslationReady(startVocabSearchApp)