Permalink
Fetching contributors…
Cannot retrieve contributors at this time
629 lines (373 sloc) 15.9 KB

Management commands

Note

Running management commands under different user than is running your webserver can cause wrong permissions on some files, please check :ref:`file-permissions` for more details.

Django comes with management script (available as :file:`./manage.py` in sources or installed as :command:`weblate` when Weblate is installed). It provides various management commands and Weblate extends it with several additional commands.

Invoking management commands

As mentioned before, invocation depends on how you have installed Weblate.

If you are using source code directly (either tarball or Git checkout), the management script is :file:`./manage.py` in Weblate sources. Execution can be done as:

python ./manage.py list_versions

If you've istalled Weblate using PIP installer or by :file:`./setup.py` script, the :command:`weblate` is installed to your path and you can use it to control Weblate:

weblate list_versions

For Docker image, the script is installed same as above, you can execute it using :command:`docker exec`:

docker exec <container> weblate list_versions

With :program:`docker-compose` this is quite similar, you just have to use :command:`docker-compose run`:

docker-compose run <container> weblate list_versions

add_suggestions

Imports translation from the file as a suggestions to given translation. It skips translations which are same as existing ones, only different ones are added.

Example:

./manage.py --author michal@cihar.com add_suggestions weblate master cs /tmp/suggestions-cs.po

auto_translate

Performs automatic translation based on other component translations.

Example:

./manage.py --user nijel --inconsistent --source phpmyadmin/master phpmyadmin 4-5 cs

changesite

You can use this to change or display site name from command line without using admin interface.

checkgit

Prints current state of backend git repository.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

commitgit

Commits any possible pending changes to backend git repository.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

commit_pending

Commits pending changes older than given age.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

This is most useful if executed periodically from cron or similar tool:

./manage.py commit_pending --all --age=48

cleanuptrans

Cleanups orphaned checks and translation suggestions.

createadmin

Creates admin account with random password unless it is specified.

dumpuserdata

Dumps userdata to file for later use by :djadmin:`importuserdata`

This is useful when migrating of merging Weblate instances.

import_json

Batch import of components based on JSON data.

The imported JSON file structure pretty much corresponds to the component object (see :http:get:`/api/components/(string:project)/(string:component)/`). You always have to include fields name and filemask.

Example of JSON file:

import_project

Batch imports components into project based on file mask.

<project> names an existing project, into which the components should be imported.

The <gitrepo> defines URL of Git repository to use, and <branch> the git branch. To import additional translation components, from an existing Weblate component, use a weblate://<project>/<component> URL for the <gitrepo>.

The repository is searched for directories matching a double wildcard (**) in the <filemask>. Each of these is then added as a component, named after the matched directory. Existing components will be skipped.

To give you some examples, let's try importing two projects.

As first we import The Debian Handbook translations, where each language has separate folder with translations of each chapter:

./manage.py import_project \
    debian-handbook \
    git://anonscm.debian.org/debian-handbook/debian-handbook.git \
    squeeze/master \
    '*/**.po'

Another example can be Tanaguru tool, where we need to specify file format, base file template and has all components and translations located in single folder:

./manage.py import_project \
    --file-format=properties \
    --base-file-template=web-app/tgol-web-app/src/main/resources/i18n/%s-I18N.properties \
    tanaguru \
    https://github.com/Tanaguru/Tanaguru \
    master \
    web-app/tgol-web-app/src/main/resources/i18n/**-I18N_*.properties

Example of more complex parsing of filenames to get correct component and language out of file name like src/security/Numerous_security_holes_in_0.10.1.de.po:

./manage.py import_project \
    --component-regexp 'wiki/src/security/(?P<name>.*)\.([^.]*)\.po$' \
    tails \
    git://git.tails.boum.org/tails master \
    'wiki/src/security/**.*.po'

Filtering only translations in chosen language:

./manage import_project \
    --language-regex '^(cs|sk)$' \
    weblate \
    https://github.com/WeblateOrg/weblate.git \
    'weblate/locale/*/LC_MESSAGES/**.po'

importuserdata

Imports userdata from file created by :djadmin:`dumpuserdata`

importusers

Imports users from JSON dump of Django auth_users database.

You can dump users from existing Django installation using:

./manage.py dumpdata auth.User > users.json

list_ignored_checks

Lists most frequently ignored checks. This can be useful for tuning your setup, if users have to ignore too many of consistency checks.

list_translators

Renders the list of translators by language for the given project:

[French]
Jean Dupont <jean.dupont@example.com>
[English]
John Doe <jd@exemple.com>

You can either define which project or component to use (eg. weblate/master) or use --all to list translators from all existing components.

list_versions

Lists versions of Weblate dependencies.

loadpo

Reloads translations from disk (eg. in case you did some updates in VCS repository).

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

lock_translation

Locks given component for translating. This is useful in case you want to do some maintenance on underlaying repository.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

pushgit

Pushes committed changes to upstream VCS repository.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

rebuild_index

Rebuilds index for fulltext search. This might be lengthy operation if you have huge set of translation units.

update_index

Updates index for fulltext search when :setting:`OFFLOAD_INDEXING` is enabled.

It is recommended to run this frequently (eg. every 5 minutes) to have index uptodate.

unlock_translation

Unnocks given component for translating. This is useful in case you want to do some maintenance on underlaying repository.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

setupgroups

Configures default groups and optionally assigns all users to default group.

setuplang

Setups list of languages (it has own list and all defined in translate-toolkit).

updatechecks

Updates all check for all units. This could be useful only on upgrades which do major changes to checks.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.

updategit

Fetches remote VCS repositories and updates internal cache.

You can either define which project or component to update (eg. weblate/master) or use --all to update all existing components.