translation 1.0.1 → 1.1.0
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/lib/translation_io/client/base_operation/save_special_yaml_files_step.rb +2 -2
- data/lib/translation_io/client/init_operation.rb +3 -4
- data/lib/translation_io/client/init_operation/cleanup_yaml_files_step.rb +1 -1
- data/lib/translation_io/client/init_operation/create_yaml_po_files_step.rb +2 -2
- data/lib/translation_io/client/sync_operation.rb +6 -4
- data/lib/translation_io/client/sync_operation/apply_yaml_source_edits_step.rb +96 -0
- data/lib/translation_io/client/sync_operation/create_yaml_pot_file_step.rb +1 -1
- data/lib/translation_io/config.rb +4 -5
- data/lib/translation_io/yaml_entry.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6055d7b901a7e9feef192da60bb4313b73fcff3
|
4
|
+
data.tar.gz: 75fc068a3a457b753c0712dd062cb4930533a93d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8e4d890eadb175c48ae56065fa2546bb2bd3d0a089a5d50ffba13091d7745cb3bdbe83295e6abe0f715764e6e462be48ee4b14f4827bf02e3daa705d1f55ce
|
7
|
+
data.tar.gz: 6ed57c9f6a19e138aaba17ba9c117b1ebd2ea370dfb5d5e3c87efe5b563d7333882f800889d1a2c1c64829486b3ee3a8838f987b2b18cb9052ed7bd7a868d555
|
@@ -21,7 +21,7 @@ module TranslationIO
|
|
21
21
|
end
|
22
22
|
|
23
23
|
all_flat_special_translations = all_flat_translations.select do |key, value|
|
24
|
-
|
24
|
+
YamlEntry.localization?(key, value)
|
25
25
|
end
|
26
26
|
|
27
27
|
@target_locales.each do |target_locale|
|
@@ -30,7 +30,7 @@ module TranslationIO
|
|
30
30
|
TranslationIO.info yaml_path, 2, 2
|
31
31
|
|
32
32
|
target_flat_special_translations = all_flat_special_translations.select do |key|
|
33
|
-
|
33
|
+
YamlEntry.from_locale?(key, target_locale) && !YamlEntry.ignored?(key)
|
34
34
|
end
|
35
35
|
|
36
36
|
yaml_data = YAMLConversion.get_yaml_data_from_flat_translations(target_flat_special_translations)
|
@@ -11,10 +11,6 @@ module TranslationIO
|
|
11
11
|
|
12
12
|
haml_source_files = config.haml_source_files
|
13
13
|
slim_source_files = config.slim_source_files
|
14
|
-
|
15
|
-
BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
|
16
|
-
BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
|
17
|
-
|
18
14
|
source_files = config.source_files
|
19
15
|
pot_path = config.pot_path
|
20
16
|
source_locale = config.source_locale
|
@@ -23,6 +19,9 @@ module TranslationIO
|
|
23
19
|
yaml_locales_path = config.yaml_locales_path
|
24
20
|
yaml_file_paths = config.yaml_file_paths
|
25
21
|
|
22
|
+
BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
|
23
|
+
BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
|
24
|
+
|
26
25
|
UpdatePotFileStep.new(pot_path, source_files).run(params)
|
27
26
|
UpdateAndCollectPoFilesStep.new(target_locales, pot_path, locales_path).run(params)
|
28
27
|
CreateYamlPoFilesStep.new(source_locale, target_locales, yaml_file_paths).run(params)
|
@@ -13,7 +13,7 @@ module TranslationIO
|
|
13
13
|
@yaml_file_paths.each do |locale_file_path|
|
14
14
|
if locale_file_removable?(locale_file_path)
|
15
15
|
if File.exist?(locale_file_path)
|
16
|
-
content_hash
|
16
|
+
content_hash = YAML::load(File.read(locale_file_path))
|
17
17
|
|
18
18
|
if content_hash
|
19
19
|
new_content_hash = content_hash.keep_if { |k| k.to_s == @source_locale.to_s }
|
@@ -25,11 +25,11 @@ module TranslationIO
|
|
25
25
|
all_flat_translations = FlatHash.to_flat_hash(all_translations)
|
26
26
|
|
27
27
|
all_flat_string_translations = all_flat_translations.select do |key, value|
|
28
|
-
|
28
|
+
YamlEntry.string?(key, value) && !YamlEntry.localization?(key, value)
|
29
29
|
end
|
30
30
|
|
31
31
|
source_flat_string_tanslations = all_flat_string_translations.select do |key|
|
32
|
-
|
32
|
+
YamlEntry.from_locale?(key, @source_locale) && !YamlEntry.ignored?(key)
|
33
33
|
end
|
34
34
|
|
35
35
|
@target_locales.each do |target_locale|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'translation_io/client/sync_operation/update_and_collect_pot_file_step'
|
2
2
|
require 'translation_io/client/sync_operation/create_yaml_pot_file_step'
|
3
|
+
require 'translation_io/client/sync_operation/apply_yaml_source_edits_step'
|
3
4
|
|
4
5
|
module TranslationIO
|
5
6
|
class Client
|
@@ -9,10 +10,6 @@ module TranslationIO
|
|
9
10
|
|
10
11
|
haml_source_files = config.haml_source_files
|
11
12
|
slim_source_files = config.slim_source_files
|
12
|
-
|
13
|
-
BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
|
14
|
-
BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
|
15
|
-
|
16
13
|
source_files = config.source_files
|
17
14
|
pot_path = config.pot_path
|
18
15
|
source_locale = config.source_locale
|
@@ -21,6 +18,11 @@ module TranslationIO
|
|
21
18
|
yaml_locales_path = config.yaml_locales_path
|
22
19
|
yaml_file_paths = config.yaml_file_paths
|
23
20
|
|
21
|
+
ApplyYamlSourceEditsStep.new(yaml_file_paths, source_locale).run(params)
|
22
|
+
|
23
|
+
BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
|
24
|
+
BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
|
25
|
+
|
24
26
|
UpdateAndCollectPotFileStep.new(pot_path, source_files).run(params)
|
25
27
|
CreateYamlPotFileStep.new(source_locale, yaml_file_paths).run(params)
|
26
28
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module TranslationIO
|
2
|
+
class Client
|
3
|
+
class SyncOperation < BaseOperation
|
4
|
+
class ApplyYamlSourceEditsStep
|
5
|
+
def initialize(yaml_file_paths, source_locale)
|
6
|
+
@yaml_file_paths = yaml_file_paths
|
7
|
+
@source_locale = source_locale
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(params)
|
11
|
+
TranslationIO.info "Downloading YAML source editions."
|
12
|
+
|
13
|
+
timestamp = YAML::load(File.read(TranslationIO.config.metadata_path))['timestamp'] rescue 0
|
14
|
+
|
15
|
+
params.merge!({ :timestamp => timestamp })
|
16
|
+
parsed_response = perform_source_edits_request(params)
|
17
|
+
|
18
|
+
unless parsed_response.nil?
|
19
|
+
TranslationIO.info "Applying YAML source editions."
|
20
|
+
|
21
|
+
parsed_response['source_edits'].each do |source_edit|
|
22
|
+
inserted = false
|
23
|
+
|
24
|
+
sort_by_project_locales_first(@yaml_file_paths).each do |file_path|
|
25
|
+
yaml_hash = YAML::load(File.read(file_path))
|
26
|
+
flat_yaml_hash = FlatHash.to_flat_hash(yaml_hash)
|
27
|
+
|
28
|
+
flat_yaml_hash.each do |key, value|
|
29
|
+
if key == "#{@source_locale}.#{source_edit['key']}" && value == source_edit['old_text']
|
30
|
+
TranslationIO.info "#{source_edit['key']} | #{source_edit['old_text']} -> #{source_edit['new_text']}", 2, 2
|
31
|
+
|
32
|
+
if locale_file_path_in_project?(file_path)
|
33
|
+
flat_yaml_hash[key] = source_edit['new_text']
|
34
|
+
|
35
|
+
File.open(file_path, 'w') do |f|
|
36
|
+
f.write(FlatHash.to_hash(flat_yaml_hash).to_yaml)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
yaml_path = File.join(TranslationIO.config.yaml_locales_path, "#{@source_locale}.yml")
|
40
|
+
|
41
|
+
if File.exists?(yaml_path) # en.yml
|
42
|
+
yaml_hash = YAML::load(File.read(yaml_path))
|
43
|
+
flat_yaml_hash = FlatHash.to_flat_hash(yaml_hash)
|
44
|
+
else
|
45
|
+
FileUtils::mkdir_p File.dirname(yaml_path)
|
46
|
+
flat_yaml_hash = {}
|
47
|
+
end
|
48
|
+
|
49
|
+
flat_yaml_hash["#{@source_locale}.#{source_edit['key']}"] = source_edit['new_text']
|
50
|
+
|
51
|
+
File.open(yaml_path, 'w') do |f|
|
52
|
+
f.write(FlatHash.to_hash(flat_yaml_hash).to_yaml)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
inserted = true
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
break if inserted
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
File.open(TranslationIO.config.metadata_path, 'w') do |f|
|
67
|
+
f.write({ 'timestamp' => Time.now.getutc.to_i }.to_yaml)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def perform_source_edits_request(params)
|
74
|
+
uri = URI("#{TranslationIO.client.endpoint}/projects/#{TranslationIO.client.api_key}/source_edits")
|
75
|
+
parsed_response = BaseOperation.perform_request(uri, params)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Sort YAML file paths by project locales first, gem locales after
|
79
|
+
# (to replace "overridden" source first)
|
80
|
+
def sort_by_project_locales_first(yaml_file_paths)
|
81
|
+
yaml_file_paths.sort do |x, y|
|
82
|
+
a = locale_file_path_in_project?(x)
|
83
|
+
b = locale_file_path_in_project?(y)
|
84
|
+
(!a && b) ? 1 : ((a && !b) ? -1 : 0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def locale_file_path_in_project?(locale_file_path)
|
89
|
+
TranslationIO.normalize_path(locale_file_path).start_with?(
|
90
|
+
TranslationIO.normalize_path(TranslationIO.config.yaml_locales_path)
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -24,7 +24,7 @@ module TranslationIO
|
|
24
24
|
all_flat_translations = FlatHash.to_flat_hash(all_translations)
|
25
25
|
|
26
26
|
source_flat_string_tanslations = all_flat_translations.select do |key, value|
|
27
|
-
|
27
|
+
YamlEntry.string?(key, value) && YamlEntry.from_locale?(key, @source_locale) && !YamlEntry.ignored?(key) && !YamlEntry.localization?(key, value)
|
28
28
|
end
|
29
29
|
|
30
30
|
pot_representation = GetText::PO.new
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module TranslationIO
|
2
2
|
class Config
|
3
|
-
attr_accessor :api_key, :locales_path
|
3
|
+
attr_accessor :api_key, :locales_path, :yaml_locales_path
|
4
4
|
attr_accessor :source_locale, :target_locales
|
5
5
|
attr_accessor :endpoint
|
6
6
|
attr_accessor :verbose
|
@@ -8,6 +8,7 @@ module TranslationIO
|
|
8
8
|
attr_accessor :ignored_key_prefixes
|
9
9
|
attr_accessor :localization_key_prefixes
|
10
10
|
attr_accessor :charset
|
11
|
+
attr_accessor :metadata_path
|
11
12
|
|
12
13
|
attr_accessor :pot_msgid_bugs_address
|
13
14
|
attr_accessor :pot_package_name
|
@@ -17,6 +18,7 @@ module TranslationIO
|
|
17
18
|
|
18
19
|
def initialize
|
19
20
|
self.locales_path = File.join('config', 'locales', 'gettext')
|
21
|
+
self.yaml_locales_path = File.join('config', 'locales')
|
20
22
|
self.source_locale = :en
|
21
23
|
self.target_locales = []
|
22
24
|
self.endpoint = 'https://translation.io/api'
|
@@ -25,6 +27,7 @@ module TranslationIO
|
|
25
27
|
self.ignored_key_prefixes = []
|
26
28
|
self.localization_key_prefixes = []
|
27
29
|
self.charset = 'UTF-8'
|
30
|
+
self.metadata_path = File.join('config', 'locales', '.translation_io')
|
28
31
|
|
29
32
|
self.pot_msgid_bugs_address = 'contact@translation.io'
|
30
33
|
self.pot_package_name = File.basename(Dir.pwd)
|
@@ -53,10 +56,6 @@ module TranslationIO
|
|
53
56
|
paths
|
54
57
|
end
|
55
58
|
|
56
|
-
def yaml_locales_path
|
57
|
-
'config/locales'
|
58
|
-
end
|
59
|
-
|
60
59
|
def haml_source_files
|
61
60
|
Dir['**/*.{haml}'].select do |p|
|
62
61
|
!p.start_with?('vendor/') && !p.start_with?('tmp/')
|
@@ -35,7 +35,7 @@ module TranslationIO
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def localization?(key, value)
|
38
|
-
key.present? && (localization_prefix?(key) || (!
|
38
|
+
key.present? && (localization_prefix?(key) || (!string?(key, value) && !value.nil?))
|
39
39
|
end
|
40
40
|
|
41
41
|
def localization_prefix?(key)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aurelien Malisart
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gettext
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/translation_io/client/init_operation/update_and_collect_po_files_step.rb
|
104
104
|
- lib/translation_io/client/init_operation/update_pot_file_step.rb
|
105
105
|
- lib/translation_io/client/sync_operation.rb
|
106
|
+
- lib/translation_io/client/sync_operation/apply_yaml_source_edits_step.rb
|
106
107
|
- lib/translation_io/client/sync_operation/create_yaml_pot_file_step.rb
|
107
108
|
- lib/translation_io/client/sync_operation/update_and_collect_pot_file_step.rb
|
108
109
|
- lib/translation_io/config.rb
|
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
134
|
version: '0'
|
134
135
|
requirements: []
|
135
136
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.4.5
|
137
138
|
signing_key:
|
138
139
|
specification_version: 4
|
139
140
|
summary: Rails translation made _("simple") with YAML and GetText.
|