Installing Weblate

From Minetest Developer Wiki
Jump to: navigation, search

Contents

How to install Weblate 2.0 with Nginx and PostgreSQL on Ubuntu 14.04

This tutorial describes how the Weblate instance at http://translate.minetest.net is installed.

If you wish to install Weblate for a different project, please consult the official Weblate documentation.

All of the following commands are supposed to be run as root. Otherwise run them with sudo.

Preparations

# Install requirements
apt-get install nginx uwsgi uwsgi-plugin-python git memcached fcgiwrap \
    postgresql libpq-dev python-pip python-virtualenv \
    python-dev libxml2-dev libxslt-dev libicu-dev

# If PostgreSQL was not installed before, set the master password
sudo -u postgres psql postgres -c "\password postgres"

# Create database user called "weblate"
sudo -u postgres createuser -D -A -P weblate

# Create database "weblate" owned by "weblate"
sudo -u postgres createdb -O weblate weblate

# Prepare directories that should be writable by weblate
for dir in /var/lib/weblate/{,avatar-cache,repos,whoosh-index}; do
	mkdir -p $dir && chown -R www-data:www-data $dir && chmod -R 700 $dir;
done

# Prepare /var/www
mkdir -p /var/www
chown root:www-data /var/www
chmod 750 /var/www

# Download and extract weblate
cd /var/www
wget http://dl.cihar.com/weblate/weblate-2.0.tar.xz
sha512sum weblate-2.0.tar.xz 
# ^ should print 37898e57a5eacc45fd0a5dca52faea235bd3102dcc6a6fb5455d4edfdabdab4f4c306674f3b71dd9749584645c914b2afa5f2f52e224238088795ba8720b9b47  weblate-2.0.tar.xz
tar -xvf weblate-2.0.tar.xz --no-same-owner
ln -s weblate-2.0 weblate

# Install weblate dependencies into a virtual environment at /var/www/weblate/env
virtualenv /var/www/weblate/env
source /var/www/weblate/env/bin/activate
pip install -r /var/www/weblate/requirements-optional.txt \
            psycopg2 python-memcached pydns

Configure weblate

cd /var/www/weblate
cp weblate/settings_example.py weblate/settings.py
# Generate a secret key, used for SECRET_KEY in weblate/settings.py
# (Copy output to clipboard)
examples/generate-secret-key
vim weblate/settings.py

Add/change the following settings. Leave everything else at the defaults.

DEBUG = False

ADMINS = (
    # people that will receive error notifications, e.g.:
    ('noreply', 'noreply@translate.minetest.net'),
)

DATABASES = {
    'default': {
        # Use 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        # Database name or path to database file if using sqlite3.
        'NAME': 'weblate',
        # Database user, not used with sqlite3.
        'USER': 'weblate',
        # Database password, not used with sqlite3.
        ##### CHANGE THIS! #####
        'PASSWORD': '????',
        # Set to empty string for localhost. Not used with sqlite3.
        'HOST': '127.0.0.1',
        # Set to empty string for default. Not used with sqlite3.
        'PORT': '',
    }
}

TIME_ZONE = None

SECRET_KEY = '...'   # as generated by examples/generate-secret-key

TEMPLATE_LOADERS = (
    ('django.template.loaders.cached.Loader', (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )),
)

AUTHENTICATION_BACKENDS = (
    #'social.backends.google.GoogleOpenId',
    'social.backends.email.EmailAuth',
    'social.backends.github.GithubOAuth2',
    # 'social.backends.suse.OpenSUSEOpenId',
    'weblate.accounts.auth.WeblateUserBackend',
)

GIT_ROOT = '/var/lib/weblate/repos'

SITE_TITLE = 'Minetest Weblate'

OFFLOAD_INDEXING = True   # we have to run manage.py update_index as cronjob

WHOOSH_INDEX = '/var/lib/weblate/whoosh-index'

SERVER_EMAIL = 'noreply@translate.minetest.net'

DEFAULT_FROM_EMAIL = 'noreply@translate.minetest.net'

ALLOWED_HOSTS = ['translate.minetest.net']

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    },
    'avatar': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/lib/weblate/avatar-cache',
        'TIMEOUT': 604800,
        'OPTIONS': {
            'MAX_ENTRIES': 1000,
        },
    }
}

os.environ['HOME'] = '/var/lib/weblate'

# Change as needed, see django documentation
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_HOST_USER = 'noreply@translate.minetest.net'
EMAIL_HOST_PASSWORD = '????'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

Save and exit.

Configure nginx

vim /etc/nginx/sites-available/weblate
server {
	listen 80;
	listen [::]:80 default ipv6only=on;
	server_name translate.minetest.net;
	root /var/www/weblate/weblate;

	location /favicon.ico {
		alias /var/www/weblate/weblate/media/favicon.ico;
		expires 30d;
	}

	location /media/ {
		alias /var/www/weblate/weblate/media/;
		expires 30d;
	}

	location /robots.txt {
		alias /var/www/weblate/weblate/media/robots.txt;
		expires 30d;
	}

	location /static/admin/ {
		alias /var/www/weblate/env/lib/python2.7/site-packages/django/contrib/admin/static/admin/;
		expires 30d;
	}

	location ~ /git(/.*) {
		# export minetest repo as translate.minetest.net/git/minetest

		gzip off;
		root /usr/lib/git-core;
		fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
		fastcgi_param DOCUMENT_ROOT       /usr/lib/git-core;
		fastcgi_param SCRIPT_NAME	  git-http-backend;
		fastcgi_param GIT_HTTP_EXPORT_ALL "";
		fastcgi_param GIT_PROJECT_ROOT    /var/lib/weblate/repos/minetest;
		fastcgi_param PATH_INFO           $1;
		include       /etc/nginx/fastcgi_params;
		fastcgi_pass  unix:/var/run/fcgiwrap.socket;
	}

	location / {
		include uwsgi_params;
		# Needed for long running operations in admin interface
		uwsgi_read_timeout 3600;
		uwsgi_pass 127.0.0.1:8080;
	}
}

Save and exit, then:

ln -s /etc/nginx/sites-{available,enabled}/weblate
rm /etc/nginx/sites-enabled/default  # if this is the first time nginx is installed

Configure uwsgi

vim /etc/uwsgi/apps-available/weblate.ini
[uwsgi]
plugins       = python
master        = true
protocol      = uwsgi
socket        = 127.0.0.1:8080
wsgi-file     = /var/www/weblate/weblate/wsgi.py
virtualenv    = /var/www/weblate/env
python-path   = /var/www/weblate
# Needed if you want to use SSH keys
unenv         = HOME
# Needed for OAuth/OpenID
buffer-size   = 8192
# Increase number of workers for heavily loaded sites
#workers       = 6
# Needed for background processing
enable-threads = true

Save and exit, then:

ln -s /etc/uwsgi/apps-{available,enabled}/weblate.ini

Create weblate database and superuser account

cd /var/www/weblate

# Create tables for weblate
./manage.py syncdb
./manage.py makemigrations
./manage.py migrate

# Create a superuser
./manage.py createsuperuser

Install indexing cronjob

  • crontab -e
*/5 * * * * /var/www/weblate/env/bin/python2.7 /var/www/weblate/manage.py update_index

Restart nginx & uwsgi

  • Make sure firewall settings are correct (i.e. allow incoming TCP connections on port 80)
  • Restart services
service nginx restart
service uwsgi restart

Set up site configuration

  • Log in at http://translate.minetest.net/admin/ with the superuser account
  • Click on Sites, then example.com
  • Replace Domain name and Display name with translate.minetest.net, then save
  • Restart uwsgi again in order to clear the site cache:
service uwsgi restart

Check performance report

  • In admin interface: Click on Home, then Performance report.
  • All results should be green checkmarks.

Add project

  • Click on Home, then Projects -> Add
  • Project name: Minetest
  • URL slug: minetest
  • Project website: http://minetest.net/
  • Mailing list:
  • Translation instructions: http://dev.minetest.net/Translation
  • Push on commit: no
  • Set Translation-Team header: yes
  • Enable ACL: no
  • Enable hooks: yes

Save.

Add subproject

  • Note: saving the subproject will take a while (several minutes) because it clones the minetest repository.
  • Click on Home, then Sub projects -> Add
  • Component name: Minetest
  • URL slug: minetest
  • Project: Minetest
  • Source code repository: https://github.com/minetest/minetest
  • Repository push URL:
  • Repository browser: https://github.com/minetest/minetest/blob/%(branch)s/%(file)s#L%(line)s
  • Exported repository URL:
  • Source string bug report address:
  • Repository branch: master
  • File mask: po/*/minetest.po
  • Monolingual base language file:
  • Base file for new translations:
  • File format: Gettext PO file
  • Additional commit file:
  • Pre-commit script:
  • Locked: no
  • Allow translation propagation: yes
  • Save translation history: yes
  • Enable suggestions: yes
  • Suggestion voting: no
  • Autoaccept suggestions: 0
  • Quality checks flags:
  • Translation license: LGPL-2.1
  • License URL: https://www.gnu.org/licenses/lgpl-2.1.html
  • New language: Use contact form
  • Merge style: Merge
  • Commit message: (keep default)
  • Committer name: Weblate
  • Committer email: noreply@translate.minetest.net

Save, logout & exit the admin interface.

GitHub integration part 1: OAuth

Log in to GitHub and click on Settings -> Applications -> Register new application, then enter the following data:

  • Application name: Minetest Weblate
  • Homepage URL: http://translate.minetest.net/
  • Application description: Web-based translation tool for Minetest
  • Authorization callback URL: http://translate.minetest.net/

Register the application, which will generate a Client ID and a Client Secret.

Edit /var/www/weblate/weblate/settings.py again and define:

SOCIAL_AUTH_GITHUB_KEY = '...'     # Client ID
SOCIAL_AUTH_GITHUB_SECRET = '...'  # Client Secret
SOCIAL_AUTH_GITHUB_SCOPE = ['user:email']

GitHub integration part 2: webhook

The purpose of the webhook is to let weblate automatically pull from the upstream repository whenever it changes.

Go to https://github.com/minetest/minetest/ and click on Settings -> Webhooks & Services -> Add service -> Weblate. (A "service" is a webhook with application-specific defaults built in by GitHub)

In the form that comes up, enter http://translate.minetest.net/ as the URL and click on Add service. Done.

Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox