-
Notifications
You must be signed in to change notification settings - Fork 8
MT command examples
Examples of how to use the mt command.
Table of content
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
You can do detection in bulk using wildcards.
$ smartling-cli mt detect "document*.txt"
document1.txt es
document2.txt fr
Streamline your workflow by organizing files in a dedicated folder:
$ smartling-cli mt detect "*.txt" --input-directory ./documents/
documentA.txt en
documentB.txt fr
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
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 │
└─────────────┴─────────┴────┴─────────┴──────┴─────────┴────────┘
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"
}
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
$ smartling-cli mt translate document1.txt --source-locale en --target-locale es-ES
document1_es-ES.txt
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
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
enthen translate the file tofr-FR. - If the detected language is
frorfr-FRthen translate toen.
#!/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