Localize date format using i18n

Tested on:

  1. Drupal 6.16+
  2. Date API 6.x-2.4
  3. Internationalization 6.x-1.3

Any date format is stored as system variable (on the global $conf variable).

Since Internationalization module allows to declare some system variables as Multilingual, you could add to your $conf[‘i18n_variables’] on settings.php these lines to use different date format for different languages:

$conf['i18n_variables'] = array(
// Other variables
// bla bla bla
// Date variables
'date_format_long',
'date_format_medium',
'date_format_short',
'date_first_day',
);

date_format variables are Long, Medium and Short date format, used in many places (including Views).

date_first_day is the first day displayed on calendars (e.g. Sunday for English, Monday for Italian).

Note that you have to save the value twice via:

http://example.com/it/admin/settings/date-time
http://example.com/en/admin/settings/date-time

And one more time:

http://example.com/it/admin/settings/date-time

After the first time, you can change format as you like without double checking.

See also:

How to automatically translate your Drupal module

You’ve created your module. But how to translate it into different languages?

Tested with:

  • Translation template extractor 6.x-3.0
  • Drupal 6.x
  • English default + Italian translation

Prerequisites:

  • Another language active apart default (English)
  • Use t() function for all translatable string, including ones on my_funny_module.admin.inc (Administration interface).

If you use t() function correctly on your module, you can create your own translation using the handy Translation template extractor module.

  1. Download and install Translation template extractor module.
  2. Create a directory named “translations” within my_funny_module directory (your module directory)
  3. Go to admin/build/translate/extract
  4. Select your module from Directory lists
  5. Select “Language independent template” and click “Extract”
  6. Save file to my_funny_module/translations directory as my_funny_module.pot
  7. In the same screen, select “Template file for Italiano translations” (where Italiano is your destination language)
  8. If you’ve already translated some strings into Italiano language, check “Include translations” to include these strings
  9. Click “Extract”, and save file to my_funny_module/translations directory as it.po, where “it” is the ISO 639-2 code for Italiano language
  10. You can add information about translation changing the first part of both files (translator mail, name, etc.)

Now, when you install your module translation strings will be added automatically. If you apply some changes to these files, and in any case the first time you complete this procedure on an active module, you have to refresh translation cache. To do this, go to admin/build/translate/refresh and use Refresh strings and Update translations after you’ve checked all boxes. If problem persists (strings are not updated or you got some weird errors), try to reinstall your module.

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.