Content translation/cxserver/Setup

Jump to: navigation, search


Get the code[edit]

Content Translation Server[edit]

If you want to do an anonymous checkout:

git clone

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>


Install nodejs 0.10 or higher. When you are using Ubuntu and depending on OS version you will 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 v0.10.x or higher

On Ubuntu Server 12.04 LTS instead do (to get v0.10.x)[1]:

sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs=0.10*
nodejs --version # should now print v0.10.x

On CentOS 7 instead do (for nodejs 6.x version):

curl -sL | bash -  #Follow the instructions
node --version # should now print v6.x.x

For other systems, see:

JS dependencies[edit]

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

npm install

Dictd Server[edit]


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:

rpm -Uvh dictd-server-1.12.0-6.4.x86_64.rpm

RESTBase Server[edit]


git clone

From the restbase project directory, install the Node dependencies:

npm install


cp config.example.yaml config.yaml

Edit the config.yaml file in these parts:

 - pattern: http://YOUR_WIKI_API_ENDPOINT
 - pattern: http://YOUR_PARSOID_SERVER:PORT
   # XXX Check API URL!
   apiUriTemplate: http://YOUR_WIKI_API_ENDPOINT
   # XXX Check Parsoid URL! localhost is the default configuration

YOUR_WIKI_API_ENDPOINT is the location of your wiki's api.php. For example, MediaWiki's API endpoint is See The endpoint.

YOUR_WIKI_WEBSITE is the base URL of your wiki. For example, MediaWiki's base URL is

YOUR_PARSOID_SERVER:PORT in the host: and pattern: entries must correspond to the URL and port of your Parsoid server. If your Parsoid and RESTBase servers are on the same machine, then localhost is a valid URL.

Run the server and Test[edit]

To run the RESTBase server use the same procedure to run the cxserver.

For testing execute:

curl http://YOUR_RESTBASE_SERVER:7231/YOUR_WIKI_WEBSITE/v1/page/html/Main_Page

You should see the HTML content of the Main_Page.

In a browser you can also test by navigating to


and you should see a page titled Wikimedia REST API. On this page you can test all manner of RESTBase methods and variables.

For other testing refer to github.

If Restbase Port is blocked[edit]

If you don't see the page, your Restbase port may be blocked.


if you get {"items":["page","transform"]}, your restbase server port is ok. but if you didn't get {"items":["page","transform"]}, then:

curl http://localhost:7231/YOUR_WIKI_WEBSITE/v1/

if you get {"items":["page","transform"]}, that means the Restbase server is not bad, but you can't access the port; To bypass the block, you can set proxypass to your httpd configuration. if you use apache, you can make a restbase.conf file like this, and put on /etc/httpd/conf.d of YOUR_RESTBASE_SERVER.

# Restbase.conf : usually on /etc/httpd/conf.d/

<VirtualHost *:80>
          ProxyPreserveHost On
          ProxyPass /YOUR_WIKI_WEBSITE/ http://localhost:7231/YOUR_WIKI_WEBSITE/
          ProxyPassReverse /YOUR_WIKI_WEBSITE/ http://localhost:7231/YOUR_WIKI_WEBSITE/

          # MediaWiki is located here:
          DocumentRoot /var/www/html


You should restart httpd(by service httpd restart or some means). now In a browser you can navigate to


and you should see a page titled Wikimedia REST API.

And in this setting, you should add below to LocalSettings.php for VisualEditor.

$wgVisualEditorRestbaseURL = "http://YOUR_RESTBASE_SERVER/YOUR_WIKI_WEBSITE/v1/page/html/";
$wgVisualEditorFullRestbaseURL = "http://YOUR_RESTBASE_SERVER/YOUR_WIKI_WEBSITE/";

Starting RESTBase Server automatically[edit]

For installing the RESTBase server as a service with systemd, create this file in the /lib/systemd/system/ directory (/etc/systemd/system/ for CentOS 7 and /usr/lib/systemd/system/ for openSUSE) and name it restbase.service.

Description=Mediawiki RESTBase Service


ExecStart=/usr/bin/node /path_to_restbase-master/server.js

Replace path_to_restbase-master with the path to your restbase project directory.

To automatically start the RESTBase server at system startup,

systemctl enable restbase.service

To control the RESTBase server,

sudo systemctl start|stop|restart|status restbase.service

If you ever change the restbase.service script, you need to reload it with,

sudo systemctl --system daemon-reload

Server Configuration[edit]

An example configuration file is given as and

RESTBase configuration section[edit]

        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[edit]

          api: http://localhost:2737

The server expected on localhost:2737 is then Apertium-apy . (See 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[edit]

Using node[edit]

$ nodejs server.js

On CentOS 7:

$ node server.js

Using npm[edit]

$ npm start

As a cxserver command[edit]

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)[edit]

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[edit]

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


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[edit]



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[edit]

Content translation extension requires following extensions as dependencies.

  1. BetaFeatures[2]
  2. CLDR[3]
  3. EventLogging[4]
  4. UniversalLanguageSelector[5]