lit 0.4.0.pre.alpha.3 → 0.4.0.pre.alpha.4
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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/lit/export.rb +7 -3
- data/lib/lit/version.rb +1 -1
- data/lib/tasks/lit_tasks.rake +3 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8731e7911097d0e6c8b3cdbf164d5a4dfb7d9c45
|
4
|
+
data.tar.gz: c478524af6694e7cf55272ae7d2f83381d05b161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b096959dfb69f64ff171173026d4c582042e8409593cfc76e522aee75ecf016ecfb13ca794e5d93588594a4428b50d30f55fd0dcd7b0b378c609efc25c4ce244
|
7
|
+
data.tar.gz: 7171984114ea8cc6d546e5e1530cf89f6d5acb46e7b9a1fc8f38256dc4a74886ccbded8aaeb7a8729afd90dbf34e6a93e8fdd47b4747f81b02d083633abc66f0
|
data/README.md
CHANGED
@@ -79,6 +79,8 @@ $ rake lit:export FORMAT=csv LOCALES=en,pl OUTPUT=export.csv
|
|
79
79
|
|
80
80
|
Using the task `lit:export_splitted` does the same as `lit:export` but splits the locales by their name (`config/locales/en.yml`, etc).
|
81
81
|
|
82
|
+
Optionally, the `INCLUDE_HITS_COUNT` option (only applicable for CSV export) can be used to include current hits count for each localization key. Note that it only makes sense to use this option when Redis is Lit's key-value engine because these counters are stored in cache and not in the database.
|
83
|
+
|
82
84
|
#### Import
|
83
85
|
|
84
86
|
Translation import is handled using the `lit:import` task, where imported file name should be specified in the `FILE` envionment variable:
|
data/lib/lit/export.rb
CHANGED
@@ -2,7 +2,7 @@ require 'csv'
|
|
2
2
|
|
3
3
|
module Lit
|
4
4
|
class Export
|
5
|
-
def self.call(locale_keys:, format:)
|
5
|
+
def self.call(locale_keys:, format:, include_hits_count: false)
|
6
6
|
raise ArgumentError, "format must be yaml or csv" if %i[yaml csv].exclude?(format)
|
7
7
|
Lit.loader.cache.load_all_translations
|
8
8
|
localizations_scope = Lit::Localization.active
|
@@ -22,7 +22,7 @@ module Lit
|
|
22
22
|
when :csv
|
23
23
|
relevant_locales = locale_keys.presence || I18n.available_locales.map(&:to_s)
|
24
24
|
CSV.generate do |csv|
|
25
|
-
csv << ['key', *relevant_locales]
|
25
|
+
csv << ['key', *relevant_locales, ('hits' if include_hits_count)].compact
|
26
26
|
keys_without_locales = db_localizations.keys.map { |k| k.gsub(/(#{relevant_locales.join('|')})\./, '') }.uniq
|
27
27
|
keys_without_locales.each do |key_without_locale|
|
28
28
|
# Here, we need to determine if we're dealing with an array or a scalar.
|
@@ -44,7 +44,11 @@ module Lit
|
|
44
44
|
key_localizations_per_locale =
|
45
45
|
relevant_locales.map { |l| Array.wrap(db_localizations["#{l}.#{key_without_locale}"]) }
|
46
46
|
transpose(key_localizations_per_locale).each do |translation_series|
|
47
|
-
|
47
|
+
csv_row = [key_without_locale, *translation_series]
|
48
|
+
if include_hits_count
|
49
|
+
csv_row << (Lit.init.cache.get_global_hits_counter(key_without_locale) || 0)
|
50
|
+
end
|
51
|
+
csv << csv_row
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
data/lib/lit/version.rb
CHANGED
data/lib/tasks/lit_tasks.rake
CHANGED
@@ -3,9 +3,10 @@ namespace :lit do
|
|
3
3
|
task export: :environment do
|
4
4
|
locale_keys = ENV['LOCALES'].to_s.split(',') || []
|
5
5
|
export_format = ENV['FORMAT'].presence&.downcase&.to_sym || :yaml
|
6
|
+
include_hits_count = ENV['INCLUDE_HITS_COUNT'].present?
|
6
7
|
path = ENV['OUTPUT'].presence || Rails.root.join('config', 'locales', "lit.#{file_extension(export_format)}")
|
7
|
-
|
8
|
-
|
8
|
+
if exported = Lit::Export.call(locale_keys: locale_keys, format: export_format,
|
9
|
+
include_hits_count: include_hits_count)
|
9
10
|
File.new(path, 'w').write(exported)
|
10
11
|
puts "Successfully exported #{path}."
|
11
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.pre.alpha.
|
4
|
+
version: 0.4.0.pre.alpha.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Litwiniuk
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-11-
|
13
|
+
date: 2018-11-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: rails
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 4.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 4.2.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: jquery-rails
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,19 +41,19 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
|
-
name: rails
|
44
|
+
name: coffee-rails
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: '0'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: appraisal
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|