lolita-i18n 0.5.3 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +4 -0
- data/app/assets/images/lolita/i18n/export.png +0 -0
- data/app/assets/stylesheets/lolita/i18n/application.scss +4 -1
- data/app/controllers/lolita/i18n_controller.rb +29 -6
- data/app/views/lolita/i18n/index.html.haml +2 -0
- data/lib/lolita-i18n/request.rb +30 -1
- data/lib/lolita-i18n/version.rb +1 -1
- data/lib/lolita-i18n.rb +4 -0
- data/lib/tasks/lolita_i18n.rake +91 -0
- data/lolita-i18n.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657f3df6b02bb91e6595e00c65609cbc4186caf3
|
4
|
+
data.tar.gz: 0290ac77ca9461ef376f533de1164754c46410ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbeedbeb867ae824036c9e8d764356ae90ff0f5aca0f67755689884a9499a0d9548c500042db315241400347d4d4f2d93e43ea9a4b8dbc41ff56840b42127cc9
|
7
|
+
data.tar.gz: dadd41f9e3ea90763b4c7dc8add194302a267c068ba861e59266e7dc24caf3fdae16be1cc7336a2982f42a6f6ef6fbfba60a2e3860f1bddb06778d5b6050e949
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -48,6 +48,10 @@ end
|
|
48
48
|
|
49
49
|
After adding go manualy trough the whole site /urls. All translations will be registerd with linked url.
|
50
50
|
|
51
|
+
## Export Redis DB to YAML file
|
52
|
+
|
53
|
+
rake lolita_i18n:export_redis -- --redisdb=1 --locale=lv --outfile=../lv.yml
|
54
|
+
|
51
55
|
---
|
52
56
|
|
53
57
|
Copyright (c) 2014 ITHouse (Latvia). See LICENSE.txt for further details.
|
Binary file
|
@@ -6,10 +6,18 @@ class Lolita::I18nController < ApplicationController
|
|
6
6
|
|
7
7
|
def index
|
8
8
|
authorization_proxy.authorize!(:read, self.resource_class)
|
9
|
-
|
9
|
+
respond_to do |format|
|
10
|
+
format.html do
|
11
|
+
@translations = i18n_request.translations(@active_locale)
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
if params[:sort] && params[:sort].to_s == "1"
|
14
|
+
@translations = i18n_request.sort_translations(@translations)
|
15
|
+
end
|
16
|
+
render
|
17
|
+
end
|
18
|
+
format.xlsx do
|
19
|
+
send_xls_file(i18n_request.xls(@active_locale), @active_locale)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
@@ -18,7 +26,7 @@ class Lolita::I18nController < ApplicationController
|
|
18
26
|
respond_to do |format|
|
19
27
|
format.json do
|
20
28
|
begin
|
21
|
-
if saved = i18n_request.update_key
|
29
|
+
if saved = i18n_request.update_key
|
22
30
|
notice(::I18n.t("lolita-i18n.Successful update"))
|
23
31
|
else
|
24
32
|
error(::I18n.t("lolita-i18n.Error"))
|
@@ -34,7 +42,7 @@ class Lolita::I18nController < ApplicationController
|
|
34
42
|
end
|
35
43
|
|
36
44
|
private
|
37
|
-
|
45
|
+
|
38
46
|
def lolita_mapping
|
39
47
|
Lolita.mappings[:i18n]
|
40
48
|
end
|
@@ -54,4 +62,19 @@ class Lolita::I18nController < ApplicationController
|
|
54
62
|
@i18n_request ||= Lolita::I18n::Request.new(params)
|
55
63
|
end
|
56
64
|
|
57
|
-
|
65
|
+
def send_xls_file(translations, active_locale)
|
66
|
+
path = '/tmp'
|
67
|
+
xlsx_package = Axlsx::Package.new
|
68
|
+
wb = xlsx_package.workbook
|
69
|
+
wb.add_worksheet(name: "Translations") do |sheet|
|
70
|
+
sheet.add_row ['Key', 'Url', 'Original', 'Translation']
|
71
|
+
translations.each do |item|
|
72
|
+
sheet.add_row [item[:key], item[:url], item[:original_translation], item[:translation]]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
file_name = "translations-export-#{active_locale}.xlsx"
|
76
|
+
file_path = File.join(path, file_name)
|
77
|
+
xlsx_package.serialize(file_path)
|
78
|
+
send_file file_path
|
79
|
+
end
|
80
|
+
end
|
@@ -13,6 +13,8 @@
|
|
13
13
|
= label_tag "show_untranslated", ::I18n.t('lolita-i18n.show-untranslated', :default => ::I18n.t('lolita-i18n.show-untranslated'))
|
14
14
|
= check_box_tag "show_with_url", nil, params[:show_with_url]
|
15
15
|
= label_tag "show_with_url", ::I18n.t('lolita-i18n.show-with-url', :default => ::I18n.t('lolita-i18n.show-with-url'))
|
16
|
+
= link_to lolita_i18n_index_path(:format => 'xlsx', :active_locale => @active_locale) do
|
17
|
+
= image_tag 'lolita/i18n/export.png', class: 'export'
|
16
18
|
%table
|
17
19
|
%thead
|
18
20
|
%tr
|
data/lib/lolita-i18n/request.rb
CHANGED
@@ -163,6 +163,29 @@ module Lolita
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
class ExportXls
|
167
|
+
private
|
168
|
+
attr_reader :translations
|
169
|
+
public
|
170
|
+
|
171
|
+
def initialize(translations)
|
172
|
+
@translations = translations
|
173
|
+
end
|
174
|
+
|
175
|
+
def to_a
|
176
|
+
result = []
|
177
|
+
translations.each do |key, value|
|
178
|
+
result << {
|
179
|
+
:key => key,
|
180
|
+
:url => value[:url],
|
181
|
+
:original_translation => value[:original_translation].to_s,
|
182
|
+
:translation => value[:translation].to_s
|
183
|
+
}
|
184
|
+
end
|
185
|
+
result
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
166
189
|
attr_accessor :params
|
167
190
|
|
168
191
|
def initialize(params)
|
@@ -170,9 +193,10 @@ module Lolita
|
|
170
193
|
end
|
171
194
|
|
172
195
|
def translations locale
|
196
|
+
return @translations if defined?(@translations)
|
173
197
|
Lolita.i18n.load_translations
|
174
198
|
translations = Translations.new(Lolita.i18n.yaml_backend.send(:translations)[::I18n.default_locale])
|
175
|
-
translations.normalized(locale)
|
199
|
+
@translations = translations.normalized(locale)
|
176
200
|
end
|
177
201
|
|
178
202
|
def sort_translations(unsorted_translations)
|
@@ -199,6 +223,11 @@ module Lolita
|
|
199
223
|
@validator ||= Validator.new()
|
200
224
|
end
|
201
225
|
|
226
|
+
def xls(locale)
|
227
|
+
return @xls if defined?(@xls)
|
228
|
+
@xls = ExportXls.new(translations(locale)).to_a
|
229
|
+
end
|
230
|
+
|
202
231
|
private
|
203
232
|
|
204
233
|
def both_values_complex?(value_a, value_b)
|
data/lib/lolita-i18n/version.rb
CHANGED
data/lib/lolita-i18n.rb
CHANGED
@@ -2,7 +2,11 @@ $:<<File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
|
|
2
2
|
require 'redis'
|
3
3
|
require 'yajl'
|
4
4
|
require 'lolita'
|
5
|
+
require 'axlsx'
|
5
6
|
|
7
|
+
unless defined? Mime::XLSX
|
8
|
+
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
|
9
|
+
end
|
6
10
|
|
7
11
|
module Lolita
|
8
12
|
# === Uses Redis DB as backend
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Lolita
|
4
|
+
module I18n
|
5
|
+
module Remake
|
6
|
+
class << self
|
7
|
+
def store_hash(subkeys, value)
|
8
|
+
hsh = {}
|
9
|
+
store_key_value(hsh, subkeys, value)
|
10
|
+
hsh
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_yaml_directory(locales_root_path, locale)
|
14
|
+
hsh = {}
|
15
|
+
file_paths = Dir["#{locales_root_path}/**/#{locale}.yml"]
|
16
|
+
file_paths.each do |file_path|
|
17
|
+
single_file_hsh = YAML.load(File.read(file_path))
|
18
|
+
hsh.deep_merge!(single_file_hsh)
|
19
|
+
end
|
20
|
+
hsh
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_yaml(hsh, file_path)
|
24
|
+
File.open(file_path, 'w') do |file|
|
25
|
+
file.write(hsh.to_yaml)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def deeply_sort_hash(object)
|
30
|
+
return object unless object.is_a?(Hash)
|
31
|
+
hash = RUBY_VERSION >= '1.9' ? Hash.new : ActiveSupport::OrderedHash.new
|
32
|
+
object.each { |k, v| hash[k] = deeply_sort_hash(v) }
|
33
|
+
sorted = hash.sort { |a, b| a[0].to_s <=> b[0].to_s }
|
34
|
+
hash.class[sorted]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def store_key_value(hsh, subkeys, value)
|
40
|
+
key = subkeys.slice!(0..0)[0]
|
41
|
+
if subkeys.empty?
|
42
|
+
hsh[key] = value
|
43
|
+
else
|
44
|
+
hsh[key] = {}
|
45
|
+
store_key_value(hsh[key], subkeys, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :lolita_i18n do |args|
|
54
|
+
desc "Export redis DB and merge with yml. args: -- --redisdb=1 --locale=lv --outfile=../lv.yml"
|
55
|
+
task :export_redis => :environment do
|
56
|
+
locales_root = File.join(Rails.root, 'config', 'locales')
|
57
|
+
options = {}
|
58
|
+
OptionParser.new(args) do |opts|
|
59
|
+
opts.banner = "Usage: rake i18n:export_redis [options]"
|
60
|
+
opts.on("-r", "--redisdb {number}","Redis database number", String) do |number|
|
61
|
+
options[:redis_rb] = number
|
62
|
+
end
|
63
|
+
opts.on("-l", "--locale {locale}","Locale to export", String) do |lang|
|
64
|
+
options[:locale] = lang
|
65
|
+
end
|
66
|
+
opts.on("-f", "--outfile {filename}","Output filename", String) do |filename|
|
67
|
+
options[:filename] = filename
|
68
|
+
end
|
69
|
+
end.parse!
|
70
|
+
store = Redis.new(:db => options[:redis_rb])
|
71
|
+
keys = store.keys("#{options[:locale]}.*").sort
|
72
|
+
new_i18n = {}
|
73
|
+
keys.each do |key|
|
74
|
+
subkeys = key.split('.')
|
75
|
+
value = store.get(key)
|
76
|
+
if value.match(/^{/) || value.match(/^\[/)
|
77
|
+
value = JSON.parse(value)
|
78
|
+
else
|
79
|
+
value.gsub!(/\bnull\b/, 'nil')
|
80
|
+
value = eval(value)
|
81
|
+
end
|
82
|
+
new_i18n.deep_merge!(Lolita::I18n::Remake.store_hash(subkeys, value))
|
83
|
+
end
|
84
|
+
file_i18n_path = File.join(locales_root, "#{options[:locale]}.yml")
|
85
|
+
file_i18n = YAML.load(File.read(file_i18n_path))
|
86
|
+
file_i18n.deep_merge!(new_i18n)
|
87
|
+
Lolita::I18n::Remake.deeply_sort_hash(file_i18n)
|
88
|
+
Lolita::I18n::Remake.write_yaml(file_i18n, options[:filename])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/lolita-i18n.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_runtime_dependency(%q<redis>, ["~> 3.0.3"])
|
25
25
|
s.add_runtime_dependency(%q<yajl-ruby>,["~> 1.1.0"])
|
26
26
|
s.add_runtime_dependency(%q<unicode_utils>,["~> 1.4.0"])
|
27
|
+
s.add_runtime_dependency(%q<axlsx>,["~> 2.0.1"])
|
27
28
|
s.files = `git ls-files`.split("\n")
|
28
29
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
30
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolita-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITHouse (Latvia)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-06-
|
13
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: lolita
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: 1.4.0
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: axlsx
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.0.1
|
106
|
+
type: :runtime
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 2.0.1
|
99
113
|
description: Lolita plugin, that enables .yml files management from administrative
|
100
114
|
interface. Also faster access to translations, that DB store
|
101
115
|
email: support@ithouse.lv
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- LICENSE.txt
|
114
128
|
- README.md
|
115
129
|
- Rakefile
|
130
|
+
- app/assets/images/lolita/i18n/export.png
|
116
131
|
- app/assets/images/lolita/i18n/google_translate_icon.png
|
117
132
|
- app/assets/javascripts/lolita/i18n/application.js
|
118
133
|
- app/assets/javascripts/lolita/i18n/i18n.js
|
@@ -133,6 +148,7 @@ files:
|
|
133
148
|
- lib/lolita-i18n/rails.rb
|
134
149
|
- lib/lolita-i18n/request.rb
|
135
150
|
- lib/lolita-i18n/version.rb
|
151
|
+
- lib/tasks/lolita_i18n.rake
|
136
152
|
- lolita-i18n.gemspec
|
137
153
|
- spec/controllers/lolita/i18n_controller_spec.rb
|
138
154
|
- spec/features/translating_spec.rb
|