Using the client

Initializing a Project

The first thing we need to do is run:

→ tx init

This will simply create an empty .tx/config file to mark the current folder as a Transifex project. Your directory structure should now look like this:

Adding Resources to Configuration

We will add the php file as a source language file in our local configuration. The simplest way to do this is with tx add which will start an interactive session:

Your .tx/config file should look like this:

You can skip steps from the interactive session by adding flags to the tx add command. In fact, you can skip the interactive session entirely if you provide all the flags:

Global settings

You can have anywhere you want your root configuration (.transifexrc) or configuration (.tx/config) and you can define their path with the following parameters --root-config and --config accordingly right after the tx command.

--root-config FILE : Root configuration from FILE

--config FILE, -c FILE : Load configuration from FILE

--token value, -t valuexliff : The API token to use [$TX_TOKEN]

--hostname value, -H value : The API hostname [$TX_HOSTNAME]

Pushing Files to Transifex

tx push is used to push language files (usually source language files) from your machine to Transifex. You will most likely want to do that frequently during the lifetime of you project when new source strings are introduced or existing ones are changed. This will make the new strings available to translators as soon as possible.

The simplest invocation of tx push is simply:

→ tx push

This will attempt to push the source file of all local resources that have been configured with tx add.

LIMITING RESOURCES

You can limit the resources you want to pull with:

→ tx push [RESOURCE_ID]...

A resource ID must refer to a resource that has already been configured with tx add and has the form <project>.<resource>. So, if the URL of your resource in Transifex is https://www.transifex.com/myorganization/myproject/myresource, then the resource ID will be myproject.myresource.

🚧

For backwards compatibility with previous versions of the client, you can also use the -r/--resources flag. You can also use both at the same time:

→ tx push p1.r1 p1.r2 -r p1.r3,p1.r4
# Equivalent to
→ tx push p1.r1 p1.r2 p1.r3 p1.r4

tx push will create the resources on Transifex if they are missing.

LANGUAGE MANAGEMENT

By default, the client will push the source file (the file that's being pointed to by the source_file configuration option from tx add). If you use the -t/--translation flag, tx push will push translation files. This may be desirable if, for example, you previously pulled translation files with the --mode translator option, translated using an offline translation tool and now you want to push your work to Transifex, or if you are migrating from another localization management service to Transifex. If you use both the -t and the -s/--source flags, then you will push both the source file and the translation files.

When you use -t, the client will find all local files that match the file-filter configuration option. The files that are found, and their language codes constitute the local languages. By default, the client will ask the Transifex API for the languages that are supported by the project you are pushing to (the remote languages) and will only push languages that are both local and remote (aka the intersection of local and remote languages).

You can use the -l/--languages flag to handpick which languages you want to push. It only makes sense to include local languages with the -l flag, ie languages for which a file exists according to the file-filter configuration option. The client will then push only the language files you have specified. If you specify local languages that are not yet supported by the remote Transifex project, the client will attempt to add these languages to the project first. Be careful of this since it may affect your pricing if you are a paying customer.

→ tx push -t -l fr,de,pt_BR

The -a/--all flag will attempt to push all local languages to the remote Transifex project, adding them if necessary. Essentially, -a is equivalent to using -l with all the local language codes.

Transifex uses the ISO/IEC 15897 standard for language codes (for example en_US). If you use a different format for the local language codes, you can define a mapping in your configuration file .tx/config (later we will offer the tx config command to make editing the configuration more convenient). You can specify these mappings for all configured resources by adding them to the [main] section or you can specify mappings per resource. The "per-resource" mappings take precendence. Configuring a language mapping looks like this:

This means that the remote pt_PT language code maps to the local pt-pt language code and the remote pt_BR language code maps to the local pt-br language code.

The -l flag works with both local and remote language codes.

SKIPPING PUSHING OLDER FILES

The default behavior of the tx push command is to skip pushing a file when the remote resource on Transifex has had a change more recently than when the local file was last edited. To make sure that the local files are pushed even if they are older than the remote resource, use the -f/--force flag.

You can use the --use-git-timestamps flag to compare against the last time the local files were committed to the local git repository instead of the last modification time in the filesystem. This can be useful in cases where you have just cloned a repository or pulled a branch. In this case, the filesystem modification time will reflect the time you pulled and not the time the file was edited by an actual person. If you use the --use-git-timestamps flag and no information about a local git repository can be found, then the client will default to taking the filesystem timestamp into account.

OTHER FLAGS

  • --xliff: Push xliff files instead of regular ones. The files must be located in the same place as indicated by the file-filter configuration option, but with the added .xlf suffix (tx pulling with the --xliff option will put xliff files in the correct positions so you will probably not have to do this by hand)
  • --branch: Using this flag, you can access copies of the regular remote resource that are tied to the provided branch. So if tx push proj.res pushes to the https://www.transifex.com/org/proj/res resource, then tx push --branch foo proj.res will push to the https://www.transifex.com/org/proj/foo--res resource. This way you can separate the localization effort across different branches. If you supply an empty string as the branch (--branch ''), then the client will attempt to figure out the currently active branch in the local git repository. For example:

This way, the "regular" https://www.transifex.com/myorganization/myproject/myresource resource will not be affected by the changes you did to the source strings and the localization effort can be done in parallel on the https://www.transifex.com/myorganization/myproject/new_feature--myresource resource.

  • --skip: Normally, if an upload fails, the client will abort. This may not be desirable if most uploads are expected to succeed. For example, the reason of the failed upload may be a syntax error in one of the language files. If you set the --skip flag and an upload fails, then the client will simply print a warning and move on to the next language file.

Pulling Files from Transifex

tx pull is used to pull language files (usually translation language files) from Transifex to your machine. Most likely, you will do this regularly when you want to incorporate newly available translations from Transifex into it.

The simplest invocation of tx pull is simply:

→ tx pull

This will attempt to pull the translation files of all local resources that have been configured with tx add.

LIMITING RESOURCES

You can limit the resources you want to pull with:

→ tx pull [RESOURCE_ID]...

As stated in the tx push section, a resource ID must refer to a resource that has already been configured with tx add and has the form <project>.<resource>.

🚧

For backwards compatibility with previous versions of the client, you can also use the -r/--resources flag. You can also use both at the same time:

→ tx pull p1.r1 p1.r2 -r p1.r3,p1.r4
# Equivalent to
→ tx pull p1.r1 p1.r2 p1.r3 p1.r4

LANGUAGE MANAGEMENT

By default, the client will pull the translation files of the existing files in the paths that are defined in the file_filter configuration option from tx add.

For instance, if the directory structure looks like this:

and the .tx/config contains:

source_file = locale/en.php
file_filter = locale/<lang>.php

If you use the -s/--source flag, tx pull will pull the source file that is pointed from the source_file option of the config file.

If you use both the -t/--translation and the -s/--source flags, then you will pull both the source file, and the translation files.

Then the client will try to search for any existing language file located at the locale/<lang> path (where <lang> is the language code) and will try to update it.

i.e locale/el.php, locale/fr.php etc

In case that there aren't any translation files, like in the structure above, then you must either use the -l/--language or the -a/--all flag.

Use the -l/--languages flag to handpick which languages you want to pull. It only makes sense to include remote languages with the -l flag, ie languages for which a file does not exist according to the file_filter configuration option. The client will then pull only the language files you have specified:

→ tx pull -l el,fr,nl

📘

Note

The languages that are defined with the -l/--language flag should belong to the project for the client to download them.

The -a/--all flag will attempt to pull all languages from the remote Transifex project. Essentially, -a is equivalent to using -l with all the project language codes.

As stated before, Transifex uses the ISO/IEC 15897 standard for language codes. If you use a different format for the local language codes, you can define a mapping in your configuration file .tx/config. You can specify these mappings for all configured resources by adding them to the [main] section or you can specify mappings per resource. The "per-resource" mappings take precendence. Configuring a language mapping looks like this:

This means that the remote pt_PT language code maps to the local pt-pt language code and the remote pt_BR language code maps to the local pt-br language code.

The -l flag works with remote language codes.

SKIPPING PULLING OLDER FILES

The default behavior of the tx pull command is to skip pulling a file when a local file on a machine has had a change more recently than when the remote resource was last edited. To make sure that the remote resources are pulled even if they are older than the local files, use the -f/--force flag.

You can use the --use-git-timestamps flag to compare against the last time the local files were committed to the local git repository instead of the last modification time in the filesystem. This can be useful in cases where you have just cloned a repository or pulled a branch. In this case, the filesystem modification time will reflect the time you pulled and not the time the file was edited by an actual person. If you use the --use-git-timestamps flag and no information about a local git repository can be found, then the client will default to taking the filesystem timestamp into account.

OTHER FLAGS

  • --xliff: Pull xliff files instead of regular ones. The files will be placed in the same place as indicated by the source-file and file-filter configuration options, but with the added .xlf suffix.
  • --json: Pull translation files as json instead of regular ones. As above, the files will be placed in the same place as indicated by the file-filter configuration options, but with the added .json suffix. Currently, source files are not supporting json format.
  • --disable-overwrite: If a file exists do not update it. This is useful when using -a/--all flag and you don't want to change the existing files but only download other language files.
  • --branch: Using this flag, you can access copies of the regular remote resource that are tied to the provided branch. So if tx pull proj.res pulls from the https://www.transifex.com/org/proj/res resource, then tx pull --branch foo proj.res will pull from the https://www.transifex.com/org/proj/foo--res resource. This way you can separate the localization effort across different branches. If you supply an empty string as the branch (--branch ''), then the client will attempt to figure out the currently active branch in the local git repository. For example:

This way, the "regular" https://www.transifex.com/myorganization/myproject/myresource resource will not be affected by the changes one did, and the localization effort can be done in parallel on the https://www.transifex.com/myorganization/myproject/new_feature--myresource resource.

  • --skip: Normally, if a download fails, the client will abort. This may not be desirable if most downloads are expected to succeed. For example, the reason of the failed download may be a syntax error in one of the language files. If you set the --skip flag and an upload fails, then the client will simply print a warning and move on to the next language file.
  • --minimum_perc=MINIMUM_PERC Specify the minimum translation completion threshold required in order for a file to be downloaded.

Removing resources from Transifex

The tx delete command lets you delete a resource that's in your config file and on Transifex.

To delete a resource, use the following command:

→ tx delete <project_slug>.<resource_slug>

To delete all resources in a specific project at once, instead of referring to a specific resource_slug, you can use the asterisk character as follows:

→ tx delete project_slug.*

or

→ tx delete project_slug.\*

🚧

For backwards compatibility with previous versions of the client, you can also use the -r/--resources flag. You can also use both at the same time:

tx delete -r <project_slug>.<resource_slug> ....

OTHER FLAGS

  • --skip: Normally, if a delete fails, the client will abort. This may not be desirable if most deletes are expected to succeed. For example, the reason of the failed delete may be a a resource that has translated content. If you set the -s/--skip flag and a delete fails, then the client will simply print a warning and move on to the next resource.
  • --force: In case you want to proceed to a deletion even if resources have translations use the -f/--force flag.
  • --branch: In case you want to delete a resource's branch that is on Transifex. If you supply an empty string as the branch (--branch ''), then the client will attempt to figure out the currently active branch in the local git repository.

Getting the local status of the project

The status command displays the existing configuration in a human readable format. It lists all resources that have been initialized under the local repo/directory and all their associated translation files:

To get the status of specific resources just add the resources you want in your command:

→ tx status <project_slug>.<resource_slug> ....

🚧

For backwards compatibility with previous versions of the client, you can also use the -r/--resources flag. You can also use both at the same time:

tx status -r <project_slug>.<resource_slug> ...

Updating the CLI app

The tx update command provide's a way to self update the application wihtout going to Github releases page.

→ tx update

Flags:

  • --check: Check if there is a new release. Nothing gets updated.
  • --no-interactive: Proceed to update if there is a newer version without seeing the confirmation prompt.
  • --debug: Enable logging for the binary update process.

Did this page help you?