ri18n 0.0.3 → 0.0.4
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.
- data/lib/gettext.rb +4 -4
- data/lib/ri18n/catalog.rb +12 -7
- data/lib/ri18n/msg.rb +7 -2
- data/lib/ri18n/po.rb +24 -1
- data/lib/ri18n/translators.rb +11 -0
- metadata +57 -40
data/lib/gettext.rb
CHANGED
@@ -7,10 +7,10 @@ require 'rake'
|
|
7
7
|
require 'rake/tasklib'
|
8
8
|
|
9
9
|
class GettextScanner < String
|
10
|
-
SINGLE = "'(
|
11
|
-
DOUBLE = '"(
|
12
|
-
MSG_PATTERN_SINGLE = /\
|
13
|
-
MSG_PATTERN_DOUBLE = /\
|
10
|
+
SINGLE = "'((?:[^\\\\]|(?:\\\\'))+?)'"
|
11
|
+
DOUBLE = '"((?:[^\\\\]|(?:\\\\"))+?)"'
|
12
|
+
MSG_PATTERN_SINGLE = /\W(?:s_|N_|_|_i)\(#{SINGLE}\)/mu
|
13
|
+
MSG_PATTERN_DOUBLE = /\W(?:s_|N_|_|_i)\(#{DOUBLE}\)/mu
|
14
14
|
MSG_PATTERN_PLURAL = /\Wn_\(#{SINGLE},\s*#{SINGLE},\s*.+?\)/mu
|
15
15
|
def GettextScanner::Gettext(source)
|
16
16
|
GettextScanner.new(source).gettext
|
data/lib/ri18n/catalog.rb
CHANGED
@@ -11,7 +11,15 @@ class Catalog < Hash
|
|
11
11
|
@lang=lang
|
12
12
|
end
|
13
13
|
|
14
|
-
#
|
14
|
+
# creates a catalog with untranslated msgstr
|
15
|
+
# lang is l, needed for plural forms (nplural depends on lang)
|
16
|
+
def Catalog.new_from_msgidlist(l, new_msg)
|
17
|
+
c = Catalog.new(l)
|
18
|
+
new_msg.each{|m| c[m] = Msg.new_untranslated(nil, m.id_plural, c.nplural)}
|
19
|
+
c
|
20
|
+
end
|
21
|
+
|
22
|
+
# in PO, header is defined as empty msgid
|
15
23
|
def header
|
16
24
|
self[""]
|
17
25
|
end
|
@@ -25,7 +33,7 @@ class Catalog < Hash
|
|
25
33
|
header[:comments]
|
26
34
|
end
|
27
35
|
|
28
|
-
|
36
|
+
# returns the formated PO header
|
29
37
|
def po_header(app_enc)
|
30
38
|
if header
|
31
39
|
ret = header_comments ? header_comments.dup.strip + "\n" : ''
|
@@ -78,12 +86,9 @@ msgstr ""
|
|
78
86
|
|
79
87
|
# update the catalog with the new_msg messages
|
80
88
|
def update(new_msg)
|
81
|
-
new_ids =
|
82
|
-
empty_plurals = []
|
83
|
-
nplural.times do empty_plurals << "" end
|
84
|
-
new_msg.each{|m| new_ids[m] = Msg.new("", nil, m.id_plural, empty_plurals )}
|
89
|
+
new_ids = Catalog.new_from_msgidlist(@lang, new_msg)
|
85
90
|
new_msg.each{|m| self[m] = new_ids[m] unless self.has_key?(m)}
|
86
91
|
end
|
87
|
-
|
92
|
+
|
88
93
|
end
|
89
94
|
|
data/lib/ri18n/msg.rb
CHANGED
@@ -12,17 +12,22 @@ class Msg < String
|
|
12
12
|
msg = Msg.new(str, com)
|
13
13
|
[id, msg]
|
14
14
|
else
|
15
|
-
[id, Msg::
|
15
|
+
[id, Msg::ParsePlurals(str, com)]
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
MSGSTR_PLURAL_RE = /(.+?)(msgstr\[\d+\]\s+.+?)+/m
|
20
|
-
def Msg::
|
20
|
+
def Msg::ParsePlurals(entry, com)
|
21
21
|
all, idp, pl = *(MSGSTR_PLURAL_RE.match(entry))
|
22
22
|
plurals = pl.strip.split(/msgstr\[\d+\]/).collect!{|mp| mp.strip_q}.compact
|
23
23
|
Msg.new(plurals[0], com, idp.strip_q, plurals)
|
24
24
|
end
|
25
25
|
|
26
|
+
# build a new untranslated msgstr
|
27
|
+
def Msg::new_untranslated(comments, id_plural, nplural)
|
28
|
+
Msg.new("", comments, id_plural, Array.new(nplural, "") )
|
29
|
+
end
|
30
|
+
|
26
31
|
def initialize(msg, comments, idp=nil, pl=nil)
|
27
32
|
super(msg)
|
28
33
|
@comments = comments
|
data/lib/ri18n/po.rb
CHANGED
@@ -54,6 +54,29 @@ class PoSource < String
|
|
54
54
|
|
55
55
|
private
|
56
56
|
def set_entries
|
57
|
-
|
57
|
+
|
58
|
+
newFile = [""]
|
59
|
+
|
60
|
+
self.each_line do |line|
|
61
|
+
if line.chomp.strip == ""
|
62
|
+
if newFile.last[-2] != '"'[0] and newFile.last != ""
|
63
|
+
newFile[-1] = newFile[-1].to_s + line
|
64
|
+
else
|
65
|
+
if newFile.last != ""
|
66
|
+
newFile[-1] = newFile[-1].chomp
|
67
|
+
newFile.push("")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
else
|
71
|
+
newFile[-1] = newFile[-1].to_s + line
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if newFile.last == ""
|
76
|
+
newFile.delete_at(-1)
|
77
|
+
end
|
78
|
+
|
79
|
+
@entries = newFile
|
58
80
|
end
|
81
|
+
|
59
82
|
end
|
data/lib/ri18n/translators.rb
CHANGED
@@ -8,6 +8,12 @@ def _(string)
|
|
8
8
|
fetch.empty? ? string : fetch
|
9
9
|
end
|
10
10
|
|
11
|
+
def s_(string)
|
12
|
+
fetch = I18nService.instance.table.fetch(string, "")
|
13
|
+
fetch.empty? ? string.split('|').last : fetch
|
14
|
+
end
|
15
|
+
|
16
|
+
|
11
17
|
# Returns the translated +string+ if available; otherwise returns +string+
|
12
18
|
# Does #{} interpolation on the tranlated string
|
13
19
|
def _i(string, caller = self)
|
@@ -30,6 +36,11 @@ def n_(msgid, msgid_plural, n)
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
39
|
+
# the 'noop' translator, better named 'message marker'
|
40
|
+
def N_(msg)
|
41
|
+
msg
|
42
|
+
end
|
43
|
+
|
33
44
|
unless i18n.try_load
|
34
45
|
i18n.table = {}
|
35
46
|
# Default translator used in case where no catalog is loaded.
|
metadata
CHANGED
@@ -1,48 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.10
|
3
|
-
specification_version: 1
|
4
2
|
name: ri18n
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2005-05-01
|
8
|
-
summary: Ruby application internationalization and localization library
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: dmertz at online dot de
|
12
|
-
homepage: http://ri18n.berlios.de/
|
13
|
-
rubyforge_project: ri18n
|
14
|
-
description: Ri18n is an internationalization and localization library for Ruby applications.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
-
|
22
|
-
- ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: 0.0.4
|
26
5
|
platform: ruby
|
27
6
|
authors:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
- lib/ri18n/pohelper.rb
|
40
|
-
- lib/ri18n/newmsglist.rb
|
41
|
-
test_files: []
|
42
|
-
rdoc_options: []
|
43
|
-
extra_rdoc_files: []
|
7
|
+
- Denis Mertz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-06 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: " Ri18n is an internationalization and localization library for Ruby applications.\n"
|
17
|
+
email: dmertz at online dot de
|
44
18
|
executables: []
|
19
|
+
|
45
20
|
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/i18nservice.rb
|
26
|
+
- lib/ri18n/standard_exts.rb
|
27
|
+
- lib/ri18n/pohelper.rb
|
28
|
+
- lib/ri18n/plural_forms.rb
|
29
|
+
- lib/ri18n/po.rb
|
30
|
+
- lib/ri18n/translators.rb
|
31
|
+
- lib/ri18n/msg.rb
|
32
|
+
- lib/ri18n/newmsglist.rb
|
33
|
+
- lib/ri18n/catalog.rb
|
34
|
+
- lib/ri18n/langtools.rb
|
35
|
+
- lib/gettext.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://ri18n.berlios.de/
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
46
57
|
requirements:
|
47
|
-
|
48
|
-
|
58
|
+
- Rake
|
59
|
+
rubyforge_project: ri18n
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Ruby application internationalization and localization library
|
64
|
+
test_files: []
|
65
|
+
|