logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: 1c3bdda14c0edf4ce321745bcf43e395635d6bf1
parent d5411c9f8809fad02b068f1b59dec59729aafd80
Author: Tusooa Zhu <tusooa@kazv.moe>
Date:   Tue, 20 Sep 2022 20:15:32 -0400

Load unicode emoji annotations

Diffstat:

Msrc/i18n/languages.js10+++++++++-
Msrc/modules/config.js1+
Msrc/modules/instance.js24++++++++++++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/i18n/languages.js b/src/i18n/languages.js @@ -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 } diff --git a/src/modules/config.js b/src/modules/config.js @@ -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': diff --git a/src/modules/instance.js b/src/modules/instance.js @@ -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')