# Globalite problem for website online but not offline

**URL:** <https://www.ruby-forum.com/t/globalite-problem-for-website-online-but-not-offline/145548>\
**Category:** Rails\
**Created:** [August 11, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/globalite-problem-for-website-online-but-not-offline/145548 "2008-08-11T13:45:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![san1981](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@san1981](https://www.ruby-forum.com/u/san1981)\
**Post date:** [August 11, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/globalite-problem-for-website-online-but-not-offline/145548/1 "2008-08-11T13:45:31Z")

</div>

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!
