gettext_simple 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/VERSION +1 -1
- data/gettext_simple.gemspec +2 -2
- data/lib/gettext_simple.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c175117d02717c98b5d0e0ca0cc2209e55454bdb
|
4
|
+
data.tar.gz: 779101b352b8f53452f39fbb3fa75f06b2e516d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717e09c91b277baa776384d4e1edbbb57f2167b93f58b7a300aa8f8515c736a8d695d907efc35ecf05b9d66b4afdc7a4bbd404d67a0e618b66da5cb256d1d98e
|
7
|
+
data.tar.gz: 34d877e509a0f9d443a70f74f6b0d59fcfec2052038e1d75cec6ab5930b81c10a2ac099bea49f36fb8eba0148de305634cac7012122a57147113f421ea27bfe2
|
data/README.md
CHANGED
@@ -2,11 +2,18 @@
|
|
2
2
|
|
3
3
|
A very simple implementation of Gettext for Ruby.
|
4
4
|
|
5
|
-
|
5
|
+
# Install
|
6
|
+
|
7
|
+
Start by putting this in your Gemfile:
|
8
|
+
```ruby
|
9
|
+
gem 'gettext_simple'
|
10
|
+
```
|
11
|
+
|
12
|
+
This is how it could be initialized in Rails and take the locale from I18n.locale by placing this code in `"#{Rails.root}/config/initializers/gettext_simple.rb`:
|
6
13
|
```ruby
|
7
14
|
require "gettext_simple"
|
8
15
|
gettext_simple = GettextSimple.new(:i18n => true)
|
9
|
-
gettext_simple.load_dir("#{
|
16
|
+
gettext_simple.load_dir("#{Rails.root}/locales_gettext")
|
10
17
|
gettext_simple.register_kernel_methods
|
11
18
|
|
12
19
|
puts _("Hello world")
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/gettext_simple.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "gettext_simple"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
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"]
|
12
|
-
s.date = "2014-04-
|
12
|
+
s.date = "2014-04-11"
|
13
13
|
s.description = "A very simple version of Gettext reading .po files directly."
|
14
14
|
s.email = "k@spernj.org"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/gettext_simple.rb
CHANGED
@@ -69,9 +69,8 @@ class GettextSimple
|
|
69
69
|
# str = "Hello" #=> "Hello"
|
70
70
|
# gtext.trans("da_DK", str) #=> "Hej"
|
71
71
|
def translate_with_locale(locale, str, replaces = nil)
|
72
|
-
locale = locale.to_s
|
73
72
|
str = str.to_s
|
74
|
-
raise "Locale was not found: '#{locale}' in '#{@locales.keys.join(", ")}'." unless @locales.key?(locale)
|
73
|
+
raise ArgumentError, "Locale was not found: '#{locale}' in '#{@locales.keys.join(", ")}'." unless @locales.key?(locale)
|
75
74
|
|
76
75
|
if !@locales[locale].key?(str)
|
77
76
|
translated_str = str.to_s
|
@@ -90,6 +89,10 @@ class GettextSimple
|
|
90
89
|
return translated_str
|
91
90
|
end
|
92
91
|
|
92
|
+
def locale_exists?(locale)
|
93
|
+
@locales.key?(locale)
|
94
|
+
end
|
95
|
+
|
93
96
|
def translate(str, replaces = nil)
|
94
97
|
if @i18n
|
95
98
|
locale = I18n.locale.to_s
|
@@ -163,7 +166,7 @@ private
|
|
163
166
|
end
|
164
167
|
|
165
168
|
def add_translation(locale, key, val)
|
166
|
-
raise "No such language: '#{locale}'." unless @locales.key?(locale)
|
169
|
+
raise ArgumentError, "No such language: '#{locale}'." unless @locales.key?(locale)
|
167
170
|
|
168
171
|
if !key.to_s.empty? && !val.to_s.empty?
|
169
172
|
debug "Found translation for locale '#{locale}' '#{key}' which is: '#{val}'." if @debug
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|