diff options
author | Jochen Topf <jochen@topf.org> | 2011-10-15 10:10:58 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2011-10-15 10:10:58 +0200 |
commit | c15edbe808649eeab0dad44d912e00590d58308b (patch) | |
tree | 582644ad787d7ee1b628485bddf08fbddc5e71b9 /web | |
parent | b0c8aca29aad6ac0adfb8fd78cb52734ff86f3b8 (diff) | |
download | taginfo-c15edbe808649eeab0dad44d912e00590d58308b.tar taginfo-c15edbe808649eeab0dad44d912e00590d58308b.tar.gz |
Fix language switching.
Switching between languages didn't work in some constellations. This seems to
be because of caching of the pages in the browser. I think the browser should
not use the cached page, because it has a different cookie, but it did. So
I changed the expire on normal web pages to 0. (API pages still have a longer
expire.)
Diffstat (limited to 'web')
-rwxr-xr-x | web/taginfo.rb | 15 | ||||
-rw-r--r-- | web/views/layout.erb | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/web/taginfo.rb b/web/taginfo.rb index d76c65d..67310eb 100755 --- a/web/taginfo.rb +++ b/web/taginfo.rb @@ -95,6 +95,12 @@ class Taginfo < Sinatra::Base erb_orig template, options, locals end + # when do we expect the next data update + def next_update + # three hours after midnight UTC + ((Time.utc(Time.now.year(), Time.now.month(), Time.now.day(), 3, 0, 0) + (Time.now.hour < 3 ? 0 : 24)*60*60)-Time.now).to_i.to_i + end + before do if request.cookies['taginfo_locale'] && request.path != '/switch_locale' params[:locale] = request.cookies['taginfo_locale'] @@ -107,8 +113,9 @@ class Taginfo < Sinatra::Base javascript 'lang/' + r18n.locale.code javascript 'taginfo' - # set expire to three hours after midnight UTC - expires(((Time.utc(Time.now.year(), Time.now.month(), Time.now.day(), 3, 0, 0) + (Time.now.hour < 3 ? 0 : 24)*60*60)-Time.now).to_i.to_i) + # set to immediate expire on normal pages + # (otherwise switching languages doesn't work) + expires 0, :no_cache @db = SQL::Database.new('../../data') @@ -125,6 +132,7 @@ class Taginfo < Sinatra::Base before '/api/*' do content_type :json + expires next_update end #------------------------------------- @@ -133,7 +141,7 @@ class Taginfo < Sinatra::Base # It sets a cookie and redirects back to the page the user was coming from. get '/switch_locale' do response.set_cookie('taginfo_locale', params[:locale]) - redirect params[:url] + redirect(TaginfoConfig.get('instance.url') + params[:url]) end #------------------------------------- @@ -268,6 +276,7 @@ class Taginfo < Sinatra::Base #------------------------------------- get '/js/lang/:lang.js' do + expires next_update trans = R18n::I18n.new(params[:lang], 'i18n') return 'var texts = ' + { :flexigrid => { diff --git a/web/views/layout.erb b/web/views/layout.erb index c91f8ac..144e7e2 100644 --- a/web/views/layout.erb +++ b/web/views/layout.erb @@ -14,7 +14,7 @@ <div id="top"> <div id="right"> <form id="set_language" action="/switch_locale"> - <input type="hidden" name="url" value="<%= request.url %>"/> + <input type="hidden" name="url" value="<%= request.path %>"/> <select id="locale" name="locale"> <% r18n.available_locales.sort{ |a,b| a.title <=> b.title }.each do |locale| %> <option value="<%= locale.code %>"<%= locale.code == r18n.locale.code ? ' selected="selected"' : ''%>><%= locale.title %> </option> |