Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x | import { okButtonEl, cancelButtonEl, isDynamicSelect } from '../../utils/dynamic-select-dom.js'
import { getLanguageFromElement } from '../../utils/get-lang-from-element.util.js'
/** @import {DynamicSelect} from '../../utils/dynamic-select-dom' */
export const i18nButtonLabels = Object.freeze({
ok: {
default: 'OK',
es: 'Aceptar',
ar: 'موافق',
hi: 'ठीक है',
tr: 'Tamam',
zh: '确定',
ko: '확인',
},
cancel: {
default: 'Cancel',
es: 'Cancelar',
zh: '取消',
hi: 'रद्द करें',
ar: 'إلغاء',
tr: 'İptal',
fr: 'Annuler',
pt: 'Cancelar',
ru: 'Отмена',
id: 'Batal',
de: 'Abbrechen',
ja: 'キャンセル',
vi: 'Hủy',
ko: '취소',
it: 'Annulla',
pl: 'Anuluj',
uk: 'Скасувати',
},
})
const mutationObserver = new MutationObserver(records => {
for (const record of records) {
const { target } = record
if (!isDynamicSelect(target) || !target.open) {
continue
}
const lang = getLanguageFromElement(target)
const locale = new Intl.Locale(lang)
const language = locale.language
const okButton = okButtonEl(target)
const { ok, cancel } = i18nButtonLabels
okButton.textContent = Object.hasOwn(ok, language) ? ok[language] : ok.default
const cancelButton = cancelButtonEl(target)
cancelButton.textContent = Object.hasOwn(cancel, language) ? cancel[language] : cancel.default
}
})
const mutationObserverInit = { attributeFilter: ['open'] }
/**
* @param {DynamicSelect} select - target select
*/
export function applyI18nOnSelectInputs (select) {
mutationObserver.observe(select, mutationObserverInit)
}
|