obsidian-translate icon indicating copy to clipboard operation
obsidian-translate copied to clipboard

Translating by a little script

Open Ananas0631 opened this issue 1 year ago • 1 comments
trafficstars

Hi there,i installed this plugin to use with a daily quote plugin.Daily quote plugin reedems a quote everyday.I have no problems understanding english but all my page is written with my native language and i don't want this quote in english language.It would be great for automatic creations/templates if you can provide this feature:

For example:

input:de[{{en_quote}}]

output:de_quote

(i am not a developer so i may have missed some things.Sorry about that.)

Ananas0631 avatar Mar 26 '24 16:03 Ananas0631

Hi, I assume you are using the quote-of-the-day plugin. If so, you may be interested in this issue https://github.com/twentytwokhz/quote-of-the-day/issues/10

In general, providing translations for a widget/view/... created by a plugin is not easily possible, as the translate plugin has no way to communicate with the other plugin (so translations/internationalisation has to be supported by the quote plugin itself)

If it helps, it is possible to create a translation script that uses this plugin using e.g. Templater like:

<%*
let engText = "Text to translate";
let sourceLanguage = "auto";  
let targetLanguage = "de";

const api = app.plugins.plugins['translate'].api;
if (api?.canTranslate) {  
	const output = await api.translate(engText, sourceLanguage, targetLanguage); 
	console.log(output)
	if (output.status_code !== 200)
	    new Notice(output.message);
	else
	    tR += output.translation;
}
%>

Fevol avatar Mar 27 '24 17:03 Fevol