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.)
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.
- 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.
- 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.
- 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.