feat: Add "no language" option to language picker

This commit is contained in:
Essem 2023-11-28 10:47:48 -06:00
parent e87b46863d
commit 8555496146
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 13 additions and 4 deletions

View file

@ -111,7 +111,7 @@ export const paramDef = {
text: { type: "string", maxLength: MAX_NOTE_TEXT_LENGTH, nullable: true },
lang: {
type: "string",
enum: Object.keys(langmap),
enum: [null, ...Object.keys(langmap)],
nullable: true,
},
cw: { type: "string", nullable: true, maxLength: 100 },

View file

@ -171,7 +171,7 @@ export const paramDef = {
text: { type: "string", maxLength: MAX_NOTE_TEXT_LENGTH, nullable: true },
lang: {
type: "string",
enum: Object.keys(langmap),
enum: [null, ...Object.keys(langmap)],
nullable: true,
},
cw: { type: "string", nullable: true, maxLength: 250 },

View file

@ -708,7 +708,7 @@ function setVisibility() {
);
}
const language = ref<string>(
const language = ref<string | null>(
props.initialLanguage ??
defaultStore.state.recentlyUsedPostLanguages[0] ??
localStorage.getItem("lang")?.split("-")[0],
@ -717,7 +717,7 @@ const language = ref<string>(
function filterLangmapByPrefix(
prefix: string,
): { langCode: string; nativeName: string }[] {
const to_return = Object.entries(langmap)
let to_return = Object.entries(langmap)
.filter(([langCode, _]) => langCode.startsWith(prefix))
.map(([langCode, v]) => {
return { langCode, nativeName: v.nativeName };
@ -781,6 +781,15 @@ function setLanguage() {
}
if (recentlyUsedLanguagesExist) actions.push(null);
actions.push({
text: i18n.ts.noLanguage,
danger: false,
active: false,
action: () => {
language.value = null;
},
});
for (const lang of langs) {
if (lang === language.value) continue;
if (defaultStore.state.recentlyUsedPostLanguages.includes(lang))