translation 1.4 → 1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6ca60fd941e00c41f19220e38e4be7483513b03
|
4
|
+
data.tar.gz: e52d363d594a15f637c9d14b81eb9577b83cd4d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6ed0c302456c4152e8ace2355d9036494a4d9a498ca924c9f0e8a0a304979cd067682c7f8684b425e08790f8af84c0b74bf03c0608bd9116508e6b686cc0d77
|
7
|
+
data.tar.gz: e7a5f82a5e66036dbc09ed1e5c29b408f630e340e6487bf8bb449ac08c02be700e3bd5210d7725025dfee7062f807f3b6583a5e4fe99c9ecfab61d3440233408
|
data/README.md
CHANGED
@@ -8,16 +8,16 @@ Add this gem to your [Rails](http://rubyonrails.org) app to translate it with [T
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
Add the gem to your project's Gemfile
|
11
|
+
Add the gem to your project's Gemfile:
|
12
12
|
|
13
13
|
gem 'translation'
|
14
14
|
|
15
|
-
Then
|
15
|
+
Then:
|
16
16
|
|
17
17
|
* Create a translation project [from the UI](https://translation.io).
|
18
18
|
* Copy the initializer into your Rails app (`config/initializers/translation.rb`)
|
19
19
|
|
20
|
-
The initializer looks like this
|
20
|
+
The initializer looks like this:
|
21
21
|
|
22
22
|
TranslationIO.configure do |config|
|
23
23
|
config.api_key = 'some api key which is very long'
|
@@ -25,7 +25,7 @@ The initializer looks like this :
|
|
25
25
|
config.target_locales = ['fr', 'nl', 'de', 'es']
|
26
26
|
end
|
27
27
|
|
28
|
-
And finish by inititalizing your translation project with
|
28
|
+
And finish by inititalizing your translation project with:
|
29
29
|
|
30
30
|
bundle exec rake translation:init
|
31
31
|
|
@@ -34,36 +34,46 @@ If you later need to add/remove target languages, please read our
|
|
34
34
|
|
35
35
|
## Sync
|
36
36
|
|
37
|
-
To send new translatable keys/strings and get new translations from Translation.io, simply run
|
37
|
+
To send new translatable keys/strings and get new translations from Translation.io, simply run:
|
38
38
|
|
39
39
|
bundle exec rake translation:sync
|
40
40
|
|
41
41
|
## Sync and Purge
|
42
42
|
|
43
|
-
If you also need to remove unused keys/strings from Translation.io using the current branch as reference
|
43
|
+
If you also need to remove unused keys/strings from Translation.io using the current branch as reference:
|
44
44
|
|
45
45
|
bundle exec rake translation:sync_and_purge
|
46
46
|
|
47
47
|
As the name says, this operation will also perform a sync at the same time.
|
48
48
|
|
49
|
-
Warning
|
49
|
+
Warning: all keys that are not present in the current branch will be **permanently deleted both on Translation.io and in your app**.
|
50
50
|
|
51
51
|
## Advanced Configuration Options
|
52
52
|
|
53
53
|
The `TranslationIO.configure` block in `config/initializers/translation.rb` can take several optional configuration options.
|
54
54
|
|
55
|
+
### Disable GetText
|
55
56
|
|
57
|
+
Sometimes, you only want to use YAML and don't want to be bothered by GetText at all.
|
58
|
+
For these cases, you just have to add `disable_gettext` in the config file.
|
59
|
+
|
60
|
+
For example:
|
61
|
+
|
62
|
+
TranslationIO.configure do |config|
|
63
|
+
...
|
64
|
+
config.disable_gettext = true
|
65
|
+
...
|
66
|
+
end
|
56
67
|
|
57
68
|
### Ignored YAML keys
|
58
69
|
|
59
70
|
Sometimes you would like to ignore some YAML keys coming from gems or so.
|
60
71
|
You can use the `ignored_key_prefixes` for that.
|
61
72
|
|
62
|
-
For example
|
73
|
+
For example:
|
63
74
|
|
64
75
|
TranslationIO.configure do |config|
|
65
76
|
...
|
66
|
-
|
67
77
|
config.ignored_key_prefixes = [
|
68
78
|
'number.human.',
|
69
79
|
'admin.',
|
@@ -74,12 +84,13 @@ For example :
|
|
74
84
|
'views.pagination.',
|
75
85
|
'enumerize.visibility.'
|
76
86
|
]
|
87
|
+
...
|
77
88
|
end
|
78
89
|
|
79
90
|
### Custom localization key prefixes
|
80
91
|
|
81
92
|
Rails YAML files contain not only translation strings but also localization values (integers, arrays, booleans)
|
82
|
-
in the same place and that's bad. For example
|
93
|
+
in the same place and that's bad. For example: date formats, number separators, default
|
83
94
|
currency or measure units, etc.
|
84
95
|
|
85
96
|
A translator is supposed to translate, not localize. That's not his role to choose how you want your dates or
|
@@ -92,28 +103,28 @@ That's why these localization keys are detected and separated on a dedicated YAM
|
|
92
103
|
We automatically threat [known localization keys](lib/translation_io/yaml_entry.rb), but if you would like
|
93
104
|
to add some more, use the `localization_key_prefixes` option.
|
94
105
|
|
95
|
-
For example
|
106
|
+
For example:
|
96
107
|
|
97
108
|
TranslationIO.configure do |config|
|
98
109
|
...
|
99
|
-
|
100
110
|
config.localization_key_prefixes = ['my_gem.date.formats']
|
111
|
+
...
|
101
112
|
end
|
102
113
|
|
103
114
|
### Paths where locales are stored (not recommended)
|
104
115
|
|
105
|
-
You can specify where your GetText and YAML files are on disk
|
116
|
+
You can specify where your GetText and YAML files are on disk:
|
106
117
|
|
107
118
|
TranslationIO.configure do |config|
|
108
119
|
...
|
109
|
-
|
110
120
|
config.locales_path = 'some/path' # defaults to config/locales/gettext
|
111
121
|
config.yaml_locales_path = 'some/path' # defaults to config/locales
|
122
|
+
...
|
112
123
|
end
|
113
124
|
|
114
125
|
## Tests
|
115
126
|
|
116
|
-
To run the specs
|
127
|
+
To run the specs:
|
117
128
|
|
118
129
|
bundle
|
119
130
|
bundle exec rspec
|
@@ -29,15 +29,32 @@ module TranslationIO
|
|
29
29
|
create_yaml_pot_files_step = CreateYamlPoFilesStep.new(source_locale, target_locales, yaml_file_paths)
|
30
30
|
create_yaml_pot_files_step.run(params)
|
31
31
|
|
32
|
-
all_used_yaml_locales
|
33
|
-
|
32
|
+
all_used_yaml_locales = (create_yaml_pot_files_step.all_used_yaml_locales.to_a.map(&:to_s) - [source_locale.to_s]).sort.map(&:to_s)
|
33
|
+
is_source_locale_unfound = !source_locale.in?(all_used_yaml_locales)
|
34
|
+
unfound_target_locales = target_locales - all_used_yaml_locales
|
34
35
|
|
35
|
-
if
|
36
|
+
if is_source_locale_unfound
|
36
37
|
puts
|
37
38
|
puts "----------"
|
38
|
-
puts "Your `config.
|
39
|
-
puts "
|
40
|
-
puts "
|
39
|
+
puts "Your `config.source_locale` is \"#{source_locale}\" but no YAML keys were found for this locale."
|
40
|
+
puts "Check that you haven't misspelled the locale (ex. 'en-GB' instead of 'en')."
|
41
|
+
puts "----------"
|
42
|
+
puts "Do you want to continue anyway? (y/N)"
|
43
|
+
|
44
|
+
print "> "
|
45
|
+
input = STDIN.gets.strip
|
46
|
+
|
47
|
+
if input != 'y' && input != 'Y'
|
48
|
+
exit(0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if unfound_target_locales.any?
|
53
|
+
puts
|
54
|
+
puts "----------"
|
55
|
+
puts "Your `config.target_locales` are [#{target_locales.sort.join(', ')}]."
|
56
|
+
puts "But we haven't found any YAML key for [#{unfound_target_locales.join(', ')}], is this normal?"
|
57
|
+
puts "If not, check that you haven't misspelled the locale (ex. 'en-GB' instead of 'en')."
|
41
58
|
puts "----------"
|
42
59
|
puts "Do you want to continue? (y/N)"
|
43
60
|
|
@@ -26,35 +26,39 @@ module TranslationIO
|
|
26
26
|
flat_yaml_hash = FlatHash.to_flat_hash(yaml_hash)
|
27
27
|
|
28
28
|
flat_yaml_hash.each do |key, value|
|
29
|
-
if key == "#{@source_locale}.#{source_edit['key']}"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
29
|
+
if key == "#{@source_locale}.#{source_edit['key']}"
|
30
|
+
if value == source_edit['old_text']
|
31
|
+
TranslationIO.info "#{source_edit['key']} | #{source_edit['old_text']} -> #{source_edit['new_text']}", 2, 2
|
32
|
+
|
33
|
+
if locale_file_path_in_project?(file_path)
|
34
|
+
flat_yaml_hash[key] = source_edit['new_text']
|
35
|
+
|
36
|
+
File.open(file_path, 'w') do |f|
|
37
|
+
f.write(FlatHash.to_hash(flat_yaml_hash).to_yaml)
|
38
|
+
end
|
39
|
+
else # override source text of gem
|
40
|
+
yaml_path = File.join(TranslationIO.config.yaml_locales_path, "#{@source_locale}.yml")
|
41
|
+
|
42
|
+
if File.exists?(yaml_path) # source yaml file
|
43
|
+
yaml_hash = YAML::load(File.read(yaml_path))
|
44
|
+
flat_yaml_hash = FlatHash.to_flat_hash(yaml_hash)
|
45
|
+
else
|
46
|
+
FileUtils::mkdir_p File.dirname(yaml_path)
|
47
|
+
flat_yaml_hash = {}
|
48
|
+
end
|
49
|
+
|
50
|
+
flat_yaml_hash["#{@source_locale}.#{source_edit['key']}"] = source_edit['new_text']
|
51
|
+
|
52
|
+
File.open(yaml_path, 'w') do |f|
|
53
|
+
f.write(FlatHash.to_hash(flat_yaml_hash).to_yaml)
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
57
|
+
inserted = true
|
58
|
+
break
|
59
|
+
else
|
60
|
+
TranslationIO.info "#{source_edit['key']} | Ignored because translation was updated directly in source YAML file", 2, 2
|
54
61
|
end
|
55
|
-
|
56
|
-
inserted = true
|
57
|
-
break
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
@@ -64,7 +68,7 @@ module TranslationIO
|
|
64
68
|
end
|
65
69
|
|
66
70
|
File.open(TranslationIO.config.metadata_path, 'w') do |f|
|
67
|
-
f.write({ 'timestamp' => Time.now.
|
71
|
+
f.write({ 'timestamp' => Time.now.utc.to_i }.to_yaml)
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
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.
|
4
|
+
version: '1.5'
|
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:
|
12
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gettext
|