exvo_globalize 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +7 -0
- data/Rakefile +1 -0
- data/app/controllers/globalize_translations_controller.rb +8 -0
- data/app/models/globalize_translation.rb +20 -0
- data/config/routes.rb +5 -0
- data/exvo_globalize.gemspec +24 -0
- data/lib/exvo_globalize/engine.rb +16 -0
- data/lib/exvo_globalize/globalize_store.rb +63 -0
- data/lib/exvo_globalize/version.rb +3 -0
- data/lib/exvo_globalize.rb +6 -0
- metadata +111 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright © 2011 Exvo.com Development BV
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Exvo Globalize
|
2
|
+
|
3
|
+
This plugin lets you make use of the Globalize app (http://store.exvo.com/teams/companies/globalize/positions/translator)
|
4
|
+
to handle the translation of your Rails app into multiple languages.
|
5
|
+
|
6
|
+
|
7
|
+
Copyright © 2011 Exvo.com Development BV, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class GlobalizeTranslationsController < ApplicationController
|
2
|
+
respond_to :json
|
3
|
+
|
4
|
+
def index
|
5
|
+
# returns {"default_locale":"en","pl":{"hello.world":"Witaj \u015bwiecie","hello.earth":"Witaj ziemio"},"en":{"hello.world":"Hello world","hello.earth":"Hello Earth"}}
|
6
|
+
respond_with I18n.backend.available_translations.merge({ :default_locale => I18n.default_locale })
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class GlobalizeTranslation < ActiveRecord::Base
|
2
|
+
|
3
|
+
# based on https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/translation.rb
|
4
|
+
|
5
|
+
def self.locale(locale)
|
6
|
+
scoped(:conditions => { :locale => locale.to_s })
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.lookup(keys)
|
10
|
+
column_name = connection.quote_column_name('key')
|
11
|
+
keys = Array(keys).map! { |key| key.to_s }
|
12
|
+
namespace = "#{keys.last}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%"
|
13
|
+
scoped(:conditions => ["#{column_name} IN (?) OR #{column_name} LIKE ?", keys, namespace])
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.available_locales
|
17
|
+
find(:all, :select => 'DISTINCT locale').map { |t| t.locale.to_sym }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require "exvo_globalize/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "exvo_globalize"
|
8
|
+
s.version = ExvoGlobalize::VERSION
|
9
|
+
s.authors = ["Paweł Gościcki"]
|
10
|
+
s.email = ["pawel.goscicki@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/Exvo/exvo_globalize"
|
12
|
+
s.summary = 'Rails gem to translate your app into multiple languages using Globalize web app'
|
13
|
+
s.description = 'It exposes `/globalize/translations.json` with JSON of all translations in the app'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.licenses = ['MIT']
|
21
|
+
|
22
|
+
s.add_dependency 'rails', ['>= 3.0.0']
|
23
|
+
s.add_dependency 'i18n', ['>= 0.5.0']
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "exvo_globalize"
|
2
|
+
require "rails"
|
3
|
+
require "i18n"
|
4
|
+
|
5
|
+
module ExvoGlobalize
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
initializer "exvo_globalize.configure_i18n" do |app|
|
8
|
+
# database backed store
|
9
|
+
I18n.backend = I18n::Backend::GlobalizeStore.new
|
10
|
+
|
11
|
+
# caching layer
|
12
|
+
I18n::Backend::GlobalizeStore.send(:include, I18n::Backend::Cache)
|
13
|
+
I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module I18n
|
2
|
+
module Backend
|
3
|
+
class GlobalizeStore
|
4
|
+
# based on https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record.rb
|
5
|
+
|
6
|
+
module Implementation
|
7
|
+
include Base, Flatten
|
8
|
+
|
9
|
+
def available_locales
|
10
|
+
GlobalizeTranslation.available_locales
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns a Hash with all translations (translation keys are dot separated strings, not hashes):
|
14
|
+
# {:en=>{"hello.world"=>"Hello world", "hello.earth"=>"Hello Earth"}, :pl=>{"hello.world"=>"Witaj świecie", "hello.earth"=>"Witaj ziemio"}}
|
15
|
+
def available_translations(locale = nil)
|
16
|
+
(locale.present? ? GlobalizeTranslation.locale(locale.to_s) : GlobalizeTranslation.all).
|
17
|
+
inject({}) do |result, element|
|
18
|
+
result[element.locale.to_sym] ||= {}
|
19
|
+
result[element.locale.to_sym][element.key] = element.value
|
20
|
+
result
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def store_translations(locale, data, options = {})
|
25
|
+
escape = options.fetch(:escape, true)
|
26
|
+
flatten_translations(locale, data, escape, false).each do |key, value|
|
27
|
+
GlobalizeTranslation.locale(locale).lookup(expand_keys(key)).delete_all
|
28
|
+
GlobalizeTranslation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def lookup(locale, key, scope = [], options = {})
|
35
|
+
key = normalize_flat_keys(locale, key, scope, options[:separator])
|
36
|
+
result = GlobalizeTranslation.locale(locale).lookup(key).all
|
37
|
+
|
38
|
+
if result.empty?
|
39
|
+
nil
|
40
|
+
elsif result.first.key == key
|
41
|
+
result.first.value
|
42
|
+
else
|
43
|
+
chop_range = (key.size + FLATTEN_SEPARATOR.size)..-1
|
44
|
+
result = result.inject({}) do |hash, r|
|
45
|
+
hash[r.key.slice(chop_range)] = r.value
|
46
|
+
hash
|
47
|
+
end
|
48
|
+
result.deep_symbolize_keys
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz']
|
53
|
+
def expand_keys(key)
|
54
|
+
key.to_s.split(FLATTEN_SEPARATOR).inject([]) do |keys, key|
|
55
|
+
keys << [keys.last, key].compact.join(FLATTEN_SEPARATOR)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
include Implementation
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exvo_globalize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Pawe\xC5\x82 Go\xC5\x9Bcicki"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-29 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: i18n
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 5
|
49
|
+
- 0
|
50
|
+
version: 0.5.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: It exposes `/globalize/translations.json` with JSON of all translations in the app
|
54
|
+
email:
|
55
|
+
- pawel.goscicki@gmail.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- MIT-LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- app/controllers/globalize_translations_controller.rb
|
69
|
+
- app/models/globalize_translation.rb
|
70
|
+
- config/routes.rb
|
71
|
+
- exvo_globalize.gemspec
|
72
|
+
- lib/exvo_globalize.rb
|
73
|
+
- lib/exvo_globalize/engine.rb
|
74
|
+
- lib/exvo_globalize/globalize_store.rb
|
75
|
+
- lib/exvo_globalize/version.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: https://github.com/Exvo/exvo_globalize
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.6.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Rails gem to translate your app into multiple languages using Globalize web app
|
110
|
+
test_files: []
|
111
|
+
|