-
Notifications
You must be signed in to change notification settings - Fork 9
Files command examples
Examples of how to use the files command.
Table of content
Upload the file as is for translation, using automatic file type detection.
$ smartling-cli files push my-file.txt
Pushes the specified my-file.txt from your local directory into Smartling
using the URI /my/super/file.txt.
$ smartling-cli files push my-file.txt /my/super/file.txt
Pushes specified README.md from the local directory into Smartling as plaintext file.
$ smartling-cli files push README.md --type plaintext
README.md overwritten [3 strings 28 words]
Uploads all txt files from your local directory (including subdirectories) into Smartling. Note: Single quotes are used here to prevent shell expansion.
$ smartling-cli files push '**.txt'
$ smartling-cli files push custom.json --directive translate_paths='{"path":"*/string","key":"{*}/string","instruction":"*/instruction"}'
Uploads all txt files from your local directory (and all subdirectories) into
Smartling, prefixing each path with testing (using the -b or --branch option)
$ smartling-cli files push '**.txt' -b 'testing'
testing/test.txt new [3 strings 28 words]
If your working directory is a git workspace, you can configure the CLI to use your current branch name as a prefix.
$ smartling-cli files push '**.txt' --branch '@auto'
* 2017-06-27 16:20:54 [INFO] autodetected branch name: master
master/test.txt new [3 strings 28 words]
Pushes txt and md files, but overrides md file type to plaintext using the configuration file (see below)
$ smartling-cli files push '**.{txt,md}'
# authentication parameters
files:
"**.md":
push:
type: "plaintext"The CLI searches for a configuration file in your working directory. However, you can always specify an explicit path for the configuration file using the -c or --config option
$ smartling-cli -c smartling.yml files push '**.{txt,md}'
$ smartling-cli files pull **test.xml --source
downloaded files\test.xml 0%
downloaded test.xml 0%
downloaded master\test.xml 0%
Download translated files using masks and specify only certain locales.
$ smartling-cli files pull '**test.xml' -l es -l fr-FR
downloaded test_es.xml 0%
downloaded files/test_es.xml 0%
downloaded master/test_es.xml 0%
downloaded files/test_fr-FR.xml 0%
downloaded test_fr-FR.xml 0%
downloaded master/test_fr-FR.xml 0%
Get a list of files and filter files only which have _ or - in URI and then download original files
$ smartling-cli files list '**test.*' --short | grep '[_-]' | smartling-cli files pull --source
downloaded content/dam/geometrixx/portraits/yolanda_huggins.jpg-65359_de.xml 0%
downloaded content/geometrixx-media/en-14306_de.xml 0%
downloaded content/dam/geometrixx/portraits/scott_reynolds.jpg-65359_de.xml 0%
downloaded content/geometrixx-outdoors/en-96925_de.xml 0%
downloaded content/geometrixx/en-31001_de.xml 0%
Download all properties files locally from the configured project
$ smartling-cli files pull **ep?.properties --source
downloaded files/ep1.properties 0%
downloaded files/ep5.properties 0%
downloaded files/ep2.properties 0%
Upload all local properties files into another project (129xxxxx)
$ smartling-cli files push **.properties -p 129xxxxx
files/ep1.properties new [1 strings 2 words]
files/ep2.properties new [1 strings 2 words]
files/ep5.properties new [1 strings 3 words]
Additionally, you can specify different credentials for the push command if the target project belongs to a different account.
$ smartling-cli files list
/files/ep1.properties 2016-08-04T08:18:14Z javaProperties
/files/ep2.properties 2016-08-04T08:30:44Z javaProperties
/files/ep5.properties 2016-08-10T14:04:45Z javaProperties
/files/example.STRINGSDICT 2016-08-26T08:47:54Z stringsdict
/files/Localizable.stringsdict 2016-09-15T13:13:37Z stringsdict
/files/Localizable2.stringsdict 2016-09-23T16:22:49Z stringsdict
....
Get a list of file URIs filtered by a mask and display only the file URIs
$ smartling-cli files list '**test.xml' --short
/files/placeholder_test.xml
/files/test.xml
master/test.xml
test.xml
Use a different format for rendering data in the table and use a more complex mask.
$ smartling-cli files list '**{id,_}**.xml' --format='{{.FileType}}\t{{.FileURI}}\n'
xml /files/placeholder_test.xml
xml new_test_file.xml
xml test-client-id.xml
xml test_dropbox_variants_ns1.xml
xml test_dropbox_variants_ns2.xml
xml test_keys.xml
Get a comprehensive overview of your local and remote files
$ smartling-cli files status
config/locales/account.en.yml en-US missing source 5 5
config/locales/account.en_be-BY.yml be-BY missing 0% 0 0
config/locales/account.en_de-DE.yml de-DE missing 100% 5 5
config/locales/account.en_en-AU.yml en-AU missing 0% 0 0
config/locales/account.en_es.yml es missing 0% 0 0
config/locales/account.en_es-ES.yml es-ES missing 100% 5 5
config/locales/account.en_fr-FR.yml fr-FR missing 100% 5 5
config/locales/account.en_it-IT.yml it-IT missing 0% 0 0
config/locales/account.en_nl-NL.yml nl-NL missing 100% 5 5
config/locales/account.en_ru-RU.yml ru-RU missing 0% 0 0
config/locales/account.en_zh-CN.yml zh-CN missing 0% 0 0
test2.json en-US missing source 1 4
test2_be-BY.json be-BY missing 0% 0 0
test2_it-IT.json it-IT missing 0% 0 0
test2_zh-CN.json zh-CN missing 0% 0 0
test2_ru-RU.json ru-RU missing 100% 1 4
test2_es.json es missing 100% 1 4
test2_de-DE.json de-DE missing 0% 0 0
test2_en-AU.json en-AU missing 0% 0 0
test2_es-ES.json es-ES missing 0% 0 0
test2_fr-FR.json fr-FR missing 0% 0 0
....
Delete all files from the master branch
$ smartling-cli files delete 'master/**'
master/test.xml deleted
Delete files listed in the files-list.txt file
$ cat files-list.txt | smartling-cli files delete -
/files/placeholder_test.xml deleted
/files/test.xml deleted
test.xml deleted
Let's say your default configured project is 129xxxxx. However, you need to delete all files in another project (2a1xxxxxx) while still using your configured credentials
$ smartling-cli files list -s -p 2a1xxxxxx | smartling-cli files delete - -p 2a1xxxxxx
27 Words To Learn Before You Visit Hawaii.docx deleted
....
$ smartling-cli files rename test.json test-rename.json
Rename all files with suffix _en.xml to _en-us.xml
#!/bin/sh
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -ge 2 ] || die "2 argument are required, $# provided"
srcLocale=$1
dstLocale=$2
mode=${3:-"dryrun"}
./smartling-cli files list -s | grep -e "_$srcLocale.xml" | while read -r oldFileName
do
# newFileName=${oldFileName/_$srcLocale.xml/_$dstLocale.xml}
newFileName=$(echo $oldFileName | sed "s/_$srcLocale.xml/_$dstLocale.xml/g")
echo -e "Rename file\n\t$oldFileName\n\t$newFileName"
if [[ $mode == "apply" ]]; then
./smartling-cli files rename "$oldFileName" "$newFileName"
fi
done
if [[ $mode == "apply" ]]; then
echo "=====All files were renamed====="
else
echo "!!!!!No files were renamed!!!!! It was dryrun mode"
fi
Now you can test it
$ ./rename-files.sh ja ja_jp dryrun
Rename file
test1_en.xml
test1_en-us.xml
Rename file
/content/geometrixx/en/products/circle-35202_en.xml
/content/geometrixx/en/products/circle-35202_en-us.xml
!!!!!No files were renamed!!!!! It was dryrun mode