Display localized unicode emoji names
This commit is contained in:
parent
1c3bdda14c
commit
a73f9731f5
|
@ -1,6 +1,7 @@
|
||||||
import { defineAsyncComponent } from 'vue'
|
import { defineAsyncComponent } from 'vue'
|
||||||
import Checkbox from '../checkbox/checkbox.vue'
|
import Checkbox from '../checkbox/checkbox.vue'
|
||||||
import StillImage from '../still-image/still-image.vue'
|
import StillImage from '../still-image/still-image.vue'
|
||||||
|
import { ensureFinalFallback } from '../../i18n/languages.js'
|
||||||
import lozad from 'lozad'
|
import lozad from 'lozad'
|
||||||
import { library } from '@fortawesome/fontawesome-svg-core'
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||||
import {
|
import {
|
||||||
|
@ -285,6 +286,25 @@ const EmojiPicker = {
|
||||||
this.waitForDomAndInitializeLazyLoad()
|
this.waitForDomAndInitializeLazyLoad()
|
||||||
this.filteredEmojiGroups = this.getFilteredEmojiGroups()
|
this.filteredEmojiGroups = this.getFilteredEmojiGroups()
|
||||||
}, 500)
|
}, 500)
|
||||||
|
},
|
||||||
|
languages () {
|
||||||
|
console.log('languages:', ensureFinalFallback(this.$store.getters.mergedConfig.interfaceLanguage))
|
||||||
|
return ensureFinalFallback(this.$store.getters.mergedConfig.interfaceLanguage)
|
||||||
|
},
|
||||||
|
maybeLocalizedEmojiName () {
|
||||||
|
return emoji => {
|
||||||
|
if (!emoji.annotations) {
|
||||||
|
return emoji.displayText
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const lang of this.languages) {
|
||||||
|
if (emoji.annotations[lang]?.name) {
|
||||||
|
return emoji.annotations[lang].name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return emoji.displayText
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
<span
|
<span
|
||||||
v-for="emoji in group.emojis"
|
v-for="emoji in group.emojis"
|
||||||
:key="group.id + emoji.displayText"
|
:key="group.id + emoji.displayText"
|
||||||
:title="emoji.displayText"
|
:title="maybeLocalizedEmojiName(emoji)"
|
||||||
class="emoji-item"
|
class="emoji-item"
|
||||||
@click.stop.prevent="onEmoji(emoji)"
|
@click.stop.prevent="onEmoji(emoji)"
|
||||||
>
|
>
|
||||||
|
|
|
@ -41,7 +41,8 @@ const langCodeToJsonName = (code) => specialJsonName[code] || code
|
||||||
const langCodeToCldrName = (code) => code
|
const langCodeToCldrName = (code) => code
|
||||||
|
|
||||||
const ensureFinalFallback = codes => {
|
const ensureFinalFallback = codes => {
|
||||||
return codes.includes('en') ? codes : codes.concat(['en'])
|
const codeList = Array.isArray(codes) ? codes : [codes]
|
||||||
|
return codeList.includes('en') ? codeList : codeList.concat(['en'])
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -117,6 +117,18 @@ const loadAnnotations = (lang) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const injectAnnotations = (emoji, annotations) => {
|
||||||
|
const availableLangs = Object.keys(annotations)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...emoji,
|
||||||
|
annotations: availableLangs.reduce((acc, cur) => {
|
||||||
|
acc[cur] = annotations[cur][emoji.replacement]
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const instance = {
|
const instance = {
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -164,13 +176,13 @@ const instance = {
|
||||||
},
|
},
|
||||||
standardEmojiList (state) {
|
standardEmojiList (state) {
|
||||||
return SORTED_EMOJI_GROUP_IDS
|
return SORTED_EMOJI_GROUP_IDS
|
||||||
.map(groupId => state.emoji[groupId] || [])
|
.map(groupId => (state.emoji[groupId] || []).map(k => injectAnnotations(k, state.unicodeEmojiAnnotations)))
|
||||||
.reduce((a, b) => a.concat(b), [])
|
.reduce((a, b) => a.concat(b), [])
|
||||||
},
|
},
|
||||||
standardEmojiGroupList (state) {
|
standardEmojiGroupList (state) {
|
||||||
return SORTED_EMOJI_GROUP_IDS.map(groupId => ({
|
return SORTED_EMOJI_GROUP_IDS.map(groupId => ({
|
||||||
id: groupId,
|
id: groupId,
|
||||||
emojis: state.emoji[groupId] || []
|
emojis: (state.emoji[groupId] || []).map(k => injectAnnotations(k, state.unicodeEmojiAnnotations))
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
instanceDomain (state) {
|
instanceDomain (state) {
|
||||||
|
@ -218,7 +230,7 @@ const instance = {
|
||||||
},
|
},
|
||||||
|
|
||||||
loadUnicodeEmojiData ({ commit, state }, language) {
|
loadUnicodeEmojiData ({ commit, state }, language) {
|
||||||
const langList = ensureFinalFallback(Array.isArray(language) ? language : [language])
|
const langList = ensureFinalFallback(language)
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
langList
|
langList
|
||||||
|
|
Loading…
Reference in a new issue