Re: Multilingual website in Sinatra - Setting default language

358 views
Skip to first unread message

Dave Sag

unread,
May 4, 2013, 7:24:18 PM5/4/13
to sina...@googlegroups.com
Hi Marcos,

When  first started experimenting with Sinatra I wrote a thing called Frank (original name not!) that incorporated a whole lot of Sinatra-r18n stuff.  (you can see the code at https://github.com/davesag/Frank but it's very out of date now, but it might give you some ideas.)

The key to what you want to do is to have a 'before' method, such as

  before do
    session[:locale] = params[:locale] if params[:locale] #the r18n system will load it automatically
    load_active_user  # pull user from database or whatever based on session info.
    session[:locale] = @active_user.locale if @active_user != nil && session[:locale] == nil
  end

then you can set the default location via a language menu and record the user's preferred locale choice against their database record.

Rather than have different paths for each language group (something I did with Frank but have steered away from in real apps) I just ensure that all of the text that appears in my pages is properly tokenised in yml files within an i18n folder.

Cheers

Dave


On Thursday, May 2, 2013 11:51:24 AM UTC+10, marcqs wrote:
I wonder how I can make a multilingual website with Sinatra + Sinatra-r18n that has the following features.
  1. Default language other than English. -- (For some reason I failed to do this with any of the following options R18n :: I18n.default = 'es'; R18n.set ('es',' ./i18n / '), or R18n.default_places ='. / i18n / '. some examples that I found on the web.
  2. Related to the above, that the default language always be the same regardless of the localization of the browser etc.. so that the user can switch the language through a language selector.
  3. That the route to the default language be "website.com/" and of others "website.com/en/" "website.com/ru/" etc. (a behavior similar to the Wordpress' plugin qTranslate).

I would appreciate very much if someone can point me to some working example or anything to help me on this.

Thank you.

Marcos.

marcqs

unread,
May 7, 2013, 4:22:51 PM5/7/13
to sina...@googlegroups.com
Hi Dave,

Thanks for your answer
. I'll give a look to "Frank" and I'll let you know how it goes.


Marcos.
Reply all
Reply to author
Forward
0 new messages