mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-18 03:34:20 +01:00
Remove Provider type (it's just a string)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { LanguageCode } from 'iso-639-1';
|
||||
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';
|
||||
|
||||
interface DeepLTranslatorOpts {
|
||||
@@ -16,7 +17,7 @@ export class DeepLTranslator implements DittoTranslator {
|
||||
private readonly endpoint: string;
|
||||
private readonly apiKey: string;
|
||||
private readonly fetch: typeof fetch;
|
||||
private static provider: Provider = 'DeepL.com';
|
||||
private static provider = 'DeepL.com';
|
||||
|
||||
constructor(opts: DeepLTranslatorOpts) {
|
||||
this.endpoint = opts.endpoint ?? 'https://api.deepl.com';
|
||||
@@ -34,7 +35,7 @@ export class DeepLTranslator implements DittoTranslator {
|
||||
|
||||
return {
|
||||
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. */
|
||||
getProvider(): Provider {
|
||||
getProvider(): string {
|
||||
return DeepLTranslator.provider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LanguageCode } from 'iso-639-1';
|
||||
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';
|
||||
|
||||
interface LibreTranslateTranslatorOpts {
|
||||
@@ -17,7 +17,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
||||
private readonly endpoint: string;
|
||||
private readonly apiKey: string;
|
||||
private readonly fetch: typeof fetch;
|
||||
private static provider: Provider = 'libretranslate.com';
|
||||
private static provider = 'libretranslate.com';
|
||||
|
||||
constructor(opts: LibreTranslateTranslatorOpts) {
|
||||
this.endpoint = opts.endpoint ?? 'https://libretranslate.com';
|
||||
@@ -37,7 +37,7 @@ export class LibreTranslateTranslator implements DittoTranslator {
|
||||
|
||||
return {
|
||||
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. */
|
||||
getProvider(): Provider {
|
||||
getProvider(): string {
|
||||
return LibreTranslateTranslator.provider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ import { LRUCache } from 'lru-cache';
|
||||
|
||||
import { Time } from '@/utils/time.ts';
|
||||
|
||||
/** Supported providers. */
|
||||
export type Provider = 'DeepL.com' | 'libretranslate.com';
|
||||
|
||||
/** Original language of the post */
|
||||
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. */
|
||||
detected_source_language: SourceLanguage;
|
||||
/** The service that provided the machine translation. */
|
||||
provider: Provider;
|
||||
provider: string;
|
||||
};
|
||||
|
||||
/** DittoTranslator class, used for status translation. */
|
||||
@@ -44,7 +41,7 @@ export interface DittoTranslator {
|
||||
/** Custom options. */
|
||||
opts?: { signal?: AbortSignal },
|
||||
): Promise<{ results: string[]; source_lang: SourceLanguage }>;
|
||||
getProvider(): Provider;
|
||||
getProvider(): string;
|
||||
}
|
||||
|
||||
/** Includes the TARGET language and the status id.
|
||||
|
||||
Reference in New Issue
Block a user