Globalite problem for website online but not offline

Hello,

I’ve just put online my first website in ruby on rails but I’ve a
problem with the globalite plugin.

Locally the plugin works perfectly, with detection of the browser’s
language. My application is foreseen in French and Dutch but locally,
if the browser is f.e. in English, the application is automatically
opened in Dutch.
But online this specification doesn’t work anymore. For the browser not
in French or dutch, the application doesn’t work properly with a lot of
“localization_missing” errors.

Someone has any idea where the problem is?

To manage the languages available on the website, I’ve created a
controller “language” to define the 2 languages available.

In environment.rb, I’ve added this “Globalite.language = :nl”

Hereunder my application.rb

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time

include AuthenticatedSystem

See ActionController::RequestForgeryProtection for details

Uncomment the :secret if you’re not using the cookie session store

protect_from_forgery # :secret => ‘5880ee74dae8cc2f2a3cc02e4976d601’

around_filter :set_locale
private

Set the locale from the parameters, the session, or the navigator

If none of these works, the Globalite default locale is set (en-*)

def set_locale
@current_path = request.env[‘PATH_INFO’]
@request_method = request.env[‘REQUEST_METHOD’]
if params[:user_locale]
logger.debug params[:user_locale]
Locale.code = params[:user_locale]
#get_matching_ui_locale(params[:user_locale][:code]) #||
session[:locale] || get_valid_lang_from_accept_header ||
Globalite.default_language
session[:locale] = Locale.code
elsif session[:locale]
Locale.code = session[:locale]
else
Locale.code = get_valid_lang_from_accept_header.local_case
end
logger.debug “[globalite] Locale set to #{Locale.code}”
yield
Locale.reset!
end

def get_sorted_langs_from_accept_header
accept_langs = (request.env[‘HTTP_ACCEPT_LANGUAGE’] ||
“en-us,en;q=0.5”).split(/,/) rescue nil
return nil unless accept_langs
wl = {}
accept_langs.each {|accept_lang|
if (accept_lang + ‘;q=1’) =~ /^(.+?);q=([^;]+)./
wl[($2.to_f rescue -1.0)]= $1
end
}
logger.debug “[globalite] client accepted locales: #{wl.sort{|a,b|
b[0] <=> a[0] }.map{|a| a[1] }.to_sentence}”
wl.sort{|a,b| b[0] <=> a[0] }.map{|a| a[1] }
end
def get_valid_lang_from_accept_header
get_sorted_langs_from_accept_header.detect{|l|
get_matching_ui_locale(l) }
end
def get_matching_ui_locale(locale)
lang = locale[0,2].downcase
if Globalite.ui_locales.values.include?(locale.local_case)
locale.local_case
end
Globalite.ui_locales.values.each do |value|
value.to_s =~ /#{lang}-
/ ? value : nil
end
end
end
class String
def local_case
if self[3,5]
“#{self[0,2]}-#{self[3,5].upcase}”.to_sym
else
“#{self[0,2]}-*”.to_sym
end
end
end

Hereunder where I defin the language in my controllers:
@homepages =
Homepage.find_all_by_language_id(Language.resolve(Locale.code.to_s[0,2]))

Thanks in advance for your help!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs