Merge branch 'language-code' into 'main'

Upgrade npm:iso-639-1, remove LanguageCode type assertions

See merge request soapbox-pub/ditto!637
This commit is contained in:
Alex Gleason 2025-02-05 16:36:22 +00:00
commit 68db1a391c
7 changed files with 10 additions and 10 deletions

View file

@ -72,7 +72,7 @@
"fast-stable-stringify": "npm:fast-stable-stringify@^1.0.0", "fast-stable-stringify": "npm:fast-stable-stringify@^1.0.0",
"formdata-helper": "npm:formdata-helper@^0.3.0", "formdata-helper": "npm:formdata-helper@^0.3.0",
"hono-rate-limiter": "npm:hono-rate-limiter@^0.3.0", "hono-rate-limiter": "npm:hono-rate-limiter@^0.3.0",
"iso-639-1": "npm:iso-639-1@2.1.15", "iso-639-1": "npm:iso-639-1@^3.1.5",
"isomorphic-dompurify": "npm:isomorphic-dompurify@^2.16.0", "isomorphic-dompurify": "npm:isomorphic-dompurify@^2.16.0",
"kysely": "npm:kysely@^0.27.4", "kysely": "npm:kysely@^0.27.4",
"kysely-postgres-js": "npm:kysely-postgres-js@2.0.0", "kysely-postgres-js": "npm:kysely-postgres-js@2.0.0",

8
deno.lock generated
View file

@ -101,7 +101,7 @@
"npm:fast-stable-stringify@1": "1.0.0", "npm:fast-stable-stringify@1": "1.0.0",
"npm:formdata-helper@0.3": "0.3.0", "npm:formdata-helper@0.3": "0.3.0",
"npm:hono-rate-limiter@0.3": "0.3.0_hono@4.2.5", "npm:hono-rate-limiter@0.3": "0.3.0_hono@4.2.5",
"npm:iso-639-1@2.1.15": "2.1.15", "npm:iso-639-1@^3.1.5": "3.1.5",
"npm:isomorphic-dompurify@^2.16.0": "2.16.0", "npm:isomorphic-dompurify@^2.16.0": "2.16.0",
"npm:kysely-postgres-js@2.0.0": "2.0.0_kysely@0.27.3_postgres@3.4.4", "npm:kysely-postgres-js@2.0.0": "2.0.0_kysely@0.27.3_postgres@3.4.4",
"npm:kysely@~0.27.2": "0.27.4", "npm:kysely@~0.27.2": "0.27.4",
@ -1211,8 +1211,8 @@
"isexe@2.0.0": { "isexe@2.0.0": {
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
}, },
"iso-639-1@2.1.15": { "iso-639-1@3.1.5": {
"integrity": "sha512-7c7mBznZu2ktfvyT582E2msM+Udc1EjOyhVRE/0ZsjD9LBtWSm23h3PtiRh2a35XoUsTQQjJXaJzuLjXsOdFDg==" "integrity": "sha512-gXkz5+KN7HrG0Q5UGqSMO2qB9AsbEeyLP54kF1YrMsIxmu+g4BdB7rflReZTSTZGpfj8wywu6pfPBCylPIzGQA=="
}, },
"isomorphic-dompurify@2.16.0": { "isomorphic-dompurify@2.16.0": {
"integrity": "sha512-cXhX2owp8rPxafCr0ywqy2CGI/4ceLNgWkWBEvUz64KTbtg3oRL2ZRqq/zW0pzt4YtDjkHLbwcp/lozpKzAQjg==", "integrity": "sha512-cXhX2owp8rPxafCr0ywqy2CGI/4ceLNgWkWBEvUz64KTbtg3oRL2ZRqq/zW0pzt4YtDjkHLbwcp/lozpKzAQjg==",
@ -2383,7 +2383,7 @@
"npm:fast-stable-stringify@1", "npm:fast-stable-stringify@1",
"npm:formdata-helper@0.3", "npm:formdata-helper@0.3",
"npm:hono-rate-limiter@0.3", "npm:hono-rate-limiter@0.3",
"npm:iso-639-1@2.1.15", "npm:iso-639-1@^3.1.5",
"npm:isomorphic-dompurify@^2.16.0", "npm:isomorphic-dompurify@^2.16.0",
"npm:kysely-postgres-js@2.0.0", "npm:kysely-postgres-js@2.0.0",
"npm:kysely@~0.27.4", "npm:kysely@~0.27.4",

View file

@ -293,7 +293,7 @@ class Conf {
} }
/** Languages this server wishes to highlight. Used when querying trends.*/ /** Languages this server wishes to highlight. Used when querying trends.*/
static get preferredLanguages(): LanguageCode[] | undefined { static get preferredLanguages(): LanguageCode[] | undefined {
return Deno.env.get('DITTO_LANGUAGES')?.split(',')?.filter(ISO6391.validate) as LanguageCode[]; return Deno.env.get('DITTO_LANGUAGES')?.split(',')?.filter(ISO6391.validate);
} }
/** Translation provider used to translate posts. */ /** Translation provider used to translate posts. */
static get translationProvider(): string | undefined { static get translationProvider(): string | undefined {

View file

@ -60,7 +60,7 @@ const languageSchema = z.string().transform<LanguageCode>((val, ctx) => {
}); });
return z.NEVER; return z.NEVER;
} }
return val as LanguageCode; return val;
}); });
const localeSchema = z.string().transform<Intl.Locale>((val, ctx) => { const localeSchema = z.string().transform<Intl.Locale>((val, ctx) => {

View file

@ -75,7 +75,7 @@ export function getLanguage(text: string): LanguageCode | undefined {
const [iso6393] = topResult; const [iso6393] = topResult;
const locale = new Intl.Locale(iso6393); const locale = new Intl.Locale(iso6393);
if (ISO6391.validate(locale.language)) { if (ISO6391.validate(locale.language)) {
return locale.language as LanguageCode; return locale.language;
} }
} }
return; return;

View file

@ -36,7 +36,7 @@ export class DeepLTranslator implements DittoTranslator {
return { return {
results: translations.map((value) => value.text), results: translations.map((value) => value.text),
source_lang: translations[0]?.detected_source_language as LanguageCode, source_lang: translations[0]?.detected_source_language,
}; };
} }

View file

@ -46,7 +46,7 @@ export function detectLanguage(text: string, minConfidence: number): LanguageCod
const locale = new Intl.Locale(iso6393); const locale = new Intl.Locale(iso6393);
if (confidence >= minConfidence && ISO6391.validate(locale.language)) { if (confidence >= minConfidence && ISO6391.validate(locale.language)) {
return locale.language as LanguageCode; return locale.language;
} }
} }
} }