Load unicode emoji annotations

This commit is contained in:
Tusooa Zhu 2022-09-20 20:15:32 -04:00
parent d5411c9f88
commit 1c3bdda14c
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
3 changed files with 34 additions and 1 deletions

View File

@ -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
}

View File

@ -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':

View File

@ -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')