Translators

## How to translate text when building websites

Not only can you use any language/alphabet you want with content/template files and page names for urls, there are two command-line based translators worth checking out if you want to translate text when building websites:

## Translate Shell

You can find installation instructions for Translate Shell here, the recommended way being direct download, though there is information about package managers here.

Note: Translate Shell needs the internet to run, if you are building your website and Translate Shell is called without internet access your build might stall. It is also unlikely to scale well to websites with 10k+ pages, possibly even 1k+.

Along with below, there are examples to help get you started here and documentation on usage here.

The simplest way to use Translate Shell with Nift is:

@system{inject}("trans -brief 'text'")

where text is the text you want translated.

If you want to translate text in a file use

@system{inject}("trans -brief file://file-path")@dep("file-path")

where file-path is the path from the project root directory to the file you want to translate. It is worth adding the file as a dependency after the @system{inject} call so that Nift will track changes to the file for purposes of knowing when the page needs rebuilding.

To specify which language to translate to add :language-code after -brief and to specify which language to translate from add language-code: after -brief, the language codes that are available can be found here. For example:

@system{inject}("trans -brief eo: 'vorto'")
@system{inject}("trans -brief :zh-CN 'hello'")
@system{inject}("trans -brief en: :zh-CN 'hello'")


To list the available translation engines enter trans -S. To use a non-default translation engine use the -e engine option, for example:

@system{inject}("trans -e yandex -brief :en '你好'")


## DeepL Translator CLI

You can use yarn to install DeepL Translator CLI with the command:

\$ yarn global add deepl-translator-cli


Along with below, there are examples to help you get started here.

The simplest way to use DeepL Translator CLI with Nift is:

@system{inject}("deepl translate -t 'country-code' 'text'")

where:
• language-code is the code for the language you want to translate in to (the available codes are in the table below); and
• text is the text you want translated.

If you want to specify the language to translate from use the -s 'language-code' option, for example:

@system{inject}("deepl translate -s 'EN' -t 'DE' 'How do you do?'")


You can pipe text from standard input, for example:

@system{inject}("echo 'text' | deepl translate -t 'language-code'")


If you want to translate a file, you can do so as follows:

@system{inject}("cat file-path | deepl translate -t 'language-code'")@dep("file-path")

where file-path is the path from the project root directory to the file you want to translate. It is worth adding the file as a page dependency after the @system{inject} call so that Nift will track changes to the file for purposes of knowing when the page needs rebuilding.

The available languages and codes are:

language code
English EN
German DE
French FR
Spanish ES
Italian IT
Dutch NL
Polish PL
language code