Skip to content

scriptingosx/translate-cli

Repository files navigation

macOS translate CLI

macOS command line tool to translate input using the built-in macOS Translation Service.

What it does

macOS 26 has a fairly robust built-in Translation service.

This command line tool uses the Translation service to translate text passed as arguments from one language to another using Apple's Translation framework.

Requirements

This tool requires macOS 26.0.

Installation

You can build the package from source with

swift build -c release

or use the pkg installer available in releases.

Usage

Important: You have to download the Translation resources in System Settings > Languge & Region > Translation Languages… (button at the bottom of that pane) before using this tool. Otherwise you will get Error: Unable to Translate messages. You only need to download the languages you are going to use.

Translation

By default, translate will translate the text from the arguments to the current system language. (in the examples, the current system language is English)

$ translate "Dies ist ein kurzer Satz."
This is a short sentence.

Multiple arguments will be joined together, so you don't need to quote the input, unless there are special characters:

$ translate Dies ist ein kurzer Satz.
This is a short sentence.
$ translate "Dies ist ein kurzer Satz!"
This is a short sentence.

You can set different target languages with the --to flag:

$ translate "Dies ist ein kurzer Satz." --to fr
C'est une courte phrase.

You can provide multiple --to options with different language codes. Each translation will be prepended with the language code.

$ translate --to en --to fr --to es "Dies ist ein kurzer Satz."
en: This is a short sentence.
fr: C'est une courte phrase.
es: Esta es una frase corta.

The source language will be determined from the text. You can override the detection with the --from flag:

$ translate --from de "Dies ist ein kurzer Satz."
This is a short sentence.
$ translate --from de --to fr "Dies ist ein kurzer Satz."
C'est une courte phrase.

When no arguments are given as arguments, text will be read from standard input:

$ echo "Dies ist ein kurzer Satz." | translate
This is a short sentence.

Language detection

Use the detect subcommand to detect the dominant language in the text:

$ translate detect "Dies ist ein kurzer Satz."
de

Translating xcstrings files

Xcode uses xcstrings to store localizations of text strings. You can use translate to add translations to an xcstrings file.

Usage:

$ translate xcstrings --to de --to fr path/to/Localizations.xcstrings path/to/Localizations_translated.xcstrings

Strings marked in Xcode as "Don't Translate" will be skipped.

When no output path is given, the resulting json will be output to standard out. The status messages are printed to standard error, so you can redict stdout to a file or pipe it into a different tool, e.g.

$ translate xcstrings --to de Localizations.xcstrings | jq '.strings | keys'

When the field for a given translation already has a value, it will be skipped unless the --replace-translations flag is set.

About

command line tool to use the macOS system translation service

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors