Load unicode emoji annotations
This commit is contained in:
parent
d5411c9f88
commit
1c3bdda14c
|
@ -38,7 +38,15 @@ const specialJsonName = {
|
|||
|
||||
const langCodeToJsonName = (code) => specialJsonName[code] || code
|
||||
|
||||
const langCodeToCldrName = (code) => code
|
||||
|
||||
const ensureFinalFallback = codes => {
|
||||
return codes.includes('en') ? codes : codes.concat(['en'])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
languages,
|
||||
langCodeToJsonName
|
||||
langCodeToJsonName,
|
||||
langCodeToCldrName,
|
||||
ensureFinalFallback
|
||||
}
|
||||
|
|
|
@ -183,6 +183,7 @@ const config = {
|
|||
break
|
||||
case 'interfaceLanguage':
|
||||
messages.setLanguage(this.getters.i18n, value)
|
||||
dispatch('loadUnicodeEmojiData', value)
|
||||
Cookies.set(BACKEND_LANGUAGE_COOKIE_NAME, localeService.internalToBackendLocale(value))
|
||||
break
|
||||
case 'thirdColumnMode':
|
||||
|
|
|
@ -2,6 +2,7 @@ import { getPreset, applyTheme } from '../services/style_setter/style_setter.js'
|
|||
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import { instanceDefaultProperties } from './config.js'
|
||||
import { langCodeToCldrName, ensureFinalFallback } from '../i18n/languages.js'
|
||||
|
||||
const SORTED_EMOJI_GROUP_IDS = [
|
||||
'smileys-and-emotion',
|
||||
|
@ -78,6 +79,7 @@ const defaultState = {
|
|||
customEmojiFetched: false,
|
||||
emoji: {},
|
||||
emojiFetched: false,
|
||||
unicodeEmojiAnnotations: {},
|
||||
pleromaBackend: true,
|
||||
postFormats: [],
|
||||
restrictedNicknames: [],
|
||||
|
@ -109,6 +111,12 @@ const defaultState = {
|
|||
}
|
||||
}
|
||||
|
||||
const loadAnnotations = (lang) => {
|
||||
return import(
|
||||
`@kazvmoe-infra/unicode-emoji-json/annotations/${langCodeToCldrName(lang)}.json`
|
||||
)
|
||||
}
|
||||
|
||||
const instance = {
|
||||
state: defaultState,
|
||||
mutations: {
|
||||
|
@ -119,6 +127,9 @@ const instance = {
|
|||
},
|
||||
setKnownDomains (state, domains) {
|
||||
state.knownDomains = domains
|
||||
},
|
||||
setUnicodeEmojiAnnotations (state, { lang, annotations }) {
|
||||
state.unicodeEmojiAnnotations[lang] = annotations
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
|
@ -206,6 +217,19 @@ const instance = {
|
|||
}
|
||||
},
|
||||
|
||||
loadUnicodeEmojiData ({ commit, state }, language) {
|
||||
const langList = ensureFinalFallback(Array.isArray(language) ? language : [language])
|
||||
|
||||
return Promise.all(
|
||||
langList
|
||||
.forEach(async lang => {
|
||||
if (!state.unicodeEmojiAnnotations[lang]) {
|
||||
const annotations = await loadAnnotations(lang)
|
||||
commit('setUnicodeEmojiAnnotations', { lang, annotations })
|
||||
}
|
||||
}))
|
||||
},
|
||||
|
||||
async getCustomEmoji ({ commit, state }) {
|
||||
try {
|
||||
const res = await window.fetch('/api/pleroma/emoji.json')
|
||||
|
|
Loading…
Reference in New Issue