gettext_simple 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.rdoc → README.md} +5 -5
- data/VERSION +1 -1
- data/gettext_simple.gemspec +5 -4
- data/lib/gettext_simple.rb +53 -7
- data/spec/gettext_simple_spec.rb +33 -2
- data/spec/sample_file.po +136 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb895e7961ef32eac71be8e4028e1e7e36f2a4c
|
4
|
+
data.tar.gz: 3b2c03860b4885c1ac2280bdd11204b5eabaffb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18e7bc4d0eeb9345ff621578cc4dcd6f48ab4fc634e6669337f6c21f592bc426d3e9191ebea0e64b031cee823fd0f2d14cf3a6ac6cfe9d5b8a91345e4f83153a
|
7
|
+
data.tar.gz: 998471cc897a4d57d2db5b0479a848e7ab630c40fef6dd123287471f7461aa94320bf22fd17dfe3d5e9c694e6acca7507624c1d47b685abbe33d2262f0281617
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# GettextSimple
|
2
2
|
|
3
3
|
A very simple implementation of Gettext for Ruby.
|
4
4
|
|
@@ -9,15 +9,15 @@ gettext_simple = GettextSimple.new(:i18n => true)
|
|
9
9
|
gettext_simple.load_dir("#{__dir__}/../../locales_gettext")
|
10
10
|
gettext_simple.register_kernel_methods
|
11
11
|
|
12
|
-
|
12
|
+
puts _("Hello world")
|
13
13
|
```
|
14
14
|
|
15
15
|
Replacements are done this way:
|
16
16
|
```ruby
|
17
|
-
|
17
|
+
puts _("Hello %{name}", :name => "Kasper") #=> "Hello Kasper"
|
18
18
|
```
|
19
19
|
|
20
|
-
|
20
|
+
## Contributing to gettext_simple
|
21
21
|
|
22
22
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
23
23
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
@@ -27,7 +27,7 @@ echo _("Hello %{name}", :name => "Kasper") #=> "Hello Kasper"
|
|
27
27
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
28
28
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
29
29
|
|
30
|
-
|
30
|
+
## Copyright
|
31
31
|
|
32
32
|
Copyright (c) 2014 Kasper Johansen. See LICENSE.txt for
|
33
33
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/gettext_simple.gemspec
CHANGED
@@ -5,16 +5,16 @@
|
|
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.3"
|
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-10"
|
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 = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
@@ -22,13 +22,14 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
24
|
"LICENSE.txt",
|
25
|
-
"README.
|
25
|
+
"README.md",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"gettext_simple.gemspec",
|
29
29
|
"include/kernel_methods.rb",
|
30
30
|
"lib/gettext_simple.rb",
|
31
31
|
"spec/gettext_simple_spec.rb",
|
32
|
+
"spec/sample_file.po",
|
32
33
|
"spec/spec_helper.rb"
|
33
34
|
]
|
34
35
|
s.homepage = "http://github.com/kaspernj/gettext_simple"
|
data/lib/gettext_simple.rb
CHANGED
@@ -101,13 +101,59 @@ class GettextSimple
|
|
101
101
|
private
|
102
102
|
|
103
103
|
def scan_pofile(locale, filepath)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
current_id = nil
|
105
|
+
current_translation = nil
|
106
|
+
|
107
|
+
reading_id = false
|
108
|
+
reading_translation = false
|
108
109
|
|
109
|
-
|
110
|
-
|
110
|
+
File.open(filepath, "r", :encoding => @args[:encoding]) do |fp|
|
111
|
+
fp.each_line do |line|
|
112
|
+
if match = line.match(/^(msgid|msgstr)\s+"(.*)"$/)
|
113
|
+
if match[1] == "msgid"
|
114
|
+
current_id = match[2]
|
115
|
+
reading_id = true
|
116
|
+
elsif match[1] == "msgstr"
|
117
|
+
current_translation = match[2]
|
118
|
+
reading_id = false
|
119
|
+
reading_translation = true
|
120
|
+
else
|
121
|
+
raise "Unknown translation parameter: '#{match[1]}'."
|
122
|
+
end
|
123
|
+
elsif match = line.match(/^"(.*)"$/)
|
124
|
+
if reading_id
|
125
|
+
current_id << match[1]
|
126
|
+
elsif reading_translation
|
127
|
+
current_translation << match[1]
|
128
|
+
else
|
129
|
+
raise "Text given but don't know what to do with it."
|
130
|
+
end
|
131
|
+
elsif line.match(/^(\r|)\n$/)
|
132
|
+
if reading_id
|
133
|
+
reading_id = false
|
134
|
+
elsif reading_translation
|
135
|
+
add_translation(locale, current_id, current_translation)
|
136
|
+
reading_translation = false
|
137
|
+
current_id = nil
|
138
|
+
current_translation = nil
|
139
|
+
end
|
140
|
+
elsif line.start_with?("#")
|
141
|
+
# Line is a comment - ignore.
|
142
|
+
else
|
143
|
+
raise "Couldn't understand line: '#{line}'."
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
add_translation(locale, current_id, current_translation) if reading_translation
|
111
148
|
end
|
149
|
+
|
150
|
+
#cont.scan(/msgid\s+\"(.+)\"(\r|)\nmsgstr\s+\"(.+)\"(\r|)\n(\r|)\n/) do |match|
|
151
|
+
# @locales[locale][match[0]] = match[2].to_s.encode("utf-8")
|
152
|
+
#end
|
153
|
+
end
|
154
|
+
|
155
|
+
def add_translation(locale, key, val)
|
156
|
+
raise "No such language: '#{locale}'." unless @locales.key?(locale)
|
157
|
+
@locales[locale][key] = val
|
112
158
|
end
|
113
|
-
end
|
159
|
+
end
|
data/spec/gettext_simple_spec.rb
CHANGED
@@ -7,9 +7,18 @@ describe "GettextSimple" do
|
|
7
7
|
Dir.mkdir("#{@dir}/da")
|
8
8
|
Dir.mkdir("#{@dir}/da/LC_MESSAGES")
|
9
9
|
|
10
|
-
|
10
|
+
file_path = "#{@dir}/da/LC_MESSAGES/default.po"
|
11
|
+
File.open(file_path, "w") do |fp|
|
11
12
|
fp.puts "msgid \"test %{name}\"\n"
|
12
|
-
fp.puts "msgstr \"test translate %{name}\"\n
|
13
|
+
fp.puts "msgstr \"test translate %{name}\"\n"
|
14
|
+
fp.puts "\n"
|
15
|
+
|
16
|
+
fp.puts "msgid \"\"\n"
|
17
|
+
fp.puts "\"test multiple lines\"\n"
|
18
|
+
fp.puts "msgstr \"\"\n"
|
19
|
+
fp.puts "\"test mange\"\n"
|
20
|
+
fp.puts "\" linjer\"\n"
|
21
|
+
fp.puts "\n"
|
13
22
|
end
|
14
23
|
|
15
24
|
@gs = GettextSimple.new
|
@@ -29,4 +38,26 @@ describe "GettextSimple" do
|
|
29
38
|
|
30
39
|
_("test %{name}", :name => "Kasper").should eq "test translate Kasper"
|
31
40
|
end
|
41
|
+
|
42
|
+
it "can read multiple line values" do
|
43
|
+
@gs.instance_variable_get(:@locales)["da"].keys.should include "test multiple lines"
|
44
|
+
@gs.instance_variable_get(:@locales)["da"]["test multiple lines"].should eq "test mange linjer"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can read a sample file from POEdit" do
|
48
|
+
@gs = GettextSimple.new
|
49
|
+
|
50
|
+
da = {}
|
51
|
+
locales = @gs.instance_variable_get(:@locales)
|
52
|
+
locales[:da] = da
|
53
|
+
|
54
|
+
@gs.__send__(:scan_pofile, :da, "#{File.dirname(__FILE__)}/sample_file.po")
|
55
|
+
|
56
|
+
da["Locale"].should eq "Sprog"
|
57
|
+
|
58
|
+
test_key = "BeachInspectors.com is your online tool for the best beach vacation in Denmark. Find reviews and insider tips for danish beaches and rate your favorite beach."
|
59
|
+
test_value = "BeachInspectors.com er dit online værktøj til den bedste strand ferie i Danmark. Find bedømmelser og insider tips til danske strande og bedøm dine favoritstrande."
|
60
|
+
|
61
|
+
da[test_key].should eq test_value
|
62
|
+
end
|
32
63
|
end
|
data/spec/sample_file.po
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
msgid ""
|
2
|
+
msgstr ""
|
3
|
+
"Project-Id-Version: danish_beaches\n"
|
4
|
+
"POT-Creation-Date: 2014-04-10 11:11+0100\n"
|
5
|
+
"PO-Revision-Date: 2014-04-10 11:11+0100\n"
|
6
|
+
"Last-Translator: Kasper Johansen <k@spernj.org>\n"
|
7
|
+
"Language-Team: Kasper Johansen <k@spernj.org>\n"
|
8
|
+
"Language: da\n"
|
9
|
+
"MIME-Version: 1.0\n"
|
10
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11
|
+
"Content-Transfer-Encoding: 8bit\n"
|
12
|
+
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
|
13
|
+
"X-Poedit-Basepath: ../../../\n"
|
14
|
+
"X-Poedit-SourceCharset: UTF-8\n"
|
15
|
+
"X-Generator: Poedit 1.5.4\n"
|
16
|
+
"X-Poedit-SearchPath-0: app\n"
|
17
|
+
"X-Poedit-SearchPath-1: lib\n"
|
18
|
+
|
19
|
+
#: app/admin/beach.rb:7 app/admin/beach_preference.rb:18
|
20
|
+
#: app/views/beach_preferences/_form.html.erb:51
|
21
|
+
#: app/views/beaches/index.html.erb:9
|
22
|
+
msgid "Name"
|
23
|
+
msgstr "Navn"
|
24
|
+
|
25
|
+
#: app/admin/beach.rb:18
|
26
|
+
msgid "Details"
|
27
|
+
msgstr "Detaljer"
|
28
|
+
|
29
|
+
#: app/admin/beach.rb:24
|
30
|
+
msgid "Preference values"
|
31
|
+
msgstr "Præference værdier"
|
32
|
+
|
33
|
+
#: app/admin/beach.rb:28 app/admin/page.rb:7
|
34
|
+
msgid "Translations"
|
35
|
+
msgstr "Oversættelser"
|
36
|
+
|
37
|
+
#: app/admin/beach.rb:31
|
38
|
+
msgid "Meta description"
|
39
|
+
msgstr "Meta beskrivelse"
|
40
|
+
|
41
|
+
#: app/admin/beach.rb:33 app/admin/beach.rb:59
|
42
|
+
#: app/views/beach_preferences/_form.html.erb:56
|
43
|
+
msgid "Description"
|
44
|
+
msgstr "Beskrivelse"
|
45
|
+
|
46
|
+
#: app/admin/beach.rb:46 app/admin/page.rb:18
|
47
|
+
msgid "Locale"
|
48
|
+
msgstr "Sprog"
|
49
|
+
|
50
|
+
#: app/admin/beach.rb:55
|
51
|
+
msgid "Appetizer"
|
52
|
+
msgstr "Appetitvækker"
|
53
|
+
|
54
|
+
#: app/admin/page.rb:24
|
55
|
+
msgid "Content"
|
56
|
+
msgstr "Indhold"
|
57
|
+
|
58
|
+
#: app/models/beach.rb:29
|
59
|
+
msgid "Beach %s"
|
60
|
+
msgstr "Strand %s"
|
61
|
+
|
62
|
+
#: app/models/beach_preference.rb:7
|
63
|
+
msgid "Boolean"
|
64
|
+
msgstr "Boolean"
|
65
|
+
|
66
|
+
#: app/models/beach_preference.rb:8
|
67
|
+
msgid "Checkbox"
|
68
|
+
msgstr "Checkboks"
|
69
|
+
|
70
|
+
#: app/models/beach_preference.rb:9 app/views/beaches/show.html.erb:345
|
71
|
+
msgid "Stars"
|
72
|
+
msgstr "Stjerner"
|
73
|
+
|
74
|
+
#: app/models/beach_preference.rb:47 app/models/beach_preference.rb:55
|
75
|
+
msgid "Not set"
|
76
|
+
msgstr "Ikke sat"
|
77
|
+
|
78
|
+
#: app/models/beach_preference.rb:48 app/models/beach_preference.rb:56
|
79
|
+
msgid "No"
|
80
|
+
msgstr "Nej"
|
81
|
+
|
82
|
+
#: app/models/beach_preference.rb:49 app/models/beach_preference.rb:57
|
83
|
+
msgid "Yes"
|
84
|
+
msgstr "Ja"
|
85
|
+
|
86
|
+
#: app/models/beach_preference.rb:63
|
87
|
+
msgid "Invalid type: '%s'."
|
88
|
+
msgstr "Ugyldig type: '%s'."
|
89
|
+
|
90
|
+
#: app/models/comment.rb:6
|
91
|
+
msgid "You do not have permission to approve comments."
|
92
|
+
msgstr "Du har ikke rettighed til at godkende kommentarer."
|
93
|
+
|
94
|
+
#: app/models/comment.rb:7
|
95
|
+
msgid "This comment is already approved."
|
96
|
+
msgstr "Denne kommentar er allerede godkendt."
|
97
|
+
|
98
|
+
#: app/controllers/facebook_sessions_controller.rb:20
|
99
|
+
msgid "No Facebook-cookie set."
|
100
|
+
msgstr "Ingen Facebook-cookie var sat."
|
101
|
+
|
102
|
+
#: app/controllers/application_controller.rb:46
|
103
|
+
msgid "Not logged in so no Facebook-token."
|
104
|
+
msgstr "Ikke logget ind så der er ingen Facebook-token."
|
105
|
+
|
106
|
+
#: app/controllers/comments_controller.rb:28
|
107
|
+
msgid "Just wrote a comment for a beach on the BeackFreaks-website!"
|
108
|
+
msgstr ""
|
109
|
+
"Har lige skrevet en kommentar til en strand på BeachFreaks-hjemmesiden!"
|
110
|
+
|
111
|
+
#: app/controllers/comments_controller.rb:29
|
112
|
+
msgid "A picture of Roedbyhavn Beach."
|
113
|
+
msgstr "Et billede af Rødbyhavn Strand."
|
114
|
+
|
115
|
+
#: app/views/pages/show.html.erb:4 app/views/beaches/show.html.erb:283
|
116
|
+
msgid "Administration"
|
117
|
+
msgstr "Administration"
|
118
|
+
|
119
|
+
#: app/views/users/show.html.erb:1
|
120
|
+
msgid "Show user: %s"
|
121
|
+
msgstr "Vis bruger: %s"
|
122
|
+
|
123
|
+
#: app/views/frontpage/index.html.erb:3
|
124
|
+
msgid "BeachInspectors | Tips and reviews for the best beaches in Denmark"
|
125
|
+
msgstr "BeachInspectors | Tips og bedømmelser af de bedste strande i Danmark."
|
126
|
+
|
127
|
+
#: app/views/frontpage/index.html.erb:7
|
128
|
+
#: app/views/layouts/application.html.erb:15
|
129
|
+
msgid ""
|
130
|
+
"BeachInspectors.com is your online tool for the best beach vacation in "
|
131
|
+
"Denmark. Find reviews and insider tips for danish beaches and rate your "
|
132
|
+
"favorite beach."
|
133
|
+
msgstr ""
|
134
|
+
"BeachInspectors.com er dit online værktøj til den bedste strand ferie i "
|
135
|
+
"Danmark. Find bedømmelser og insider tips til danske strande og bedøm dine "
|
136
|
+
"favoritstrande."
|
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.3
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -86,20 +86,21 @@ executables: []
|
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files:
|
88
88
|
- LICENSE.txt
|
89
|
-
- README.
|
89
|
+
- README.md
|
90
90
|
files:
|
91
91
|
- .document
|
92
92
|
- .rspec
|
93
93
|
- Gemfile
|
94
94
|
- Gemfile.lock
|
95
95
|
- LICENSE.txt
|
96
|
-
- README.
|
96
|
+
- README.md
|
97
97
|
- Rakefile
|
98
98
|
- VERSION
|
99
99
|
- gettext_simple.gemspec
|
100
100
|
- include/kernel_methods.rb
|
101
101
|
- lib/gettext_simple.rb
|
102
102
|
- spec/gettext_simple_spec.rb
|
103
|
+
- spec/sample_file.po
|
103
104
|
- spec/spec_helper.rb
|
104
105
|
homepage: http://github.com/kaspernj/gettext_simple
|
105
106
|
licenses:
|