gettext_simple 0.0.4 → 0.0.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: 160fe8d8a9f477f0b81264bc7505a02dc015b10b
4
- data.tar.gz: c29d0a464ca361ad747ea9e018dbd803d113176d
3
+ metadata.gz: e43070b335b7174bf71fbb327f5fd561e4ea3138
4
+ data.tar.gz: 71c72e671bdb466f1ab9a5d4dd4ff04855e176e4
5
5
  SHA512:
6
- metadata.gz: 20b8d3e2847981c4b12f9c99fd7cc7659f45c03316b08a8f29cb26a5a252e6fdf330c5ba5a393a8003a3c3f6368831fe579e1eb66a802588abb039e5c4c8c0b3
7
- data.tar.gz: dd48e51243a04a8b5d06f1b0c08b4288e11c3beff410c4e2723f617677a32041756a1327a64d4269cb0300ac09bff56308d45a0db98ff2aa52ff190d4a3a2607
6
+ metadata.gz: 9c153f4b4a9b558445d11ebe3f8b0457ae74e5b0a27a120ff94e720c522e033fd4595d8632097db1f79318c2cc5ee9e5471bc0adbe413f20f356c68993806b6a
7
+ data.tar.gz: 4509cddc233d9f337c0216c29d29aaeac21337a232a925853255ac461767d97e4aecd4d6405e9bfd10fcc910c122591098dba04fc80d953f824675dcf27f1597
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gettext_simple"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -8,6 +8,7 @@ class GettextSimple
8
8
  :default_locale => "en"
9
9
  }.merge(args)
10
10
  @locales = {}
11
+ @debug = @args[:debug]
11
12
 
12
13
  # To avoid doing a hash lookup on every translate.
13
14
  @i18n = @args[:i18n]
@@ -37,20 +38,26 @@ class GettextSimple
37
38
  check_folders = ["LC_MESSAGES", "LC_ALL"]
38
39
 
39
40
  Dir.foreach(dir) do |file|
41
+ debug "New locale folder found: '#{file}'." if @debug
42
+
40
43
  fn = "#{dir}/#{file}"
41
- if File.directory?(fn) && file.match(/^[a-z]{2}/)
42
- @locales[file] = {} unless @locales[file]
44
+ if !File.directory?(fn) || !file.match(/^[a-z]{2}/)
45
+ debug "Skipping: '#{file}'." if @debug
46
+ next
47
+ end
48
+
49
+ @locales[file] = {} unless @locales[file]
50
+
51
+ check_folders.each do |fname|
52
+ fpath = "#{dir}/#{file}/#{fname}"
53
+ next if !File.exists?(fpath) || !File.directory?(fpath)
54
+ debug "Found subfolder in '#{file}': '#{fname}'." if @debug
43
55
 
44
- check_folders.each do |fname|
45
- fpath = "#{dir}/#{file}/#{fname}"
46
-
47
- if File.exists?(fpath) && File.directory?(fpath)
48
- Dir.foreach(fpath) do |pofile|
49
- if pofile.match(/\.po$/)
50
- pofn = "#{dir}/#{file}/#{fname}/#{pofile}"
51
- scan_pofile(file, pofn)
52
- end
53
- end
56
+ Dir.foreach(fpath) do |pofile|
57
+ if pofile.match(/\.po$/)
58
+ debug "Starting to parse '#{pofile}'." if @debug
59
+ pofn = "#{dir}/#{file}/#{fname}/#{pofile}"
60
+ scan_pofile(file, pofn)
54
61
  end
55
62
  end
56
63
  end
@@ -78,12 +85,14 @@ class GettextSimple
78
85
  end
79
86
  end
80
87
 
88
+ debug "Translation with locale '#{locale}' and replaces '#{replaces}': '#{str}' to '#{translated_str}'." if @debug
89
+
81
90
  return translated_str
82
91
  end
83
92
 
84
93
  def translate(str, replaces = nil)
85
94
  if @i18n
86
- locale = I18n.locale
95
+ locale = I18n.locale.to_s
87
96
  elsif locale = Thread.current[:gettext_simple_locale]
88
97
  # Locale already set through condition.
89
98
  else
@@ -99,6 +108,10 @@ class GettextSimple
99
108
  end
100
109
 
101
110
  private
111
+
112
+ def debug(str)
113
+ $stderr.puts str if @debug
114
+ end
102
115
 
103
116
  def scan_pofile(locale, filepath)
104
117
  current_id = nil
@@ -107,6 +120,7 @@ private
107
120
  reading_id = false
108
121
  reading_translation = false
109
122
 
123
+ debug "Opening file for parsing: '#{filepath}' in locale '#{locale}'." if @debug
110
124
  File.open(filepath, "r", :encoding => @args[:encoding]) do |fp|
111
125
  fp.each_line do |line|
112
126
  if match = line.match(/^(msgid|msgstr)\s+"(.*)"$/)
@@ -150,6 +164,10 @@ private
150
164
 
151
165
  def add_translation(locale, key, val)
152
166
  raise "No such language: '#{locale}'." unless @locales.key?(locale)
153
- @locales[locale][key] = val unless val.to_s.empty?
167
+
168
+ if !key.to_s.empty? && !val.to_s.empty?
169
+ debug "Found translation for locale '#{locale}' '#{key}' which is: '#{val}'." if @debug
170
+ @locales[locale][key] = val
171
+ end
154
172
  end
155
173
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext_simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen