summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2011-10-15 10:10:58 +0200
committerJochen Topf <jochen@topf.org>2011-10-15 10:10:58 +0200
commitc15edbe808649eeab0dad44d912e00590d58308b (patch)
tree582644ad787d7ee1b628485bddf08fbddc5e71b9
parentb0c8aca29aad6ac0adfb8fd78cb52734ff86f3b8 (diff)
downloadtaginfo-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.)
-rw-r--r--taginfo-config-example.json2
-rwxr-xr-xweb/taginfo.rb15
-rw-r--r--web/views/layout.erb2
3 files changed, 15 insertions, 4 deletions
diff --git a/taginfo-config-example.json b/taginfo-config-example.json
index 9dbc624..efcbcab 100644
--- a/taginfo-config-example.json
+++ b/taginfo-config-example.json
@@ -3,6 +3,8 @@
{
// You probably want to change all these.
"instance": {
+ // url prefix for the site
+ "url": "http://localhost:4567",
// Used in the title of all HTML pages.
"name": "Test Taginfo",
// Description that appears if you click on the instance icon in the upper left.
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 %>&nbsp;</option>