i18n_screwdriver 5.1 → 6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36b2576441d68ecd7a79975b76fee091de68f10f
4
- data.tar.gz: 704059b0323d79e61f0fd68f2870942c8880f71a
3
+ metadata.gz: 3fb8ed962112d953a9faf5f4150d3f213710179d
4
+ data.tar.gz: 6d3e1a2a3f0258d4a5c49796ab800c002fbf60a5
5
5
  SHA512:
6
- metadata.gz: 675315966e45b946ea2b3a5973cba0974e9d6efd8794deeeacd499e60149a7efdb5a08309af45dfb51573d47499f69713baff0f29d8fc774bc93141e6dc822be
7
- data.tar.gz: 081994bb117a431eb84d5bd45e373d985dd80f4124ad08d7e22552a293fce7e162e5ca5f1b988c97052bbbb3b66e0ebed9f5882b0dbc666d4ab8c94957d1b67a
6
+ metadata.gz: 434aef9acfceefb716e73afe39ce90ab2e78c24a3a56c17ab6aa25756419eec475ef3117d8d9adddb280f405c20cb53daace89337c17312c84f2b8f88d4d05c4
7
+ data.tar.gz: a417c66dc9ef6213436057c82fb7e639233c2cde4e9e6242e12446359916eac80fd3489ae5457f2cc0fb02bd0f246bdc023e8c61322154fd81c8e528dea864d1
data/Gemfile.lock CHANGED
@@ -1,79 +1,69 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_screwdriver (2.1.1)
4
+ i18n_screwdriver (6.0)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (3.2.8)
11
- actionpack (= 3.2.8)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.8)
14
- activemodel (= 3.2.8)
15
- activesupport (= 3.2.8)
16
- builder (~> 3.0.0)
10
+ actionmailer (4.1.6)
11
+ actionpack (= 4.1.6)
12
+ actionview (= 4.1.6)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ actionpack (4.1.6)
15
+ actionview (= 4.1.6)
16
+ activesupport (= 4.1.6)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.6)
20
+ activesupport (= 4.1.6)
21
+ builder (~> 3.1)
17
22
  erubis (~> 2.7.0)
18
- journey (~> 1.0.4)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.1.3)
23
- activemodel (3.2.8)
24
- activesupport (= 3.2.8)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.8)
27
- activemodel (= 3.2.8)
28
- activesupport (= 3.2.8)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.8)
32
- activemodel (= 3.2.8)
33
- activesupport (= 3.2.8)
34
- activesupport (3.2.8)
35
- i18n (~> 0.6)
36
- multi_json (~> 1.0)
37
- arel (3.0.2)
38
- builder (3.0.0)
23
+ activemodel (4.1.6)
24
+ activesupport (= 4.1.6)
25
+ builder (~> 3.1)
26
+ activerecord (4.1.6)
27
+ activemodel (= 4.1.6)
28
+ activesupport (= 4.1.6)
29
+ arel (~> 5.0.0)
30
+ activesupport (4.1.6)
31
+ i18n (~> 0.6, >= 0.6.9)
32
+ json (~> 1.7, >= 1.7.7)
33
+ minitest (~> 5.1)
34
+ thread_safe (~> 0.1)
35
+ tzinfo (~> 1.1)
36
+ arel (5.0.1.20140414130214)
37
+ builder (3.2.2)
39
38
  diff-lcs (1.1.3)
40
39
  erubis (2.7.0)
41
- hike (1.2.1)
42
- i18n (0.6.0)
43
- journey (1.0.4)
44
- json (1.7.5)
45
- mail (2.4.4)
46
- i18n (>= 0.4.0)
47
- mime-types (~> 1.16)
48
- treetop (~> 1.4.8)
49
- mime-types (1.19)
50
- multi_json (1.3.6)
51
- polyglot (0.3.3)
52
- rack (1.4.1)
53
- rack-cache (1.2)
54
- rack (>= 0.4)
55
- rack-ssl (1.3.2)
56
- rack
57
- rack-test (0.6.1)
40
+ hike (1.2.3)
41
+ i18n (0.6.11)
42
+ json (1.8.1)
43
+ mail (2.6.1)
44
+ mime-types (>= 1.16, < 3)
45
+ mime-types (2.3)
46
+ minitest (5.4.2)
47
+ multi_json (1.10.1)
48
+ rack (1.5.2)
49
+ rack-test (0.6.2)
58
50
  rack (>= 1.0)
59
- rails (3.2.8)
60
- actionmailer (= 3.2.8)
61
- actionpack (= 3.2.8)
62
- activerecord (= 3.2.8)
63
- activeresource (= 3.2.8)
64
- activesupport (= 3.2.8)
65
- bundler (~> 1.0)
66
- railties (= 3.2.8)
67
- railties (3.2.8)
68
- actionpack (= 3.2.8)
69
- activesupport (= 3.2.8)
70
- rack-ssl (~> 1.3.2)
51
+ rails (4.1.6)
52
+ actionmailer (= 4.1.6)
53
+ actionpack (= 4.1.6)
54
+ actionview (= 4.1.6)
55
+ activemodel (= 4.1.6)
56
+ activerecord (= 4.1.6)
57
+ activesupport (= 4.1.6)
58
+ bundler (>= 1.3.0, < 2.0)
59
+ railties (= 4.1.6)
60
+ sprockets-rails (~> 2.0)
61
+ railties (4.1.6)
62
+ actionpack (= 4.1.6)
63
+ activesupport (= 4.1.6)
71
64
  rake (>= 0.8.7)
72
- rdoc (~> 3.4)
73
- thor (>= 0.14.6, < 2.0)
74
- rake (0.9.2.2)
75
- rdoc (3.12)
76
- json (~> 1.4)
65
+ thor (>= 0.18.1, < 2.0)
66
+ rake (10.3.2)
77
67
  rspec (2.10.0)
78
68
  rspec-core (~> 2.10.0)
79
69
  rspec-expectations (~> 2.10.0)
@@ -82,16 +72,20 @@ GEM
82
72
  rspec-expectations (2.10.0)
83
73
  diff-lcs (~> 1.1.3)
84
74
  rspec-mocks (2.10.1)
85
- sprockets (2.1.3)
75
+ sprockets (2.12.2)
86
76
  hike (~> 1.2)
77
+ multi_json (~> 1.0)
87
78
  rack (~> 1.0)
88
79
  tilt (~> 1.1, != 1.3.0)
89
- thor (0.16.0)
90
- tilt (1.3.3)
91
- treetop (1.4.10)
92
- polyglot
93
- polyglot (>= 0.3.1)
94
- tzinfo (0.3.33)
80
+ sprockets-rails (2.1.4)
81
+ actionpack (>= 3.0)
82
+ activesupport (>= 3.0)
83
+ sprockets (~> 2.8)
84
+ thor (0.19.1)
85
+ thread_safe (0.3.4)
86
+ tilt (1.4.1)
87
+ tzinfo (1.2.2)
88
+ thread_safe (~> 0.1)
95
89
 
96
90
  PLATFORMS
97
91
  ruby
data/README.rdoc CHANGED
@@ -26,6 +26,10 @@ In your views, helpers and controllers use the convenient underscore helper meth
26
26
 
27
27
  _("your translation")
28
28
 
29
+ Starting with version 6.0 you can also use symbols as keys
30
+
31
+ _(:my_long_text)
32
+
29
33
  Variable interpolation works as for normal strings
30
34
 
31
35
  _("Hello %{name}!") % {name: "Liah"}
@@ -1,3 +1,3 @@
1
1
  module I18nScrewdriver
2
- VERSION = "5.1"
2
+ VERSION = "6.0"
3
3
  end
@@ -4,22 +4,27 @@ require "i18n_screwdriver/translation_helper"
4
4
  require "i18n_screwdriver/rails"
5
5
 
6
6
  module I18nScrewdriver
7
- def self.filename(locale)
8
- "config/locales/application.#{locale}.yml"
7
+ def self.filename_for_locale(locale)
8
+ File.join("config", "locales", "application.#{locale}.yml")
9
9
  end
10
10
 
11
11
  def self.for_key(string)
12
- Digest::MD5.hexdigest(string.strip)
12
+ string = string.strip
13
+ (string =~ /^:[a-z][a-z0-9_]*$/) ? string : Digest::MD5.hexdigest(string)
14
+ end
15
+
16
+ def self.file_with_translations_exists?(locale)
17
+ File.exists?(filename_for_locale(locale))
13
18
  end
14
19
 
15
20
  def self.load_translations(locale)
16
- filename = self.filename(locale)
17
- raise "File #{filename} not found!" unless File.exists?(filename)
18
- YAML.load_file(filename)[locale]
21
+ path = filename_for_locale(locale)
22
+ raise "File #{path} not found!" unless File.exists?(path)
23
+ sanitize_hash(YAML.load_file(path)[locale])
19
24
  end
20
25
 
21
26
  def self.write_translations(locale, translations)
22
- File.open(filename(locale), "w") do |file|
27
+ File.open(filename_for_locale(locale), "w") do |file|
23
28
  file.puts "# use rake task i18n:update to generate this file"
24
29
  file.puts
25
30
  file.puts({locale => in_utf8(translations)}.to_yaml)
@@ -34,6 +39,10 @@ module I18nScrewdriver
34
39
  end
35
40
  end
36
41
 
42
+ def self.grab_symbols_to_be_translated(string)
43
+ string.scan(/_\((:[a-z][a-z0-9_]*)\)/).flatten
44
+ end
45
+
37
46
  def self.in_utf8(hash)
38
47
  {}.tap do |result|
39
48
  hash.sort.each do |k, v|
@@ -72,5 +81,52 @@ module I18nScrewdriver
72
81
  end
73
82
  end
74
83
  end
75
- end
76
84
 
85
+ def self.gather_translations
86
+ texts = []
87
+ symbols = []
88
+ Dir.glob("**/*.{haml,erb,slim,rb}").each do |file|
89
+ input = File.read(file)
90
+ texts.concat(grab_texts_to_be_translated(input))
91
+ symbols.concat(grab_symbols_to_be_translated(input))
92
+ end
93
+ translations = Hash[texts.uniq.map{ |text| [for_key(text), text] }]
94
+ translations.merge(Hash[symbols.uniq.map{ |symbol| [for_key(symbol), ""] }])
95
+ end
96
+
97
+ def self.default_locale
98
+ @default_locale ||= begin
99
+ raise "Please set I18.default_locale" unless I18n.default_locale.present?
100
+ I18n.default_locale.to_s
101
+ end
102
+ end
103
+
104
+ def self.available_locales
105
+ @available_locales ||= begin
106
+ raise "Please set I18.available_locales" unless I18n.available_locales.count > 0
107
+ I18n.available_locales.map(&:to_s)
108
+ end
109
+ end
110
+
111
+ def self.dummy_text
112
+ "TRANSLATION_MISSING"
113
+ end
114
+
115
+ def self.update_translations_file(locale, translations)
116
+ existing_translations = file_with_translations_exists?(locale) ? load_translations(locale) : {}
117
+ existing_translations.select!{ |k| translations.has_key?(k) }
118
+
119
+ translations.each do |k, v|
120
+ next if existing_translations[k]
121
+ existing_translations[k] = (default_locale == locale) ? v : dummy_text
122
+ end
123
+
124
+ write_translations(locale, existing_translations)
125
+ end
126
+
127
+ def self.sanitize_hash(hash)
128
+ {}.tap do |new_hash|
129
+ hash.each{ |k, v| new_hash[k.to_s] = v.to_s }
130
+ end
131
+ end
132
+ end
data/lib/tasks/i18n.rake CHANGED
@@ -1,65 +1,10 @@
1
1
  namespace :i18n do
2
- def default_locale
3
- @default_locale ||= begin
4
- raise "Please set I18.default_locale" unless I18n.default_locale.present?
5
- I18n.default_locale.to_s
6
- end
7
- end
8
-
9
- def available_locales
10
- @available_locales ||= begin
11
- raise "Please set I18.available_locales" unless I18n.available_locales.count > 0
12
- I18n.available_locales.map(&:to_s)
13
- end
14
- end
15
-
16
- def dummy_text
17
- "TRANSLATION_MISSING"
18
- end
19
-
20
2
  desc 'Find all translations in views, helpers and controllers'
21
3
  task :update => :environment do
22
- # parse all files for texts to be translated
23
- texts = []
24
- Dir.glob("**/*.{haml,erb,slim,rb}").each do |file|
25
- texts.concat(I18nScrewdriver.grab_texts_to_be_translated(File.read(file)))
26
- end
27
-
28
- # properly handle character codes in strings (\n, \r, \t, \\)
29
- texts.map!{ |text| I18nScrewdriver.unescape_string(text) }
30
-
31
- # remove duplicates
32
- texts.uniq!
33
-
34
- # transform translations into a hash, sanitizing the keys
35
- translations = {}
36
- texts.each{ |text| translations[I18nScrewdriver.for_key(text)] = text }
37
-
38
- # rewrite default language file with updated translations
4
+ translations = I18nScrewdriver.gather_translations
39
5
  puts "Found #{translations.keys.size} unique translations"
40
- I18nScrewdriver.write_translations(default_locale, translations)
41
- end
42
-
43
- desc 'Write dummy translation files so they can manually be translated'
44
- task :update_foreign => :environment do
45
- # load translations from default locale
46
- translations = I18nScrewdriver.load_translations(default_locale)
47
-
48
- # process each language we'd like to translate
49
- (available_locales - [default_locale]).each do |locale|
50
- filename = I18nScrewdriver.filename(locale)
51
-
52
- # load existing translations
53
- existing_translations = File.exists?(filename) ? I18nScrewdriver.load_translations(locale) : {}
54
-
55
- # delete removed translations from hash
56
- existing_translations.reject!{ |k| !translations.has_key?(k) }
57
-
58
- # add new translations
59
- translations.each_key{ |k| existing_translations[k] ||= dummy_text }
60
-
61
- # write the file
62
- I18nScrewdriver.write_translations(locale, existing_translations)
6
+ I18nScrewdriver.available_locales.each do |locale|
7
+ I18nScrewdriver.update_translations_file(locale, translations)
63
8
  end
64
9
  end
65
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_screwdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: '5.1'
4
+ version: '6.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Miesel
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-19 00:00:00.000000000 Z
12
+ date: 2014-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rails
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 3.0.0
42
42
  description: make translating with rails i18n fun again
@@ -47,7 +47,7 @@ executables: []
47
47
  extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
- - .gitignore
50
+ - ".gitignore"
51
51
  - Gemfile
52
52
  - Gemfile.lock
53
53
  - LICENSE.txt
@@ -71,17 +71,17 @@ require_paths:
71
71
  - lib
72
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project: i18n_screwdriver
84
- rubygems_version: 2.2.1
84
+ rubygems_version: 2.2.2
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: make translating with rails i18n fun again