Skip to content

MT command examples

Dmitry Studynsky edited this page Jul 10, 2025 · 1 revision

Examples of how to use the mt command.

Table of content

Detect File Language

The following examples demonstrate how to identify the language of your content files.

$ smartling-cli mt detect document1.txt
document1.txt   es

For scripting purposes, you can output just the locale code using the -s/--short option:

$ smartling-cli mt detect document1.txt --short
es

Detect Language for Multiple Files

You can do detection in bulk using wildcards.

$ smartling-cli mt detect "document*.txt"
document1.txt   es
document2.txt   fr

Detect Language for Files from a Folder

Streamline your workflow by organizing files in a dedicated folder:

$ smartling-cli mt detect "*.txt" --input-directory ./documents/
documentA.txt        en
documentB.txt        fr

Override File Type

When automatic file type detection is insufficient, you can explicitly specify the file type for proper content parsing:

$ smartling-cli mt detect "*.json" --type json
document.json   fr

Use Different Output Formats

Customize how results are displayed by selecting from various output formats. The table format provides a comprehensive view of file information:

$ smartling-cli mt detect "document*.txt" --output table
┌─────────────┬─────────┬────┬─────────┬──────┬─────────┬────────┐
│File         │Name     │Ext │Directory│Upload│Detect   │Language│
├─────────────┼─────────┼────┼─────────┼──────┼─────────┼────────┤
│document1.txt│document1│.txt│.        │✓     │COMPLETED│es      │
│document2.txt│document2│.txt│.        │✓     │COMPLETED│fr      │
└─────────────┴─────────┴────┴─────────┴──────┴─────────┴────────┘

Use Pipes for Advanced Filtering

Combine the CLI with other tools like jq to create powerful data processing pipelines. This example filters the JSON output to show only files in Spanish:

$ smartling-cli mt detect "document*.txt" --output json | jq '.[] | select(.Language == "es") | {File, Language}'
{
  "File": "document1.txt",
  "Language": "es"
}

Translate Files

Detect Language and Translate

The easiest way to translate is to specify a file and the desired target locale. When --source-locale is omitted, the CLI automatically detects the source language:

$ smartling-cli mt translate document1.txt --target-locale es-ES
document1_es-ES.txt

You can translate multiple files at once using wildcards:

$ smartling-cli mt translate "document*.txt" -l es-ES
document1_es-ES.txt
document2_es-ES.txt

Translate File for the Pair of Languages

$ smartling-cli mt translate document1.txt --source-locale en --target-locale es-ES
document1_es-ES.txt

Translate File from/to Folder

It is very convenient to download translated files into a separate folder.

$ smartling-cli mt translate "document*.txt" -l es -l fr --output-directory ./translations
document1_es,fr.txt
document2_es,fr.txt

$ ls ./translations/
document1_es.txt  document1_fr.txt  document2_es.txt  document2_fr.txt

Additionally, you can specify a source folder containing the original files.

$ smartling-cli mt translate "*.txt" -l es -l fr --input-directory ./documents/ --output-directory ./translations/
documentA_es,fr.txt

Combine Detect and Translation

An example of a bash script that can translate a file from English to French or vice versa based on the source language.

  • If the detected language is en then translate the file to fr-FR.
  • If the detected language is fr or fr-FR then translate to en.
#!/bin/bash
detected=$(smartling-cli mt detect test.txt --short)
if [[ "$detected" == "en" ]]; then
    smartling-cli mt translate test.txt --source-locale en --target-locale fr-FR
elif [[ "$detected" =~ ^fr(-FR)?$ ]]; then
    smartling-cli mt translate test.txt --source-locale "$detected" --target-locale en
fi