weeler 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -7
- data/app/assets/javascripts/weeler/init.js +0 -2
- data/app/assets/stylesheets/weeler/style.css.scss +7 -1
- data/app/controllers/weeler/seo_items_controller.rb +3 -2
- data/app/controllers/weeler/settings_controller.rb +27 -9
- data/app/controllers/weeler/static_sections_controller.rb +2 -2
- data/app/controllers/weeler/translations_controller.rb +4 -18
- data/app/models/setting.rb +7 -0
- data/app/views/weeler/base/_footer.html.haml +1 -1
- data/app/views/weeler/settings/_form.html.haml +16 -0
- data/app/views/weeler/settings/index.html.haml +5 -8
- data/app/views/weeler/static_sections/show.html.haml +5 -1
- data/app/views/weeler/translations/_form.html.haml +5 -2
- data/app/views/weeler/translations/index.html.haml +0 -10
- data/lib/generators/weeler/templates/assets/javascripts/weeler/app/index.js +3 -1
- data/lib/generators/weeler/templates/assets/stylesheets/weeler/app/index.css +1 -1
- data/lib/i18n/backend/weeler/exporter.rb +32 -14
- data/lib/i18n/backend/weeler/importer.rb +57 -54
- data/lib/i18n/backend/weeler.rb +14 -25
- data/lib/weeler/action_dispatch/routing/mapper.rb +1 -2
- data/lib/weeler/action_view/helpers/translation_helper.rb +2 -2
- data/lib/weeler/version.rb +1 -1
- data/lib/weeler.rb +6 -1
- data/spec/.DS_Store +0 -0
- data/spec/controllers/translations_controller_spec.rb +1 -1
- data/spec/dummy/.ruby-version +1 -1
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/db/schema.rb +3 -3
- data/spec/fixtures/test_2020_format.xlsx +0 -0
- data/spec/weeler/i18n/backend/weeler/exporter_spec.rb +6 -0
- data/spec/weeler/i18n/backend/weeler/importer_spec.rb +17 -6
- data/spec/weeler/i18n/backend/weeler_spec.rb +51 -66
- data/weeler.gemspec +4 -5
- metadata +22 -37
- data/app/models/settings.rb +0 -2
- data/app/views/weeler/translations/usage_stats.html.haml +0 -34
- data/lib/generators/weeler/templates/migrations/create_weeler_translation_stats.rb +0 -11
- data/lib/i18n/backend/weeler/usage_logger.rb +0 -35
- data/spec/weeler/i18n/backend/weeler/usage_logger_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a5843d8169cc1f00da76876d33c136077878f6f02b516207402652068bfb54b
|
4
|
+
data.tar.gz: 2b1d3e9aa399794f81e91b096b76147cd7529bae9966e1798668551321890c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8a8056a9690d1dfab75ea1e570e1b332e0c22b245c48908ad46f4994e9dd8c3ae1557b7d089555143d6824a0a0af2756817bf623a62a23a50d1922f3ba56cd5
|
7
|
+
data.tar.gz: 02dc435b1cd9f7f358b2a36b2a2507389071ca0e0a65a8d43136dd442c0b748664d77d2d99f4f5d1473effff97cb0e335c8441993d960071b5ff01822bfd66ab
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/.travis.yml
CHANGED
@@ -8,7 +8,8 @@ before_script:
|
|
8
8
|
- psql -c 'create database travis_ci_test;' -U postgres
|
9
9
|
rvm:
|
10
10
|
- "2.6.0"
|
11
|
-
- "2.7.
|
11
|
+
- "2.7.2"
|
12
|
+
- "3.0.0"
|
12
13
|
# uncomment this line if your project needs to run something other than `rake`:
|
13
14
|
script:
|
14
15
|
- RAILS_ENV=test bundle exec rake db:migrate --trace
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -3,12 +3,5 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'globalize', github: 'globalize/globalize'
|
4
4
|
gem 'rails-controller-testing'
|
5
5
|
|
6
|
-
# platform :jruby do
|
7
|
-
# github 'jruby/activerecord-jdbc-adapter', branch: 'rails-5' do
|
8
|
-
# gem 'activerecord-jdbc-adapter'
|
9
|
-
# gem 'activerecord-jdbcpostgresql-adapter'
|
10
|
-
# end
|
11
|
-
# end
|
12
|
-
|
13
6
|
# Specify your gem's dependencies in weeler.gemspec
|
14
7
|
gemspec
|
@@ -17,8 +17,9 @@ module Weeler
|
|
17
17
|
translation.value = value
|
18
18
|
translation.save
|
19
19
|
end
|
20
|
-
|
20
|
+
Setting.i18n_updated_at = Time.now
|
21
|
+
|
21
22
|
redirect_to({action: :edit, id: params[:id]}, {flash: {success: "Section updated."}})
|
22
23
|
end
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
@@ -1,21 +1,39 @@
|
|
1
1
|
class Weeler::SettingsController < Weeler::ConfigurationController
|
2
|
+
HIDDEN_SETTINGS_KEYS = %w[i18n_updated_at].freeze
|
3
|
+
|
2
4
|
def index
|
3
|
-
|
4
|
-
|
5
|
+
@settings = Setting.all.order(:id).where.not(var: HIDDEN_SETTINGS_KEYS)
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@setting = Setting.new(create_setting_params)
|
10
|
+
|
11
|
+
if @setting.save
|
12
|
+
redirect_to weeler_settings_path, flash: { success: 'Setting created.' }
|
13
|
+
else
|
14
|
+
flash.now[:error] = 'Errors on creating.'
|
15
|
+
render :index
|
16
|
+
end
|
5
17
|
end
|
6
18
|
|
7
19
|
def update
|
8
|
-
@setting =
|
9
|
-
|
10
|
-
|
20
|
+
@setting = Setting.find(params[:id])
|
21
|
+
|
22
|
+
if @setting.update(update_setting_params)
|
23
|
+
redirect_to weeler_settings_path, flash: { success: 'Setting updated.' }
|
11
24
|
else
|
12
|
-
flash.now[:error] =
|
25
|
+
flash.now[:error] = 'Errors on updating.'
|
13
26
|
render :index
|
14
27
|
end
|
15
28
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def create_setting_params
|
33
|
+
params.require(:setting).permit(:var, :value)
|
19
34
|
end
|
20
35
|
|
36
|
+
def update_setting_params
|
37
|
+
params.require(:setting).permit(:value)
|
38
|
+
end
|
21
39
|
end
|
@@ -12,8 +12,8 @@ module Weeler
|
|
12
12
|
translation.value = value
|
13
13
|
translation.save
|
14
14
|
end
|
15
|
-
|
16
|
-
redirect_to({action: :show, id: params[:id]}, {flash: {success: "Section updated."}})
|
15
|
+
Setting.i18n_updated_at = Time.current
|
16
|
+
redirect_to({ action: :show, id: params[:id] }, { flash: { success: "Section updated." } })
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -19,7 +19,7 @@ module Weeler
|
|
19
19
|
@translation = I18n::Backend::Weeler::Translation.new(translation_params)
|
20
20
|
|
21
21
|
if @translation.save
|
22
|
-
|
22
|
+
Setting.i18n_updated_at = Time.now
|
23
23
|
redirect_to ({ action: :edit, id: @translation }), flash: { success: "Translation saved." }
|
24
24
|
else
|
25
25
|
flash.now[:error] = "Errors in saving."
|
@@ -31,7 +31,7 @@ module Weeler
|
|
31
31
|
@translation = I18n::Backend::Weeler::Translation.find(params[:id])
|
32
32
|
|
33
33
|
if @translation.update(translation_params)
|
34
|
-
|
34
|
+
Setting.i18n_updated_at = Time.now
|
35
35
|
|
36
36
|
redirect_to ({ action: :edit, id: @translation }), flash: { success: "Translation updated." }
|
37
37
|
else
|
@@ -44,24 +44,11 @@ module Weeler
|
|
44
44
|
@translation = I18n::Backend::Weeler::Translation.find(params[:id])
|
45
45
|
@translation.destroy
|
46
46
|
|
47
|
-
|
47
|
+
Setting.i18n_updated_at = Time.now
|
48
48
|
|
49
49
|
redirect_to ({ action: :index }), flash: {success: "Translation succesfully removed."}
|
50
50
|
end
|
51
51
|
|
52
|
-
def usage_stats
|
53
|
-
@used_keys = []
|
54
|
-
if Settings.log_key_usage == 'dump'
|
55
|
-
I18n::Backend::Weeler::TranslationStat.all.each do |translation_stat|
|
56
|
-
@used_keys << [translation_stat.key, translation_stat.usage_count]
|
57
|
-
end
|
58
|
-
else
|
59
|
-
Weeler.i18n_cache.instance_variable_get(:@data).keys.each do |key|
|
60
|
-
@used_keys << [key, Weeler.i18n_cache.read(key)] if key.start_with?('usage_stats')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
52
|
def export
|
66
53
|
respond_to do |format|
|
67
54
|
format.xlsx do
|
@@ -76,7 +63,7 @@ module Weeler
|
|
76
63
|
if params[:file].present?
|
77
64
|
I18n::Backend::Weeler::Translation.import params[:file]
|
78
65
|
|
79
|
-
|
66
|
+
Setting.i18n_updated_at = Time.now
|
80
67
|
|
81
68
|
redirect_to ({ action: :index }), flash: {success: "Translations succesfully imported."}
|
82
69
|
else
|
@@ -108,6 +95,5 @@ module Weeler
|
|
108
95
|
translations = translations.lookup(params[:group]) if params[:group].present?
|
109
96
|
translations
|
110
97
|
end
|
111
|
-
|
112
98
|
end
|
113
99
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
%footer
|
2
|
-
%p © Weby
|
2
|
+
%p © Weby 2021
|
@@ -0,0 +1,16 @@
|
|
1
|
+
= form_for [:weeler, item], html: {class: "form-vertical", role: "form"} do |f|
|
2
|
+
- if item.new_record?
|
3
|
+
= f.hidden_field :var
|
4
|
+
|
5
|
+
.form-group
|
6
|
+
%label.col-lg-4.col-md-4.control-label
|
7
|
+
= "#{item.var.humanize.capitalize}:"
|
8
|
+
.col-lg-6.col-md-6
|
9
|
+
- type = item.class.get_field(item.var)[:type]
|
10
|
+
- if type == :boolean
|
11
|
+
= f.check_box :value, class: "form-check-input"
|
12
|
+
- else
|
13
|
+
= f.text_field :value, class: "form-control"
|
14
|
+
|
15
|
+
.col-lg-2.col-md-2
|
16
|
+
= f.submit "Save", class: "btn btn-primary"
|
@@ -9,11 +9,8 @@
|
|
9
9
|
%div{class: "col-lg-8 col-md-8"}
|
10
10
|
- @settings.each do |item|
|
11
11
|
%div{style: "min-height: 50px;"}
|
12
|
-
=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
= f.text_field :value, value: item.value, class: "form-control"
|
18
|
-
.col-lg-2.col-md-2
|
19
|
-
= f.submit "Save", class: "btn btn-primary"
|
12
|
+
= render 'form', item: item
|
13
|
+
- Setting.keys.each do |key|
|
14
|
+
- if !Setting.all.map(&:var).include?(key)
|
15
|
+
%div{style: "min-height: 50px;"}
|
16
|
+
= render 'form', item: Setting.new(var: key)
|
@@ -17,8 +17,12 @@
|
|
17
17
|
.form-group
|
18
18
|
= label_tag key, key.to_s.split('.').last.humanize, class: "col-lg-2 col-md-2 control-label"
|
19
19
|
%div{class: "col-lg-10 col-md-10"}
|
20
|
+
|
20
21
|
- if translation.html?
|
21
|
-
|
22
|
+
- if ::Weeler.use_rails_rich_text_editor
|
23
|
+
= rich_text_area_tag "translations[#{translation.id}]", translation.value
|
24
|
+
- else
|
25
|
+
= text_area_tag "translations[#{translation.id}]", translation.value, class: 'form-control html'
|
22
26
|
- else
|
23
27
|
= text_area_tag "translations[#{translation.id}]", translation.value, class: 'form-control'
|
24
28
|
|
@@ -10,8 +10,11 @@
|
|
10
10
|
.form-group
|
11
11
|
%label.col-lg-2.col-md-2.control-label Value
|
12
12
|
.col-lg-10.col-md-10
|
13
|
-
|
14
|
-
= translation.value
|
13
|
+
- if ::Weeler.use_rails_rich_text_editor && translation.html?
|
14
|
+
= rich_text_area_tag 'i18n_backend_weeler_translation[value]', translation.value
|
15
|
+
- else
|
16
|
+
%textarea.form-control{class: "#{'html' if translation.html?}", name: 'i18n_backend_weeler_translation[value]', id: 'i18n_backend_weeler_translation_value'}
|
17
|
+
= translation.value
|
15
18
|
%h4 Info
|
16
19
|
.form-group
|
17
20
|
%label.col-lg-2.col-md-2.control-label Variables
|
@@ -10,15 +10,6 @@
|
|
10
10
|
= link_to 'Show translations', weeler_translations_path(show_translation_keys: false)
|
11
11
|
- else
|
12
12
|
= link_to 'Show translation keys', weeler_translations_path(show_translation_keys: true)
|
13
|
-
%h1 Stats
|
14
|
-
%p.lead.text-muted
|
15
|
-
- if Settings.log_key_usage == 'true'
|
16
|
-
= 'Translation usage stat gathering is ON'
|
17
|
-
- else
|
18
|
-
= 'Translation usage stat gathering is OFF'
|
19
|
-
%p.lead.text-muted
|
20
|
-
= link_to 'Go to Stats', {action: :usage_stats}
|
21
|
-
|
22
13
|
.row
|
23
14
|
.col-xs-12
|
24
15
|
%nav.navbar.navbar-default{ role: "navigation" }
|
@@ -39,7 +30,6 @@
|
|
39
30
|
%li
|
40
31
|
%a{href: weeler_translations_path(group: params[:group], filtered_locale: locale)}= locale.capitalize
|
41
32
|
|
42
|
-
|
43
33
|
/ key group lookup
|
44
34
|
%ul.nav.navbar-nav.navbar-left
|
45
35
|
%li.dropdown
|
@@ -25,7 +25,6 @@ module I18n
|
|
25
25
|
extend ActiveSupport::Concern
|
26
26
|
|
27
27
|
module ClassMethods
|
28
|
-
|
29
28
|
# Prepare xlsx package from current scope
|
30
29
|
# Stores all translations in translations worksheet.
|
31
30
|
def as_xlsx_package
|
@@ -42,33 +41,52 @@ module I18n
|
|
42
41
|
|
43
42
|
included_keys = []
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
tranlsations_by_locales = Translation.where(locale: locales).group_by(&:locale)
|
45
|
+
|
46
|
+
current_scope.each do |translation|
|
47
|
+
next if included_keys.include?(translation.key)
|
48
|
+
|
49
|
+
row = Translation.translation_row_by_key_and_locales(tranlsations_by_locales, translation.key, locales)
|
50
|
+
sheet.add_row(row, types: types)
|
51
|
+
included_keys << translation.key
|
50
52
|
end
|
51
|
-
|
53
|
+
|
54
|
+
package
|
52
55
|
end
|
53
56
|
|
54
|
-
def title_row
|
57
|
+
def title_row(locales)
|
55
58
|
row = [ 'Key' ]
|
56
59
|
locales.each do |locale|
|
57
60
|
row.push(locale.capitalize)
|
58
61
|
end
|
62
|
+
|
63
|
+
row.push('Created at')
|
64
|
+
row.push('Updated at')
|
65
|
+
|
59
66
|
row
|
60
67
|
end
|
61
68
|
|
62
|
-
def translation_row_by_key_and_locales key, locales
|
63
|
-
row = [
|
69
|
+
def translation_row_by_key_and_locales(tranlsations_by_locales, key, locales)
|
70
|
+
row = [key]
|
71
|
+
created_ats = []
|
72
|
+
updated_ats = []
|
73
|
+
|
64
74
|
locales.each do |locale|
|
65
|
-
|
66
|
-
|
67
|
-
|
75
|
+
translation = tranlsations_by_locales[locale.to_s]&.find { |t| t.key == key }
|
76
|
+
|
77
|
+
if translation.present?
|
78
|
+
created_ats.push(translation.created_at)
|
79
|
+
updated_ats.push(translation.updated_at)
|
80
|
+
|
81
|
+
row.push(translation.value)
|
68
82
|
else
|
69
|
-
row.push(
|
83
|
+
row.push('')
|
70
84
|
end
|
71
85
|
end
|
86
|
+
|
87
|
+
row.push(created_ats.min)
|
88
|
+
row.push(updated_ats.max)
|
89
|
+
|
72
90
|
row
|
73
91
|
end
|
74
92
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# if params[:file].present?
|
7
7
|
# I18n::Backend::Weeler::Translation.import params[:file]
|
8
|
-
#
|
8
|
+
# Setting.i18n_updated_at = Time.now
|
9
9
|
# end
|
10
10
|
|
11
11
|
begin
|
@@ -17,82 +17,85 @@ end
|
|
17
17
|
module I18n
|
18
18
|
module Backend
|
19
19
|
class Weeler
|
20
|
-
|
21
20
|
module Importer
|
22
21
|
extend ActiveSupport::Concern
|
23
22
|
|
24
23
|
module ClassMethods
|
25
|
-
|
26
24
|
# Loads file and iterates each sheet and row.
|
27
|
-
def import
|
28
|
-
xls = open_spreadsheet
|
29
|
-
xls.each_with_pagename do |name, sheet|
|
25
|
+
def import(file)
|
26
|
+
xls = open_spreadsheet(file)
|
30
27
|
|
28
|
+
xls.each_with_pagename do |_, sheet|
|
31
29
|
# Lookup locales
|
32
30
|
locales = locales_from_xlsx_sheet_row(sheet.row(1))
|
31
|
+
tranlsations_by_locales = Translation.where(locale: locales).group_by(&:locale)
|
33
32
|
|
34
33
|
# Lookup values
|
35
34
|
(2..sheet.last_row).each do |row_no|
|
36
|
-
store_translations_from_xlsx_row(sheet.row(row_no), locales)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end # import
|
35
|
+
store_translations_from_xlsx_row(tranlsations_by_locales, sheet.row(row_no), locales)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
42
39
|
|
43
40
|
private
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
42
|
+
# Open csv, xls, xlsx or ods file and read content
|
43
|
+
def open_spreadsheet(file)
|
44
|
+
case File.extname(file.original_filename)
|
45
|
+
when ".csv" then Roo::Csv.new(file.path, file_warning: :ignore)
|
46
|
+
when ".xls" then Roo::Excel.new(file.path, file_warning: :ignore)
|
47
|
+
when ".xlsx" then Roo::Excelx.new(file.path, file_warning: :ignore)
|
48
|
+
when ".ods" then Roo::OpenOffice.new(file.path, file_warning: :ignore)
|
49
|
+
else raise "Unknown file type: #{file.original_filename}"
|
54
50
|
end
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
locales.push(cell.downcase)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
locales
|
65
|
-
end
|
53
|
+
# Lookup locales and sequence for loading
|
54
|
+
def locales_from_xlsx_sheet_row(row)
|
55
|
+
locales = []
|
56
|
+
row.each_with_index do |cell, i|
|
57
|
+
next unless i.positive?
|
66
58
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
row.each_with_index do |cell, i|
|
74
|
-
if i == 0
|
75
|
-
key = cell
|
76
|
-
else
|
77
|
-
locale = locales[ i - 1 ]
|
78
|
-
store_translation_from_xlsx_cell locale, key, cell
|
79
|
-
end
|
80
|
-
end
|
59
|
+
locale = cell.downcase
|
60
|
+
|
61
|
+
# check if legal local
|
62
|
+
next if locale.size != 2
|
63
|
+
|
64
|
+
locales.push(cell.downcase)
|
81
65
|
end
|
66
|
+
locales
|
67
|
+
end
|
68
|
+
|
69
|
+
# Iterate each cell in row and store translation by locale
|
70
|
+
def store_translations_from_xlsx_row(tranlsations_by_locales, row, locales)
|
71
|
+
locale = nil
|
72
|
+
key = nil
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
74
|
+
row.each_with_index do |cell, i|
|
75
|
+
if i.zero?
|
76
|
+
key = cell
|
77
|
+
else
|
78
|
+
locale = locales[i - 1]
|
86
79
|
|
87
|
-
|
88
|
-
translation = Translation.find_or_initialize_by locale: locale, key: key
|
89
|
-
if translation.value != value
|
90
|
-
translation.value = value
|
91
|
-
translation.save
|
92
|
-
end
|
80
|
+
store_translation_from_xlsx_cell(tranlsations_by_locales[locale.to_s], locale, key, cell) if locale.present?
|
93
81
|
end
|
94
82
|
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Store locale if locale and key present
|
86
|
+
def store_translation_from_xlsx_cell(locale_translations, locale, key, cell)
|
87
|
+
value = cell.nil? ? '' : cell
|
88
|
+
|
89
|
+
return if locale.blank? || key.blank?
|
90
|
+
|
91
|
+
translation = locale_translations&.find { |t| t.key == key }
|
92
|
+
|
93
|
+
return if translation.present? && translation.value == value
|
95
94
|
|
95
|
+
translation ||= Translation.new(locale: locale, key: key)
|
96
|
+
translation.value = value
|
97
|
+
translation.save
|
98
|
+
end
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
data/lib/i18n/backend/weeler.rb
CHANGED
@@ -4,8 +4,6 @@ require 'i18n/backend/weeler/dedupe'
|
|
4
4
|
require 'i18n/backend/weeler/html_checker'
|
5
5
|
require 'i18n/backend/weeler/exporter'
|
6
6
|
require 'i18n/backend/weeler/importer'
|
7
|
-
require 'i18n/backend/weeler/usage_logger'
|
8
|
-
require 'i18n/backend/weeler/translation_stat'
|
9
7
|
require 'i18n/backend/weeler/lock'
|
10
8
|
|
11
9
|
module I18n
|
@@ -31,8 +29,6 @@ module I18n
|
|
31
29
|
autoload :Translation, 'i18n/backend/weeler/translation'
|
32
30
|
autoload :Exporter, 'i18n/backend/weeler/exporter'
|
33
31
|
autoload :Importer, 'i18n/backend/weeler/importer'
|
34
|
-
autoload :UsageLogger, 'i18n/backend/weeler/usage_logger'
|
35
|
-
autoload :TranslationStat, 'i18n/backend/weeler/translation_stat'
|
36
32
|
autoload :Lock, 'i18n/backend/weeler/lock'
|
37
33
|
|
38
34
|
module Implementation
|
@@ -52,12 +48,16 @@ module I18n
|
|
52
48
|
Translation.all.each do |translation|
|
53
49
|
# Load in cache unless value is nil or it is blank and empty
|
54
50
|
# translation acts like missing
|
55
|
-
if
|
56
|
-
|
57
|
-
|
51
|
+
next if translation.value.nil? || (::Weeler.empty_translation_acts_like_missing && translation.value.blank?)
|
52
|
+
|
53
|
+
i18n_cache.write [translation.locale, translation.key], translation
|
58
54
|
end
|
59
55
|
|
60
|
-
i18n_cache.write('UPDATED_AT',
|
56
|
+
i18n_cache.write('UPDATED_AT', Setting.i18n_updated_at) if ActiveRecord::Base.connection.data_source_exists?('settings')
|
57
|
+
end
|
58
|
+
|
59
|
+
def available_locales
|
60
|
+
I18n::Backend::Weeler::Translation.distinct.pluck(:locale).compact.map(&:to_sym)
|
61
61
|
end
|
62
62
|
|
63
63
|
protected
|
@@ -70,26 +70,15 @@ module I18n
|
|
70
70
|
|
71
71
|
private
|
72
72
|
|
73
|
-
def lookup_in_cache
|
73
|
+
def lookup_in_cache(locale, key, scope = [], options = {})
|
74
74
|
# reload cache if cache timestamp differs from last translations update
|
75
|
-
reload_cache if ((!ActiveRecord::Base.connection.data_source_exists?('settings')) || i18n_cache.read('UPDATED_AT') !=
|
76
|
-
|
77
|
-
# log locale/key usage for statistics
|
78
|
-
if Settings.log_key_usage == 'true'
|
79
|
-
i18n_cache.delete([:dump_usage_stats, Process.pid])
|
80
|
-
log_key_usage(locale, key)
|
81
|
-
end
|
82
|
-
|
83
|
-
if Settings.log_key_usage == 'dump'
|
84
|
-
dump_key_usage
|
85
|
-
end
|
75
|
+
reload_cache if ((!ActiveRecord::Base.connection.data_source_exists?('settings')) || i18n_cache.read('UPDATED_AT') != Setting.i18n_updated_at)
|
86
76
|
|
87
77
|
return nil if i18n_cache.read([:missing, [locale, key]])
|
88
78
|
|
89
79
|
keys = expand_keys key
|
90
80
|
|
91
81
|
keys.reverse.each do |check_key|
|
92
|
-
|
93
82
|
result = i18n_cache.read([locale, check_key])
|
94
83
|
|
95
84
|
return result.value unless result.blank?
|
@@ -145,10 +134,12 @@ module I18n
|
|
145
134
|
|
146
135
|
keys = options[:count] ? PLURAL_KEYS.map { |k| [singular_key, k].join(FLATTEN_SEPARATOR) } : [singular_key]
|
147
136
|
|
148
|
-
|
149
137
|
keys.each do |key|
|
150
|
-
translation = Weeler::Translation.find_or_initialize_by
|
138
|
+
translation = Weeler::Translation.find_or_initialize_by(locale: locale.to_s, key: key)
|
151
139
|
translation.interpolations = interpolations
|
140
|
+
|
141
|
+
|
142
|
+
|
152
143
|
fallback_value = fallback_backend_translation locale, key
|
153
144
|
if fallback_value.present?
|
154
145
|
translation.value = fallback_value
|
@@ -162,7 +153,6 @@ module I18n
|
|
162
153
|
return_value
|
163
154
|
end
|
164
155
|
|
165
|
-
|
166
156
|
def fallback_backend_translation locale, key
|
167
157
|
if I18n.backend.backends.size > 1
|
168
158
|
alternative_backend = I18n.backend.backends[1]
|
@@ -171,7 +161,6 @@ module I18n
|
|
171
161
|
nil
|
172
162
|
end
|
173
163
|
end
|
174
|
-
|
175
164
|
end
|
176
165
|
|
177
166
|
include Implementation
|
@@ -54,11 +54,10 @@ module Weeler
|
|
54
54
|
collection do
|
55
55
|
get :export
|
56
56
|
post :import
|
57
|
-
get :usage_stats
|
58
57
|
end
|
59
58
|
end
|
60
59
|
resources :seo_items
|
61
|
-
resources :settings, :only => [:index, :
|
60
|
+
resources :settings, :only => [:index, :update, :create]
|
62
61
|
end
|
63
62
|
|
64
63
|
# Ordable route concern for dynamic sorting and removing image
|