summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2012-01-25 10:53:39 +0100
committerJochen Topf <jochen@topf.org>2012-01-25 10:53:39 +0100
commitbeaabfd589a9f04ea5ea6e40c8ab1515ceb0aefa (patch)
treea20ee1f91ac81b36e29ab75329c62a5ee2b44b1c /web
parentb8ffeb2230639bbb3ed05cb04ec13c08d1866c16 (diff)
downloadtaginfo-beaabfd589a9f04ea5ea6e40c8ab1515ceb0aefa.tar
taginfo-beaabfd589a9f04ea5ea6e40c8ab1515ceb0aefa.tar.gz
Add page showing i18n translations
Diffstat (limited to 'web')
-rw-r--r--web/lib/ui/i18n.rb45
-rw-r--r--web/public/css/taginfo.css3
-rw-r--r--web/public/robots.txt1
-rwxr-xr-xweb/taginfo.rb2
-rw-r--r--web/views/taginfo/i18n.erb35
5 files changed, 85 insertions, 1 deletions
diff --git a/web/lib/ui/i18n.rb b/web/lib/ui/i18n.rb
new file mode 100644
index 0000000..d801daf
--- /dev/null
+++ b/web/lib/ui/i18n.rb
@@ -0,0 +1,45 @@
+# web/lib/ui/i18n.rb
+class Taginfo < Sinatra::Base
+
+ def i18n_walk(line, level, path, en, other)
+ out = ''
+ en.keys.sort.each do |key|
+ name = path.sub(/^\./, '') + '.' + key
+ name.sub!(/^\./, '')
+ if en[key].class == Hash
+ if other.nil?
+ out += line.call(level, "<b>#{key}</b>", name, '', '<span style="color: red;">MISSING</span>')
+ else
+ out += line.call(level, "<b>#{key}</b>", name, '', '')
+ out += i18n_walk(line, level+1, path + '.' + key, en[key], other[key])
+ end
+ else
+ if other.nil?|| ! other[key]
+ out += line.call(level, key, name, en[key], '<span style="color: red;">MISSING</span>')
+ else
+ out += line.call(level, key, name, en[key], other[key])
+ end
+ end
+ end
+ out
+ end
+
+ get '/taginfo/i18n' do
+ @lang = params[:lang] || 'de'
+ @i18n_en = YAML.load_file("i18n/en.yml")
+ begin
+ @i18n_lang = YAML.load_file("i18n/#{@lang}.yml")
+ rescue
+ @error = "Unknown language: #{@lang}"
+ end
+
+ c = 'even'
+ @line = lambda { |level, key, name, en, other|
+ c = (c == '') ? 'even': ''
+ "<tr><td class='#{c}' style='padding-left: #{ level * 16 + 6 }px;'><span title='#{ name }'>#{ key }</span></td><td class='#{c}'>#{ en }</td><td class='#{c}'>#{ other }</td></tr>"
+ }
+
+ erb :'taginfo/i18n'
+ end
+
+end
diff --git a/web/public/css/taginfo.css b/web/public/css/taginfo.css
index 584d2d6..96664ba 100644
--- a/web/public/css/taginfo.css
+++ b/web/public/css/taginfo.css
@@ -157,6 +157,7 @@ span.customStyleSelectBox {
-chrome-border-radius: 4px;
-o-border-radius: 4px;
font-size: 90%;
+ text-align: left;
}
span.customStyleSelectBox.changed { }
@@ -191,7 +192,7 @@ div#header div#header_forms form {
padding-left: 22px;
}
-select#locale {
+select#locale, select#lang {
font-size: 90%;
background-color: #ffffff;
width: 98px;
diff --git a/web/public/robots.txt b/web/public/robots.txt
index 5b11141..f39fb5c 100644
--- a/web/public/robots.txt
+++ b/web/public/robots.txt
@@ -8,4 +8,5 @@ Disallow: /js
Disallow: /keys
Disallow: /search/suggest
Disallow: /tags
+Disallow: /taginfo/i18n
Disallow: /test
diff --git a/web/taginfo.rb b/web/taginfo.rb
index 93ec312..6dd6700 100755
--- a/web/taginfo.rb
+++ b/web/taginfo.rb
@@ -30,6 +30,7 @@
require 'rubygems'
require 'json'
require 'sqlite3'
+require 'yaml'
require 'sinatra/base'
require 'sinatra/r18n'
@@ -188,6 +189,7 @@ class Taginfo < Sinatra::Base
load 'lib/ui/keys_tags.rb'
load 'lib/ui/reports.rb'
load 'lib/ui/search.rb'
+ load 'lib/ui/i18n.rb'
load 'lib/ui/test.rb'
# run application
diff --git a/web/views/taginfo/i18n.erb b/web/views/taginfo/i18n.erb
new file mode 100644
index 0000000..8445efa
--- /dev/null
+++ b/web/views/taginfo/i18n.erb
@@ -0,0 +1,35 @@
+<div class="pre">
+ <h1>Translations of taginfo texts</h1>
+</div>
+<div class="box resize" style="overflow: auto;">
+<% if @error %>
+ <p style="color: red;"><%= @error %></p>
+<% else %>
+ <table class="list">
+ <th></th>
+ <th><a class="extlink" style="float: right;" href="https://github.com/joto/taginfo/blob/master/web/i18n/en.yml">on github</a>English</th>
+ <th><a class="extlink" style="float: right;" href="https://github.com/joto/taginfo/blob/master/web/i18n/<%= @lang %>.yml">on github</a>
+<form action="/taginfo/i18n" method="GET">
+ <select id="lang" name="lang">
+<% r18n.available_locales.sort{ |a,b| a.title <=> b.title }.each do |locale| %>
+ <option value="<%= locale.code %>"<%= @lang == locale.code ? ' selected="selected"' : ''%>><%= locale.title %></option>
+<% end %>
+ </select>
+</form>
+ </th>
+<%= i18n_walk(@line, 0, '', @i18n_en, @i18n_lang) %>
+ </table>
+</div>
+<%
+end
+javascript do
+ JS.raw(<<"JAVASCRIPT")
+function page_init() {
+ jQuery('span[title]').tipsy({ opacity: 1, delayIn: 500, gravity: 'w' });
+ jQuery('#lang').bind('change', function() {
+ jQuery('form').submit();
+ });
+}
+JAVASCRIPT
+end
+%>