Globalizing Mephisto (Part 3)

Welcome to the third part of the Globalizing Mephisto article series where I’ll be talking about how to use this plugin with a multi site mephisto instance.

I’ve updated the plugin to provide full multisite support:

  • All rake tasks now have multi site support, allowing you to easily convert an existing globalized single site mephisto instance into a multisite instance with little effort.
  • You can now also specify separate list of supported locales for each site so that site 1 can support english, french and german, site 2: spanish & catalan and site 3: klingon, esperanto and elfish.
  • SupportedLocales now loads the locales lazily.

Single-site to multi-site.

Create a new site instance

Create a new site instance. e.g. via something like:

1
2
3
s = Site.create(:host => "webtypes.com", :title => "Webtypes", :subtitle => 'We do web, and you?')
s.sections << Section.create(:name=>"Home", :path =>'', :template=>"home.liquid")
s.save

Add the following to environment.rb:

1
2
3
Site.multi_sites_enabled = true 
SupportedLocales.define_by_key('saimonmoore.net',['el-GR', 'es-ES', 'ca-ES'],'en-GB')
SupportedLocales.define_by_key('webtypes.com',['es-ES','nl-NL'],'en-GB')

Create subroots

If you haven’t already globalized your mephisto then follow the same steps as before what are you referring to? ensuring the first step in this list has been done which list?. If you’re upgrading a single site globalized mephisto then just execute:

1
2
svn up vendor/plugins/mephisto_i18n
rake mephisto:i18n:ui:setup_subroots

This will create all the necessary subroots within /public/cache/saimonmoore.net, /public/cache/webtypes.com. It’ll also add symlinks to public/assets so that within your site, you can just access /assets/2007/10/3/myimage.png.

This is how my public directory looks after running setup_subroots for a multisite-enabled mephisto:

(Note: I’ve retained the previous subroots from my single instance site (the ca,es,el directories, but in a multisite system the base doc root is /public/cache/site_host)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
saimon@iris:~/dev/projects/saimonmoore.net$ ll public/
total 32K
-rw-r--r-- 1 saimon  619 2007-04-20 17:04 404.html
-rw-r--r-- 1 saimon  684 2007-04-20 17:04 500.html
drwxr-xr-x 6 saimon  160 2007-05-14 13:57 assets/
drwxr-xr-x 3 saimon  304 2007-04-20 17:04 ca/
drwxr-xr-x 5 saimon  136 2007-05-14 14:02 cache/
-rwxr-xr-x 1 saimon  479 2007-04-20 17:04 dispatch.cgi*
-rwxr-xr-x 1 saimon  859 2007-04-20 17:04 dispatch.fcgi*
-rwxr-xr-x 1 saimon  479 2007-04-20 17:04 dispatch.rb*
drwxr-xr-x 5 saimon  120 2007-04-20 17:04 documents/
drwxr-xr-x 3 saimon  304 2007-04-20 17:04 el/
drwxr-xr-x 3 saimon  304 2007-04-20 17:04 es/
-rw-r--r-- 1 saimon    0 2007-04-20 17:04 favicon.ico
drwxr-xr-x 4 saimon   96 2007-05-11 13:46 images/
-rw-r--r-- 1 saimon 3.3K 2007-04-20 17:04 install.html
drwxr-xr-x 4 saimon   96 2007-04-20 17:04 javascripts/
-rw-r--r-- 1 saimon   99 2007-04-20 17:04 robots.txt
-rw-r--r-- 1 saimon  631 2007-04-20 17:04 sitemap.txt
drwxr-xr-x 4 saimon  136 2007-05-14 09:27 stylesheets/


saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/
total 0
drwxr-xr-x 6 saimon 400 2007-05-14 14:02 saimonmoore.net/
drwxr-xr-x 5 saimon 376 2007-05-14 14:02 webtypes.com/


saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/saimonmoore.net/
total 0
lrwxrwxrwx 1 saimon  24 2007-05-18 13:48 404.html -> ../../../public/404.html
lrwxrwxrwx 1 saimon  24 2007-05-18 13:48 500.html -> ../../../public/500.html
lrwxrwxrwx 1 saimon  38 2007-05-18 13:48 assets -> ../../../public/assets/saimonmoore.net/
drwxr-xr-x 3 saimon 232 2007-05-18 13:50 ca/
drwxr-xr-x 3 saimon 232 2007-05-18 13:50 el/
drwxr-xr-x 3 saimon 232 2007-05-18 13:50 es/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 images/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 javascripts/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 stylesheets/


saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/webtypes.com/
total 0
lrwxrwxrwx 1 saimon  24 2007-05-18 13:48 404.html -> ../../../public/404.html
lrwxrwxrwx 1 saimon  24 2007-05-18 13:48 500.html -> ../../../public/500.html
lrwxrwxrwx 1 saimon  35 2007-05-18 13:48 assets -> ../../../public/assets/webtypes.com/
drwxr-xr-x 3 saimon 232 2007-05-18 13:50 es/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 images/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 javascripts/
drwxr-xr-x 3 saimon 232 2007-05-18 13:50 nl/
drwxr-xr-x 3 saimon  72 2007-05-18 13:54 stylesheets/

saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/webtypes.com/javascripts/
total 0
lrwxrwxrwx 1 saimon 39 2007-05-18 17:35 mephisto -> ../../../../public/javascripts/mephisto/

saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/webtypes.com/images/
total 0
lrwxrwxrwx 1 saimon 34 2007-05-18 17:35 mephisto -> ../../../../public/images/mephisto/

saimon@iris:~/dev/projects/saimonmoore.net$ ll public/cache/webtypes.com/stylesheets/
total 0
lrwxrwxrwx 1 saimon 39 2007-05-18 17:35 mephisto -> ../../../../public/stylesheets/mephisto/

Update your webserver

Finally update your webserver to point to the new subroots. For those using the very recommended nginx server that would be:

1
2
3
4
5
6
7
8
9
server {
    listen       80;

   #Spanish locale: es subdomain
    server_name es.webtypes.com;

    root /var/www/apps/saimonmoore.net/current/public/cache/webtypes.com/es;
    ...
}

showing the change needed for the ‘es’ (spanish) virtual host. Update the rest of the virtual hosts as necessary.

Other fixes

  • Fixes for the automatically generated “switch locale” links via:
    {{ i18n.switch_to_locale_links }}

    These no longer break when browsing the archives/tags, searching for articles or using any custom controllers. WARNING!: As a result of this change it is necessary to update your schema (which basically localizes site.search_path/tag_path) via:

    
    
    {{ rake mephisto:i18n:update_schema }}

    Also, in order for the search feature to be correctly localized, you need to ensure the search form submit url is localized (and the view translation is the same as the model translation of site.search_path )

    e.g.

    
    
    <form method="get" id="sform" action="/{{'search' | t: 'urls'}}">
    Note the use of the ‘urls’ namespace….
  • Within the admin interface, when switching to the base locale, the locale switcher will automatically switch to www.mydomain.com rather than e.g. en.mydomain.com if base locale is english.
  • Moved certain rake tasks related to schema changes to the mephisto:i18n namespace.
  • Updated rake tasks. mephisto:i18n:un/install_schema to accept the LANGS environment variable to easily add more languages to the schema.
  • It’s no longer necessary to manually add the session domain (ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => ’.saimonmoore.net’)) to environments/production.rb as this is now automatically done for you.
  • Various fixes to the Translations module including ordering entries case-insensitively, fixing bug where interpolated keys weren’t being found (‘bla %s ..’), now the search function searches translated text rather than keys.

Custom controllers

If you’re using a mephisto plugin that injects it’s own custom controller and routes (.e.g the contact form plugin) and you’d like to localize it’s url, then simply add something like the following to your routes file:

1
2
3
4
5
6

ActionController::Routing::Routes.draw do |map|
  map.contact_form 'contact' >> :urls, :controller => 'contact_form', :action => 'contact_form'
  map.contact_submit 'contact_submit', :controller => 'contact_form', :action => 'contact_submit', :conditions => { :method => :post }
  Mephisto::Routing.connect_with map
end

Note: The urls in the routes are localized so you need to translate them in the translations tab. This relies on code from the following plugin which has been incorporated into this plugin.

Known bugs/limitations

Currently if multisite mode is enabled, you have to use “SupportedLocales.define_key()” to define the supported locales for each site, even if both site will support the same locales. i.e. You have to duplicate the entries:

1
2
SupportedLocales.define_by_key('saimonmoore.net',['es-ES','nl-NL'],'en-GB')
SupportedLocales.define_by_key('webtypes.com',['es-ES','nl-NL'],'en-GB')
I’ll try and fix this soon so you can just define:

SupportedLocales.define(['es-ES','nl-NL'],'en-GB') 

and both sites will support the same locales.

Future plans

  • There’s been talk on the mephisto forums about using an alternative localization library to localize mephisto which will make it’s way into trunk. I’ve already expressed my opinions on that issue so I won’t regurgitate here, suffice to say that if that happens I will still be supporting and maintaining the globalize-plugin. Of course, it’ll be a complete pain and I’ll have to do a quite a bit of hacking but I’m commited to this (since I use it for my own client applications) so I’ll be maintaining it no matter what.
  • “Upgrade for support with the next version of globalize”. We’re pushing through a lot of changes for the next version of globalize and this will soon be available. When this happens I’ll be updating this plugin for compatibility with the new globalize.
  • “Edge-Rails support”. I’ve decided to only maintain support for use of the plugin with Rails 1.2.x for now. When the next major release of rails occurs, I’ll update the plugin. That said, anyone wanting to provide patches for edge-rails support is more than welcome. (Patches are generally welcome :)
  • “Support for allowing your readers to translate your content for you”. I’m working on a separate plugin for mephisto to allow you to do this. It’ll obviously depend on this one but I’d rather keep it separate for now. Or should I just bundle it together?
  • “Support for publishing/hiding content without translations”. Currently, untranslated content is visible and shown in the base language. With this feature, you’ll be able to selectively hide/show content that has no translation for a whole locale or on an individual basis. I’m also toying with the idea of providing place holders for untranslated content.

Sites running the mephisto_i18n plugin

We’ve got 4 sites up using this plugin:

Other sites

  • onlinevortex.com & bitmapped.onlinevortex.com. (This site by Carlos Mendoza is running a slightly customized version of the plugin to allow specifically named domains to indicate the language rather than using the language code prefix)

If you’ve got a site running this plugin, please let me know so I can add it to the list. Also if you’ve set it up using a different webserver/app server configuration, I’d like to know about it too. Just leave a comment here

Prefer to use a path parameter to define the active locale? Read Part 4

Saimon Moore (also in Greek, Spanish & Catalan :)

7 comments on “Globalizing Mephisto (Part 3)”

  1. Eloise - Hotels A Londres

    Awesome plugin! Honestly I have no idea how complicated is your work, but thanks for taking the time to put your instructions up. Very helpfull. Your plugin is so dang easy to use! Thanks for making it for all of us to use for our blogs. keep up good works!

  2. izmir halı yıkama,bornova halı yıka

    very beatiful :)

  3. sepetli platform

    Thanks for this article and most generaly for this very amazing website :) this information most important for me.

  4. John Alden

    Really nice article :) Web Tasarımı

  5. Shared Files

    right, the process of globalization has reached Mephisto) I wonder how things are with Slavic languages like Russian or Ukrainian?

  6. Treppenlift

    danke für die informationen über treppenlifter

  7. Maxine

    Do it—it’ll be helpful!

Leave your comment