mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Remove Provider type (it's just a string)
This commit is contained in:
parent
c048cda2e5
commit
33d2eb6ca3
3 changed files with 11 additions and 13 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { LanguageCode } from 'iso-639-1';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { DittoTranslator, Provider, SourceLanguage, TargetLanguage } from '@/translators/translator.ts';
|
import { DittoTranslator, SourceLanguage, TargetLanguage } from '@/translators/translator.ts';
|
||||||
import { languageSchema } from '@/schema.ts';
|
import { languageSchema } from '@/schema.ts';
|
||||||
|
|
||||||
interface DeepLTranslatorOpts {
|
interface DeepLTranslatorOpts {
|
||||||
|
|
@ -16,7 +17,7 @@ export class DeepLTranslator implements DittoTranslator {
|
||||||
private readonly endpoint: string;
|
private readonly endpoint: string;
|
||||||
private readonly apiKey: string;
|
private readonly apiKey: string;
|
||||||
private readonly fetch: typeof fetch;
|
private readonly fetch: typeof fetch;
|
||||||
private static provider: Provider = 'DeepL.com';
|
private static provider = 'DeepL.com';
|
||||||
|
|
||||||
constructor(opts: DeepLTranslatorOpts) {
|
constructor(opts: DeepLTranslatorOpts) {
|
||||||
this.endpoint = opts.endpoint ?? 'https://api.deepl.com';
|
this.endpoint = opts.endpoint ?? 'https://api.deepl.com';
|
||||||
|
|
@ -34,7 +35,7 @@ export class DeepLTranslator implements DittoTranslator {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
results: data.map((value) => value.text),
|
results: data.map((value) => value.text),
|
||||||
source_lang: data[0].detected_source_language,
|
source_lang: data[0].detected_source_language as LanguageCode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@ export class DeepLTranslator implements DittoTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DeepL provider. */
|
/** DeepL provider. */
|
||||||
getProvider(): Provider {
|
getProvider(): string {
|
||||||
return DeepLTranslator.provider;
|
return DeepLTranslator.provider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { LanguageCode } from 'iso-639-1';
|
import { LanguageCode } from 'iso-639-1';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { DittoTranslator, Provider, SourceLanguage, TargetLanguage } from '@/translators/translator.ts';
|
import { DittoTranslator, SourceLanguage, TargetLanguage } from '@/translators/translator.ts';
|
||||||
import { languageSchema } from '@/schema.ts';
|
import { languageSchema } from '@/schema.ts';
|
||||||
|
|
||||||
interface LibreTranslateTranslatorOpts {
|
interface LibreTranslateTranslatorOpts {
|
||||||
|
|
@ -17,7 +17,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
||||||
private readonly endpoint: string;
|
private readonly endpoint: string;
|
||||||
private readonly apiKey: string;
|
private readonly apiKey: string;
|
||||||
private readonly fetch: typeof fetch;
|
private readonly fetch: typeof fetch;
|
||||||
private static provider: Provider = 'libretranslate.com';
|
private static provider = 'libretranslate.com';
|
||||||
|
|
||||||
constructor(opts: LibreTranslateTranslatorOpts) {
|
constructor(opts: LibreTranslateTranslatorOpts) {
|
||||||
this.endpoint = opts.endpoint ?? 'https://libretranslate.com';
|
this.endpoint = opts.endpoint ?? 'https://libretranslate.com';
|
||||||
|
|
@ -37,7 +37,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
results: translations.map((value) => value.translatedText),
|
results: translations.map((value) => value.translatedText),
|
||||||
source_lang: translations[0]?.detectedLanguage?.language ?? source as LanguageCode, // cast is ok
|
source_lang: (translations[0]?.detectedLanguage?.language ?? source) as LanguageCode, // cast is ok
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** LibreTranslate provider. */
|
/** LibreTranslate provider. */
|
||||||
getProvider(): Provider {
|
getProvider(): string {
|
||||||
return LibreTranslateTranslator.provider;
|
return LibreTranslateTranslator.provider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ import { LRUCache } from 'lru-cache';
|
||||||
|
|
||||||
import { Time } from '@/utils/time.ts';
|
import { Time } from '@/utils/time.ts';
|
||||||
|
|
||||||
/** Supported providers. */
|
|
||||||
export type Provider = 'DeepL.com' | 'libretranslate.com';
|
|
||||||
|
|
||||||
/** Original language of the post */
|
/** Original language of the post */
|
||||||
export type SourceLanguage = LanguageCode;
|
export type SourceLanguage = LanguageCode;
|
||||||
|
|
||||||
|
|
@ -29,7 +26,7 @@ export type MastodonTranslation = {
|
||||||
//** The language of the source text, as auto-detected by the machine translation provider. */
|
//** The language of the source text, as auto-detected by the machine translation provider. */
|
||||||
detected_source_language: SourceLanguage;
|
detected_source_language: SourceLanguage;
|
||||||
/** The service that provided the machine translation. */
|
/** The service that provided the machine translation. */
|
||||||
provider: Provider;
|
provider: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** DittoTranslator class, used for status translation. */
|
/** DittoTranslator class, used for status translation. */
|
||||||
|
|
@ -44,7 +41,7 @@ export interface DittoTranslator {
|
||||||
/** Custom options. */
|
/** Custom options. */
|
||||||
opts?: { signal?: AbortSignal },
|
opts?: { signal?: AbortSignal },
|
||||||
): Promise<{ results: string[]; source_lang: SourceLanguage }>;
|
): Promise<{ results: string[]; source_lang: SourceLanguage }>;
|
||||||
getProvider(): Provider;
|
getProvider(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Includes the TARGET language and the status id.
|
/** Includes the TARGET language and the status id.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue