malta-translate

malta plugin to translate quickly anything from/into a lot of languages

Usage no npm install needed!

<script type="module">
  import maltaTranslate from 'https://cdn.skypack.dev/malta-translate';
</script>

README


npm version"> npm downloads npm downloads

This plugin can be used on: all files

Options :
- input : default 'it' ... yes Italian! but You can specify any language supported by @vitalets/google-translate-api (here is the list) - output : default 'en' but You can specify any language supported by @vitalets/google-translate-api (here is the list)

Sample usage:

suppose the outfile contains a label that should be translated:

hello.js:

...
var hello = "hello world", 
    presentations = "myname is Federico";

this is a .js file but could be anything, now if we want to translate it in german for example, we rewrite it like:

var hello = "i18n[hello world]", 
    presentations = "i18n[my name is] Federico";

now we can run malta on it using the malta-translate:

malta app/hello.js public -plugins=malta-js-uglify...malta-translate[input:\"\'en\",output:\"de\"]

or in the .json file :

"app/hello.js" : "public -plugins=malta-js-uglify...malta-translate[input:\"\'en\",output:\"de\"]"

and get :

public/hello.js

var hello="Hallo Welt",presentations="Ich heisse Federico";

if

...within a file that must be translated for example from en to de one particular word has always to be translated to japanese, regardless the input & output given parameters then is enough to mark it as:

i18n[always japanese|ja] 

Cache

in the example will be created a file in the forlder where malta is executed a file named .malta-translate-cache-en-de.json which contains the cached results to avoid unnecessary requests; the outmessage of the plugin will containsome stats about hit/missed elements. Malta will create/update those files but will never delete them; if needed You have to delete em.

Backward compatibility

Malta-translate versions < 1.1 need malta < 4.1