Jump to content

Content translation/cxserver/Setup

From mediawiki.org
Note: Using Docker will make this setup easier. Please refer Content Translation Docker configuration documentation if you like to use it



Get the code


Content Translation Server


If you want to do an anonymous checkout:

git clone https://gerrit.wikimedia.org/r/mediawiki/services/cxserver

Or if you plan to hack CXServer, then please follow the Gerrit 'getting started' docs and use an authenticated checkout url instead, such as:

git clone ssh://<user>@gerrit.wikimedia.org:29418/mediawiki/services/cxserver



Install nodejs 8 or higher. When you are using Ubuntu and depending on OS version you may not end up with the most recent version of nodejs please read this [1] first before you proceed:

sudo apt-get install nodejs npm
nodejs --version # should now print 8 or higher

For other systems, see:

JS dependencies


Install the JS dependencies. Run this command in the cxserver directory:

npm install

Dictd Server



sudo apt-get install dictd

To install language pair,

sudo apt-get install dict-freedict-xxx-yyy

Where xxx and yyy are two different languages.

On CentOS 7 instead do:

wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/Kenzy:/packages/CentOS_7/x86_64/dictd-server-1.12.0-6.4.x86_64.rpm
rpm -Uvh dictd-server-1.12.0-6.4.x86_64.rpm

RESTBase Server




See RESTBase/Installation.

Server Configuration


An example configuration file is given as config.dev.yaml and config.prod.yaml.

RESTBase configuration section

        method: '{{request.method}}'
        uri: http://localhost:7231/YOUR_WIKI_WEBSITE/v1/{+path}
        query: '{{ default(request.query, {}) }}'
        headers: '{{request.headers}}'
        body: '{{request.body}}'

Apertium configuration section

          api: http://localhost:2737

The server expected on localhost:2737 is then Apertium-apy . (See http://wiki.apertium.org/wiki/Apy for instructions; you'll have to install Apertium and at least one language pair too). Adjust configuration according to your requirement and restart the server.

Run the server


Using node

$ nodejs server.js

On CentOS 7:

$ node server.js

Using npm

$ npm start

As a cxserver command


Following step is to be performed only once. You might have to use 'sudo'.

$ npm link .

Subsequently, just use following to start the server.

$ cxserver

Then browse to http://localhost:8080/v1 You'll see the server playground page.

Running it in secure mode (https)


In the configuration file, provide the SSL certificate details and set value of 'secure' as true



To run the ContentTranslation server:

$ npm run-script debug

It will open Chrome developer tools with the ContentTranslation source code. You can debug the code just like a web application. You can also edit the code and save from the debugger.

Starting cxserver automatically


There are many ways to start services automatically, consult your server's operating system documentation.



On Ubuntu and other operating systems using Upstart, one approach is

sudo ln -s /lib/init/upstart-job /etc/init.d/cxserver
sudo vi /etc/init/cxserver.conf

And, use following upstart script template:

# Upstart job configuration for cxserver

description "cxserver service"

start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]

setuid "www-data"
setgid "www-data"

env NODE_PATH="/path/to/cxserver/node_modules"

chdir "/path/to/cxserver"
exec npm start


To start cxserver,

sudo service cxserver start

To stop cxserver,

sudo service cxserver stop



Upstart can be debug using log messages at /var/log/syslog.



On recent versions of Debian, Fedora and other operating systems using systemd, use a cxserver.service unit file similar to the following template (modify the file paths as appropriate) and place file at /lib/systemd/system/ directory.

Description=MediaWiki Content Translation service
Wants=local-fs.target network.target
After=local-fs.target network.target


ExecStart=/usr/bin/node /path/to/cxserver/server.js

To start cxserver,

sudo service cxserver start

To stop cxserver,

sudo service cxserver stop

If you change in service script, you need to reload script by,

sudo systemctl --system daemon-reload



Systemd scripts logs messages at /var/log/syslog. It can be customized using StandardOutput= in cxserver.service script.

Backend Services





sudo apt-get install varnish



1. Configure varnish http accelerator port:

edit /etc/default/varnish

Example configuration to run varnish on port 8000

DAEMON_OPTS="-a :8000 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

2. Configure the varnish default backend:

edit /etc/varnish/default.vcl

backend default {
    .host = "";
    .port = "8080";

3. Restart the varnish:

sudo service varnish restart

Make sure you are running cxserver nodejs server on port 8080 - the backend configuration of varnish

cxserver --port=8080 will be your server URL with varnish will be your server URL without varnish

4. Configure cxclient's wgContentTranslationServerURL to

Extensions dependencies


Content translation extension requires following extensions as dependencies.

  1. BetaFeatures
  2. Cite
  3. UniversalLanguageSelector
  4. VisualEditor
  5. GlobalPreferences

Also see