Skip to content
Merged
Changes from all commits
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
45 changes: 30 additions & 15 deletions src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -377,26 +377,41 @@ export default {
},

async loadEditorTranslations(language) {
if (language === 'en') {
// CKEditor uses lowercase locale codes (e.g. "de-ch" instead of "de-CH")
const ckeditorLanguage = language.toLowerCase()

if (ckeditorLanguage === 'en') {
// The default, nothing to fetch
return this.showEditor('en')
this.showEditor('en')
return
}

try {
logger.debug(`loading ${language} translations for CKEditor`)

/* eslint-disable @stylistic/comma-dangle, @stylistic/function-paren-newline */
const { default: coreTranslations } = await import(
/* webpackMode: "lazy" */
`ckeditor5/translations/${language}.js`
)
/* eslint-enable @stylistic/comma-dangle, @stylistic/function-paren-newline */
// Try exact match first (e.g. "de-ch"), then language only (e.g. "de"), then fall back to "en"
const candidates = [ckeditorLanguage]
if (ckeditorLanguage.includes('-')) {
candidates.push(ckeditorLanguage.split('-')[0])
}

this.showEditor(language, [coreTranslations])
} catch (error) {
logger.error(`could not find CKEditor translations for "${language}"`, { error })
this.showEditor('en')
for (const candidate of candidates) {
try {
logger.debug(`loading "${candidate}" translations for CKEditor`)

/* eslint-disable @stylistic/comma-dangle, @stylistic/function-paren-newline */
const { default: coreTranslations } = await import(
/* webpackMode: "lazy" */
`ckeditor5/translations/${candidate}.js`
)
/* eslint-enable @stylistic/comma-dangle, @stylistic/function-paren-newline */

this.showEditor(candidate, [coreTranslations])
return
} catch (error) {
logger.debug(`no CKEditor translations for "${candidate}"`, { error })
}
}

logger.info(`no CKEditor translations found for "${language}", falling back to English`)
this.showEditor('en')
},

showEditor(language, translations) {
Expand Down
Loading