This repository has been archived by the owner on Apr 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
267 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
jQuery -> | ||
|
||
$('.locale-line').live 'click', (event) -> | ||
event.preventDefault() | ||
translator = new Translator($(this).data('key'),$(this).data('locale'),$(this).data('value')) | ||
|
||
class Translator | ||
constructor: (_key,_locale,_default) -> | ||
@locale = _locale | ||
@default = _default | ||
@key = _key | ||
@is_counter = @default instanceof Object | ||
|
||
bootbox.dialog( @dialog, [ | ||
{"label": "OK", "class":"btn-primary", "callback": @update}, | ||
{"label": "Cancel", "class":"btn-default", "callback": @cancel}, | ||
]) | ||
|
||
dialog: => | ||
html_form = "<h1>Translate</h1>" + | ||
"<p>Locale: #{@locale}<br/>Key: #{@key}</p><form>" | ||
if !@is_counter | ||
html_form += "<textarea id='new-translation' style='width: 90%'>#{@default}</textarea>" | ||
else | ||
html_form += "Zero:<br/><input type='text' name='zero' style='width: 90%' id='new-translation-zero' value='" | ||
html_form += @remove_extra_chars(@default['zero']) + "'>" | ||
html_form += "<br/><br/>One:<br/><input name='one' type='text' style='width: 90%' id='new-translation-one' value='" | ||
html_form += @remove_extra_chars(@default['one']) + "'>" | ||
html_form += "<br/></br>Other:<br/><input name='other' type='text' style='width: 90%' id='new-translation-other' value='" | ||
html_form += @remove_extra_chars(@default['other']) + "'>" | ||
html_form += "</form>" | ||
return html_form | ||
|
||
update: => | ||
if @is_counter | ||
result = { | ||
'zero': $('#new-translation-zero').val(), | ||
'one': $('#new-translation-one').val(), | ||
'other':$('#new-translation-other').val() | ||
} | ||
else | ||
result = $('#new-translation').val() | ||
$.ajax("/translations", { | ||
type: 'POST', | ||
data: { | ||
translation: { | ||
locale: @locale, | ||
key: @key, | ||
value: result | ||
} | ||
} | ||
}) | ||
|
||
cancel: => | ||
# NOOP | ||
|
||
remove_extra_chars: (_str) => | ||
_str.replace(/^\[\"/, '').replace(/\"\]$/,'').replace(/'/g, ''') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- encoding : utf-8 -*-" | ||
class TranslationsController < ApplicationController | ||
|
||
before_filter :ensure_translator_facility | ||
|
||
def index | ||
@translations = TRANSLATION_STORE | ||
end | ||
|
||
def show | ||
@translations = TRANSLATION_STORE | ||
render :index | ||
end | ||
|
||
|
||
# {"translation"=>{"locale"=>"en", "key"=>"close", "value"=>"close"}, "action"=>"create", "controller"=>"translations"}): | ||
def create | ||
@locale = params[:translation][:locale] | ||
@key = params[:translation][:key] | ||
@value = save_by_key(@locale, @key, params[:translation][:value]) | ||
end | ||
|
||
private | ||
def ensure_translator_facility | ||
redirect_to signin_path, alert: t(:access_denied) unless can_read?('Locale Admin') | ||
end | ||
|
||
def save_by_key(locale, key, value) | ||
I18n.backend.store_translations(locale, {key => value}, :escape => false) | ||
value | ||
end | ||
|
||
def prepare_locale_value_for_js(locale,key) | ||
_locale=I18n.locale | ||
I18n.locale = locale | ||
_rc = (_in = I18n.t(key.to_sym)).class == Hash ? combine_store_keys(locale,key,_in) : _in | ||
I18n.locale=_locale | ||
_rc | ||
end | ||
helper_method :prepare_locale_value_for_js | ||
|
||
def combine_store_keys(locale,key,_in) | ||
_zero = I18n.backend.backends.first.store.get( [locale,key,"zero"].join('.') ) | ||
if _zero | ||
_one = I18n.backend.backends.first.store.get( [locale,key,"one"].join('.') ) | ||
_other = I18n.backend.backends.first.store.get( [locale,key,"other"].join('.') ) | ||
{ :zero => _zero, :one => _one, :other => _other }.to_json | ||
else | ||
_in.to_json | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%tr{id: "translation-tr-#{locale}-#{key.gsub(/\./, '-')}", class: 'locale-line', 'data-locale' => locale, 'data-key' => key, 'data-value' => _json = prepare_locale_value_for_js(locale,key) } | ||
%td= locale.to_s | ||
- I18n.locale = locale | ||
%td{id: "translation-#{locale}-#{key}"}= _json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.well | ||
.pull-right | ||
= form_tag edit_page_translations_path do | ||
= hidden_field_tag :used_keys, used_keys: I18n.used_locales | ||
= submit_tag t(:edit_translations), class: "btn btn-primary" | ||
%h3= t(:used_locales) | ||
|
||
%ul | ||
- I18n.used_locales.each do |key| | ||
%li | ||
%strong= key | ||
="=>" | ||
= t(key) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$("#translation-tr-<%= @locale %>-<%= @key.gsub(/\./, '-') %>").replaceWith('<%= j render "locale_tr", locale: @locale, key: @key %>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%h1= title t(:translations) + " (#{I18n.locale})" | ||
|
||
- gui_locale = I18n.locale | ||
%table.full-width.table.stripped | ||
- eval(params[:used_keys])[:used_keys].map {|k| k.to_s.gsub(/\A..\./,'')}.uniq.each do |key| | ||
%tr | ||
%td{colspan: 1+I18n.available_locales.count} | ||
%h3= key | ||
- I18n.available_locales.each do |locale| | ||
- I18n.locale=locale | ||
= render 'locale_tr', locale: locale, key: key | ||
- I18n.locale=gui_locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module I18n | ||
|
||
def self.track_locales=(new_value) | ||
@track_locales = new_value | ||
@used_locales = [] | ||
end | ||
|
||
def self.track_locales? | ||
@track_locales ||= false | ||
end | ||
|
||
def self.translate(*args) | ||
return super unless track_locales? | ||
@used_locales += [args[0]] | ||
super | ||
end | ||
|
||
def self.used_locales | ||
@used_locales.sort{|a,b| a.to_s <=> b.to_s}.uniq | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def get_redis_db_id | ||
_yml_file = File.expand_path('../../redis.yml', __FILE__) | ||
if File.exist?(_yml_file) | ||
yml = YAML.load( File.read(_yml_file) ) | ||
db = yml[Rails.env]['db'] | ||
Rails.logger.info("Using Redis database #{db} as defined in #{_yml_file}") | ||
db | ||
else | ||
Rails.logger.warn("File #{_yml_file} doesn't exist. Using default Redis database (0)") | ||
0 | ||
end | ||
end | ||
|
||
TRANSLATION_STORE = Redis.new(db: get_redis_db_id) | ||
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(TRANSLATION_STORE), I18n.backend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test: | ||
db: 0 | ||
|
||
development: | ||
db: 1 | ||
|
||
production: | ||
db: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,8 @@ developer_mail_address: "[email protected]" | |
# show_user_menu: true | ||
# supress_global_search: false | ||
|
||
# default, when not defined = 4 | ||
paginate_users_per_page: 2 | ||
paginate_pages_per_page: 2 | ||
# paginate_users_per_page: 4 | ||
# paginate_pages_per_page: 4 | ||
|
||
# TIMELINE BEHAVIOR | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- encoding : utf-8 -*-" | ||
require "rspec" | ||
|
||
describe "Translations with redis" do | ||
|
||
it "should reads from redis" do | ||
I18n.backend.store_translations(:en, {"test_redis" => "Test redis backend"}, :escape => false) | ||
I18n.t(:test_redis).should == "Test redis backend" | ||
I18n.backend.store_translations(:en, {"test_redis" => nil}, :escape => false) | ||
I18n.t(:test_redis).should == "translation missing: en.test_redis" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- encoding : utf-8 -*-" | ||
require "rspec" | ||
|
||
describe TranslationsController do | ||
|
||
before(:each) do | ||
user=test_user "Translator", "babelfish", ["Locale Admin"] | ||
sign_in_user name: "Translator", password: "babelfish" | ||
end | ||
|
||
it "should list translations keys" do | ||
click_button "Edit this translations" | ||
page.should have_content "edit_profile en Edit profile de Benutzerkonto bearbeiten" | ||
end | ||
end |