Translators
Google translate on Globe image

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:

Google translate hello to hola image

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("trans -brief 'text'")

where text is the text you want translated.

If you want to translate text in a file use

@system("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 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("trans -brief eo: 'vorto'")
@system("trans -brief :zh-CN 'hello'")
@system("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("trans -e yandex -brief :en '你好'")
translated text on world map

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("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("deepl translate -s 'EN' -t 'DE' 'How do you do?'")

You can pipe text from standard input, for example:

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

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

@system("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 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
translated text on mobile, tablet and PC