mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-11 13:52:19 +00:00
Merge pull request #1561 from bilawalsidhu/german/chat-autocomplete-arabic-marks
Ignore Arabic short vowels and shadda in chat autocomplete
This commit is contained in:
3 files changed
+28
-6
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
- Chat autocomplete finds Arabic suggestions typed without short vowels or
|
||||||
|
shadda, so «تتبع» now suggests «اعرض تتبّع الرحلات المباشر»
|
||||||
|
(German, @gekh, #1561).
|
||||||
@@ -22,6 +22,10 @@ export function bindChatPreferences({ ui, getDraft, setDraft }) {
|
|||||||
msg('Reset to globe view'),
|
msg('Reset to globe view'),
|
||||||
msg('Show earthquakes'),
|
msg('Show earthquakes'),
|
||||||
].map((text) => t(text));
|
].map((text) => t(text));
|
||||||
|
// Arabic short vowels and shadda are optional in writing: typing "تتبع"
|
||||||
|
// still finds "تتبّع".
|
||||||
|
const fold = (text) =>
|
||||||
|
text.toLowerCase().replace(/[\u064B-\u065F\u0670]/g, '');
|
||||||
try {
|
try {
|
||||||
const stored = JSON.parse(localStorage.getItem(key));
|
const stored = JSON.parse(localStorage.getItem(key));
|
||||||
if (typeof stored?.quick === 'boolean') quick = stored.quick;
|
if (typeof stored?.quick === 'boolean') quick = stored.quick;
|
||||||
@@ -31,18 +35,14 @@ export function bindChatPreferences({ ui, getDraft, setDraft }) {
|
|||||||
function render() {
|
function render() {
|
||||||
const draft = getDraft();
|
const draft = getDraft();
|
||||||
if (historyIndex >= 0 && draft !== recent[historyIndex]) resetHistory();
|
if (historyIndex >= 0 && draft !== recent[historyIndex]) resetHistory();
|
||||||
const query = draft.trim().toLowerCase();
|
const query = fold(draft.trim());
|
||||||
const groups = [];
|
const groups = [];
|
||||||
if (query) {
|
if (query) {
|
||||||
const candidates = [...recent, ...(quick ? quickCommands() : [])];
|
const candidates = [...recent, ...(quick ? quickCommands() : [])];
|
||||||
groups.push({
|
groups.push({
|
||||||
label: t('Suggestions'),
|
label: t('Suggestions'),
|
||||||
items: [...new Set(candidates)]
|
items: [...new Set(candidates)]
|
||||||
.filter(
|
.filter((text) => fold(text).includes(query) && fold(text) !== query)
|
||||||
(text) =>
|
|
||||||
text.toLowerCase().includes(query) &&
|
|
||||||
text.toLowerCase() !== query,
|
|
||||||
)
|
|
||||||
.slice(0, 4),
|
.slice(0, 4),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
|
import { setLocale } from '../i18n/index.js';
|
||||||
import { bindChatPreferences } from './chatPreferences.js';
|
import { bindChatPreferences } from './chatPreferences.js';
|
||||||
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
|
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
|
||||||
|
|
||||||
@@ -99,3 +100,21 @@ test('editing a recalled message ends recall, and sending resets it', (t) => {
|
|||||||
press('ArrowUp');
|
press('ArrowUp');
|
||||||
assert.equal(field.value, 'Show live flights now');
|
assert.equal(field.value, 'Show live flights now');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('autocomplete ignores Arabic short vowels and shadda', (t) => {
|
||||||
|
setLocale('ar');
|
||||||
|
t.after(() => setLocale('en'));
|
||||||
|
const ui = createTestVoiceUi();
|
||||||
|
let draft = '';
|
||||||
|
const prefs = bindChatPreferences({ ui, getDraft: () => draft });
|
||||||
|
t.after(() => prefs.destroy());
|
||||||
|
const suggested = (text) => {
|
||||||
|
draft = text;
|
||||||
|
prefs.render();
|
||||||
|
return ui.state.chat.suggestions.flatMap((group) => group.items);
|
||||||
|
};
|
||||||
|
// The quick command is written "تتبّع", with a shadda.
|
||||||
|
assert.deepEqual(suggested('تتبع'), ['اعرض تتبّع الرحلات المباشر']);
|
||||||
|
prefs.remember('انتقل إلى طوكيو');
|
||||||
|
assert.deepEqual(suggested('طُوكيو'), ['انتقل إلى طوكيو']);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user