Wiki style: multilingual subdomain on 6.x

Drupal 6.x comes with some nice multilingual features: I want to use these to transform my multilingual website from “prefix path” (http://example.com/en) to language subdomains (http://en.example.com). I like this method on Wikipedia, so it will be a nice additions to my Drupal wiki site.

Prerequisites:

  • Drupal 6.x (tested on Drupal 6.x)
  • A sites/default directory with a settings.php file pointing to your database (locally). You can alternatively create one “sites/example.com” directory on production website. Setting for subdomains will be read here.

If you want to test this on your local machine before any production use, change your /etc/hosts file adding near “localhost” your language subdomains (I will use english* and italian*).

127.0.0.1 localhost example en.example it.example

Go to your Apache configuration (usually /etc/apache2/sites-available/default) and copy your local configuration for each server name (copy and change bold declaration, eg. example it.example en.example).
Note: skip this step if you want to configure subdomains. I use this configuration on my local test machine, but I use subdomains (configured via CPanels) on production website.

<VirtualHost *>
ServerName example
DocumentRoot /var/www/example.com/public_html/drupal6/
<Directory “/var/www/example.com/public_html/drupal6/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

<VirtualHost *>
ServerName it.example
DocumentRoot /var/www/example.com/public_html/drupal6/
<Directory “/var/www/example.com/public_html/drupal6/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

Now visit http://en.example and http://it.example. You should login to these site before proceed, otherwise you cannot set a language URL.

Now, on http://example/ (your localhost server name for this site)

  1. go to Admin > Languages > Configure
  2. set Language negotiation to Domain name only
  3. Save settings
  4. go to Admin > Languages > List and edit a language (you may have to enable it with add language)
  5. On Language domain for english type http://en.example. Do the same (with it subdomain) on Italian language configuration.

Now you can download and install Internationalization module. After that:

  1. Go to Admin > Content types > Your-content-type (tipically Page or similar)
  2. On Workflow settings select Enabled, with translation

Now, create a page selecting “English” as language. Save it and go to Translate tab, then add a translation in the other language. On the bottom of the page you can see a language switcher. Click on it and watch your URL.

If you use Path alias (and/or Pathauto module) you can use the same alias for any subdomain. Why? Because {url_alias} table comes with a nice “language” field. If I want to have two different articles about Ritsuko Akagi, one in English and the other in Italian, using the same path alias, my database table {url_alias} will contains:

pid 	src 	        dst 	                language
6  	node/3  	wiki/Ritsuko_Akagi  	it
8  	node/4  	wiki/Ritsuko_Akagi  	en

For:

That’s all.

Advertisements

2 thoughts on “Wiki style: multilingual subdomain on 6.x

  1. chirale Post author

    Thanks Thomas.

    Update: When passing from local to production site or vice-versa, you have to change drp_languages table manually to specify the correct domain.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s