Fallback to emoji-datasource for unlocalized emoji
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
0607f01540
commit
48b78e7e35
3 changed files with 34 additions and 6 deletions
|
@ -130,9 +130,10 @@ function useFunEmojiSearchIndex(
|
||||||
localeEmojiList: LocaleEmojiListType | null
|
localeEmojiList: LocaleEmojiListType | null
|
||||||
): FunEmojiSearchIndex {
|
): FunEmojiSearchIndex {
|
||||||
const funEmojiSearchIndex = useMemo(() => {
|
const funEmojiSearchIndex = useMemo(() => {
|
||||||
|
const defaultSearchIndex = getEmojiDefaultEnglishSearchIndex();
|
||||||
return localeEmojiList != null
|
return localeEmojiList != null
|
||||||
? createFunEmojiSearchIndex(localeEmojiList)
|
? createFunEmojiSearchIndex(localeEmojiList, defaultSearchIndex)
|
||||||
: getEmojiDefaultEnglishSearchIndex();
|
: defaultSearchIndex;
|
||||||
}, [localeEmojiList]);
|
}, [localeEmojiList]);
|
||||||
return funEmojiSearchIndex;
|
return funEmojiSearchIndex;
|
||||||
}
|
}
|
||||||
|
@ -141,9 +142,10 @@ function useFunEmojiLocalizerIndex(
|
||||||
localeEmojiList: LocaleEmojiListType | null
|
localeEmojiList: LocaleEmojiListType | null
|
||||||
): FunEmojiLocalizerIndex {
|
): FunEmojiLocalizerIndex {
|
||||||
const funEmojiLocalizerIndex = useMemo(() => {
|
const funEmojiLocalizerIndex = useMemo(() => {
|
||||||
|
const defaultSearchIndex = getEmojiDefaultEnglishLocalizerIndex();
|
||||||
return localeEmojiList != null
|
return localeEmojiList != null
|
||||||
? createFunEmojiLocalizerIndex(localeEmojiList)
|
? createFunEmojiLocalizerIndex(localeEmojiList, defaultSearchIndex)
|
||||||
: getEmojiDefaultEnglishLocalizerIndex();
|
: defaultSearchIndex;
|
||||||
}, [localeEmojiList]);
|
}, [localeEmojiList]);
|
||||||
return funEmojiLocalizerIndex;
|
return funEmojiLocalizerIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ export type FunEmojiLocalizer = Readonly<{
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export function createFunEmojiLocalizerIndex(
|
export function createFunEmojiLocalizerIndex(
|
||||||
localeEmojiList: LocaleEmojiListType
|
localeEmojiList: LocaleEmojiListType,
|
||||||
|
defaultLocalizerIndex?: FunEmojiLocalizerIndex
|
||||||
): FunEmojiLocalizerIndex {
|
): FunEmojiLocalizerIndex {
|
||||||
const parentKeyToLocaleShortName = new Map<EmojiParentKey, string>();
|
const parentKeyToLocaleShortName = new Map<EmojiParentKey, string>();
|
||||||
const localeShortNameToParentKey = new Map<string, EmojiParentKey>();
|
const localeShortNameToParentKey = new Map<string, EmojiParentKey>();
|
||||||
|
@ -37,10 +38,25 @@ export function createFunEmojiLocalizerIndex(
|
||||||
const variantKey = getEmojiVariantKeyByValue(entry.emoji);
|
const variantKey = getEmojiVariantKeyByValue(entry.emoji);
|
||||||
const parentKey = getEmojiParentKeyByVariantKey(variantKey);
|
const parentKey = getEmojiParentKeyByVariantKey(variantKey);
|
||||||
const localizedShortName = entry.tags.at(0) ?? entry.shortName;
|
const localizedShortName = entry.tags.at(0) ?? entry.shortName;
|
||||||
|
|
||||||
parentKeyToLocaleShortName.set(parentKey, localizedShortName);
|
parentKeyToLocaleShortName.set(parentKey, localizedShortName);
|
||||||
localeShortNameToParentKey.set(localizedShortName, parentKey);
|
localeShortNameToParentKey.set(localizedShortName, parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defaultLocalizerIndex != null) {
|
||||||
|
for (const [
|
||||||
|
parentKey,
|
||||||
|
defaultShortName,
|
||||||
|
] of defaultLocalizerIndex.parentKeyToLocaleShortName) {
|
||||||
|
if (parentKeyToLocaleShortName.has(parentKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentKeyToLocaleShortName.set(parentKey, defaultShortName);
|
||||||
|
localeShortNameToParentKey.set(defaultShortName, parentKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { parentKeyToLocaleShortName, localeShortNameToParentKey };
|
return { parentKeyToLocaleShortName, localeShortNameToParentKey };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,13 @@ export type FunEmojiSearch = (
|
||||||
) => ReadonlyArray<FunEmojiSearchResult>;
|
) => ReadonlyArray<FunEmojiSearchResult>;
|
||||||
|
|
||||||
export function createFunEmojiSearchIndex(
|
export function createFunEmojiSearchIndex(
|
||||||
localeEmojiList: LocaleEmojiListType
|
localeEmojiList: LocaleEmojiListType,
|
||||||
|
defaultSearchIndex: ReadonlyArray<FunEmojiSearchIndexEntry> = []
|
||||||
): FunEmojiSearchIndex {
|
): FunEmojiSearchIndex {
|
||||||
const results: Array<FunEmojiSearchIndexEntry> = [];
|
const results: Array<FunEmojiSearchIndexEntry> = [];
|
||||||
|
|
||||||
|
const localizedKeys = new Set<string>();
|
||||||
|
|
||||||
for (const localeEmoji of localeEmojiList) {
|
for (const localeEmoji of localeEmojiList) {
|
||||||
if (!isEmojiParentValue(localeEmoji.emoji)) {
|
if (!isEmojiParentValue(localeEmoji.emoji)) {
|
||||||
// Skipping unknown emoji, most likely apple doesn't support it
|
// Skipping unknown emoji, most likely apple doesn't support it
|
||||||
|
@ -54,6 +57,7 @@ export function createFunEmojiSearchIndex(
|
||||||
|
|
||||||
const parentKey = getEmojiParentKeyByValue(localeEmoji.emoji);
|
const parentKey = getEmojiParentKeyByValue(localeEmoji.emoji);
|
||||||
const emoji = getEmojiParentByKey(parentKey);
|
const emoji = getEmojiParentByKey(parentKey);
|
||||||
|
localizedKeys.add(parentKey);
|
||||||
results.push({
|
results.push({
|
||||||
key: parentKey,
|
key: parentKey,
|
||||||
rank: localeEmoji.rank,
|
rank: localeEmoji.rank,
|
||||||
|
@ -66,6 +70,12 @@ export function createFunEmojiSearchIndex(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const defaultEntry of defaultSearchIndex) {
|
||||||
|
if (!localizedKeys.has(defaultEntry.key)) {
|
||||||
|
results.push(defaultEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue