Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some languages supported by custom translators are not displaying in the dropdown menu #374

Open
Prasanta-Hembram opened this issue Jun 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Prasanta-Hembram
Copy link

Description

I have created a custom translator that uses the Mymemory API for translation. Thanks to @AlphaBack for making it work! However, when I add the translator to the custom translator list of the extension, languages such as Santali (code: sat), which Mymemory supports, do not display in the drop-down menu when I am translating using the extension.

Steps

  1. Copy the below custom translator code of Mymemory. (Added Santali for demo)
class MyMemoryTranslator {
	
	apiPath = 'https://api.mymemory.translated.net/get';

	translate = (text, from, to) => {
		return fetch(`${this.apiPath}?q=${text}&langpair=${from}|${to}`, {
			credentials: 'omit',
			headers: {
				'User-Agent':
					'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0',
				Accept: '*/*',
				'Accept-Language': 'en-US,en;q=0.5',
				'Sec-Fetch-Dest': 'empty',
				'Sec-Fetch-Mode': 'cors',
				'Sec-Fetch-Site': 'same-origin',
			},
			method: 'GET',
			mode: 'cors',
		})
			.then((r) => r.json())
			.then(({ responseData }) => responseData.translatedText);
	};

	translateBatch = (texts, from, to) =>
		Promise.all(texts.map((text) => this.translate(text, from, to)));

	getLengthLimit = () => 4000;
	getRequestsTimeout = () => 300;
	checkLimitExceeding = (text) => {
		const textLength = !Array.isArray(text)
			? text.length
			: text.reduce((len, text) => len + text.length, 0);

		return textLength - this.getLengthLimit();
	};

	static isSupportedAutoFrom = () => true;

	// prettier-ignore
	static getSupportedLanguages = () => [
		"en", "ar", "az", "zh", "cs",
        "nl", "eo", "fi", "fr", "de",
        "el", "hi", "hu", "id", "ga",
        "it", "ja", "ko", "fa", "pl",
        "pt", "ru", "sat", "sk", "es", "sv",
        "tr", "uk", "vi"
	];
}

MyMemoryTranslator;
  1. Go to Translation preferences and add it to Custom translators by giving any name and save it.
  2. Select that from Translator module.
  3. Now try to translate some sentences from English to Santali.
  4. Santali language is missing.

Expected

It should show Santali language as an option.

@vitonsky
Copy link
Collaborator

Currently, Linguist supports only 2-letter ISO-639-1 language codes.

As i see, ISO 639-2 language codes have sat code. To fix the problem, we have to supports ISO 639-2 language codes. Also, we should to update custom translators docs.

We have to ensure ISO 639-1 language codes will works fine too, to implement it, we have to add mapper for ISO codes.

This problem serious, i will fix it as soon as possible and will release in next hot fix update. Thank you for report.

@Prasanta-Hembram
Copy link
Author

Prasanta-Hembram commented Jun 17, 2024

return fetch(${this.apiPath}?q=${text}&langpair=${from}|${to}, {

to

return fetch(${this.apiPath}?q=${text}&langpair=${from}|sat, {

I have found a quick workaround, if we replace variable ${to} with simply a language code (three letter) then it is working fine. then select any language from the target language it will translate it properly in that desired language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants