saLOUt-kdegettext 0.9.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.
Files changed (8) hide show
  1. data/Changelog +1 -0
  2. data/LICENSE +4 -0
  3. data/README +27 -0
  4. data/Rakefile +24 -0
  5. data/VERSION +1 -0
  6. data/bin/kdegettext.rb +205 -0
  7. data/kdegettext.gemspec +57 -0
  8. metadata +100 -0
data/Changelog ADDED
@@ -0,0 +1 @@
1
+ 2009-08-02: v 0.9.0 initial release
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (C) 2009 Robert Riemann
2
+
3
+ You may redistribute it and/or modify it under the same
4
+ license terms as Ruby.
data/README ADDED
@@ -0,0 +1,27 @@
1
+ Acknowledgments:
2
+ * Masao Mutoh ( author of gettext package for ruby)
3
+ - write a parser from the author of gettext: http://www.yotabanana.com/hiki/ruby-gettext-howto-poparser.html
4
+ * Richard Dale ( some helpful links, author of korundum/qtruby package )
5
+ * the author of that piece of code found on http://www.koders.com/ruby/fidA7A93BC839C40D00497E6BB33479BAC9430FE50C.aspx?s="Chris+Wanstrath"#L20
6
+
7
+ Known Bugs:
8
+ * in ruby1.8 the hash (TargetList) is not sorted -> output in po is not sorted for line numbers
9
+ * rgettext -r kdegettext file.rb (with kdegettext.rb $:) only works if
10
+ - ruby version is 1.9
11
+ - the command comes from a new login-console, started via su - user
12
+
13
+ Install:
14
+ * maybe you need first: gem sources -a http://gems.github.com
15
+ * gem install kdegettext
16
+
17
+ Dependencies (should me installed automatically via gem):
18
+ * ruby 1.8: gem install locale gettext ruby_parser sexp_processor
19
+ * ruby 1.9: gem1.9 install locale gettext ruby_parser sexp_processor
20
+
21
+ Possible ways to start this script (kdegettext has to be in $: except in the first 3 ways):
22
+ * ./kdegettext.rb file.rb
23
+ * ruby kdegettext.rb file.rb
24
+ * ruby1.9 kdegettext.rb file.rb
25
+ * ruby1.9 /usr/bin/rgettext -r kdegettext file.rb (only in login-console: > su - user)
26
+ * ruby /usr/lib64/ruby/gems/1.8/gems/gettext-2.0.4/lib/gettext/tools/rgettext.rb -r kdegettext file.rb
27
+ * ruby1.9 /usr/lib64/ruby/gems/1.9.1/gems/gettext-2.0.4/lib/gettext/tools/rgettext.rb -r kdegettext file.rb
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rake'
2
+ require 'git'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |s|
7
+ s.name = %q{kdegettext}
8
+ s.date = %q{2009-08-05}
9
+ s.authors = ["Robert Riemann"]
10
+ s.email = %q{robert.riemann@physik.hu-berlin.de}
11
+ s.summary = %q{KDEgettext.rb is a tool to localize KDE programs implemented in ruby.}
12
+ s.homepage = %q{http://github.com/saLOUt/KDEgettext.rb/}
13
+ s.description = %q{KDEgettext.rb is a parser that extends ruby gettext to work with the Qt/KDE framework provided by korundum. It allows creating catalog files (po-file) with the GNU GetText format.}
14
+ s.add_dependency('gettext', '>= 2.0.4')
15
+ s.add_dependency('locale', '>= 2.0.4')
16
+ s.add_dependency('ruby_parser', '>= 2.0.3')
17
+ s.add_dependency('sexp_processor', '>= 3.0.2')
18
+ s.has_rdoc = false
19
+ end
20
+
21
+ rescue LoadError
22
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
23
+ end
24
+ # kate: syntax ruby
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.0
data/bin/kdegettext.rb ADDED
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env ruby
2
+ =begin
3
+ KDEgettext.rb - parser for ruby scripts using the korundum (KDE) or qtruby (Qt) package
4
+
5
+ Copyright (C) 2009 Robert Riemann
6
+
7
+ You may redistribute it and/or modify it under the same
8
+ license terms as Ruby.
9
+ =end
10
+
11
+ require 'rubygems'
12
+ require 'ruby_parser'
13
+ require 'sexp_processor'
14
+
15
+ class KDERubyProcessor < SexpProcessor
16
+
17
+ private_class_method :new
18
+ @@singleton = nil
19
+
20
+ def self.create(*args)
21
+ @@singleton = new(*args) unless @@singleton
22
+ @@singleton
23
+ end
24
+
25
+ def initialize(api,separator)
26
+ super()
27
+ self.strict = false
28
+ @category = Hash.new {|aHash,aKey| aHash[aKey] = []}
29
+ api.each do |call|
30
+ name = call.shift
31
+ @category[:all] << name
32
+ call.each do |category|
33
+ @category[category] << name
34
+ end
35
+ end
36
+ @separator = separator
37
+ end
38
+
39
+ def targets=(targets)
40
+ @aTargetList = TargetList.import_array targets
41
+ end
42
+
43
+ def targets
44
+ @aTargetList.export_array if @aTargetList
45
+ end
46
+
47
+ def parse_files(files,targets = [])
48
+ self.targets = targets
49
+ files.each do |file|
50
+ self.process(RubyParser.new.parse(File.read(file), file))
51
+ end
52
+ end
53
+
54
+ def check_call(call)
55
+ if @category[:all].include? call[:name]
56
+ msgid = ""
57
+ if @category[:context].include? call[:name]
58
+ msgid << call[:arguments].shift.to_s << @separator[:context]
59
+ end
60
+ msgid << call[:arguments].shift.to_s
61
+ if @category[:plural].include? call[:name]
62
+ msgid << @separator[:plural] << call[:arguments].shift.to_s
63
+ call[:arguments].shift # removes argument after plural string
64
+ end
65
+ @aTargetList.add_target(msgid,call[:file].to_s + ":" + call[:line].to_s)
66
+ end
67
+ end
68
+
69
+ def process_call(exp)
70
+ # receiver is sexp: e.g. s(const, :KDE) or s(:lvar, :myinstance)
71
+ # name is a symbol, receiver is Sexp, arguments is array
72
+ call = { :line => exp.line, :file => exp.file, :receiver => exp[1], :name => exp[2], :arguments => [] }
73
+
74
+ exp[3][1..-1].each do |aSexp| # iterate over arguments
75
+ type,val = *aSexp # type is symbol, val is datatype like string or fixnum
76
+ call[:arguments] << val
77
+ end
78
+
79
+ check_call call
80
+
81
+ # pass through
82
+ begin
83
+ s(:call,
84
+ *(exp.map { |inner| process_inner_expr inner })
85
+ )
86
+ ensure
87
+ exp.clear
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def process_inner_expr(inner)
94
+ inner.kind_of?(Array) ? process(inner) : inner
95
+ end
96
+
97
+ end
98
+
99
+ class TargetList < Hash
100
+
101
+ def self.import_array(targets = [])
102
+ aTargetList = self.new
103
+ targets.each do |aTarget|
104
+ aTargetList[aTarget.shift] = aTarget
105
+ end
106
+ return aTargetList
107
+ end
108
+
109
+ def export_array
110
+ self.map do |msgid,pos|
111
+ [msgid] + pos
112
+ end
113
+ end
114
+
115
+ def add_target(msgid, pos)
116
+ msgid.gsub!(/\n/, '\n') # escape newline: \n -> \\n
117
+ if self.include? msgid
118
+ self[msgid] << pos
119
+ return nil
120
+ else
121
+ self[msgid] = [pos]
122
+ return true
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ module KDERubyParser
129
+
130
+ # Syntax:
131
+ #
132
+ # first element in array: name of the function,
133
+ # after that other symbols defining the properties of the function :
134
+ # * qt : function from Qt or KDE framework
135
+ # * rgt (ruby gettext) : function from ruby gettext
136
+ # * plural : after msgid follows the argument for plural ( msgid_plural) and then a number to compute which form to use
137
+ # * context : before msgid is argument for context (msgctxt)
138
+ # * div : last argument defines a divider string, usually div = "|"
139
+ # actually only context and plural are handled
140
+ API = [
141
+ [:N_, :rgt],
142
+ [:_, :rgt],
143
+ [:gettext, :rgt],
144
+
145
+ [:Nn_, :rgt, :plural], # ! only 2 arguments: singular form, plural form
146
+ [:n_, :rgt, :plural],
147
+
148
+ [:p_, :rgt, :context],
149
+ [:pgettext, :rgt, :context],
150
+
151
+ [:npgettext, :rgt, :context, :plural],
152
+ [:np_, :rgt, :context, :plural],
153
+
154
+ [:s_, :rgt, :div],
155
+ [:sgettext, :rgt, :div],
156
+
157
+ [:ns_, :rgt, :div, :plural],
158
+ [:nsgettext, :rgt, :div, :plural],
159
+
160
+ [:i18n, :qt],
161
+ [:ki18n, :qt],
162
+ [:tr, :qt],
163
+
164
+ [:i18np, :qt, :plural],
165
+ [:ki18np, :qt, :plural],
166
+
167
+ [:i18nc, :qt, :context],
168
+ [:ki18nc, :qt, :context],
169
+
170
+ [:i18ncp, :qt, :context, :plural],
171
+ [:ki18ncp, :qt, :context, :plural],
172
+ ]
173
+
174
+ SEPARATOR = {:plural => "\000", :context => "\004"}
175
+
176
+ extend self
177
+
178
+ def parse(files, targets = []) # :nodoc: # files is string (1 file) or array (more files)
179
+ files = [files] unless files.class == Array
180
+ aKDERubyProcessor = KDERubyProcessor.create(API,SEPARATOR)
181
+ aKDERubyProcessor.parse_files(files,targets)
182
+ aKDERubyProcessor.targets
183
+ end
184
+
185
+ def target?(file) # :nodoc:
186
+ true # always true, as this parser is able to handle also normal ruby files
187
+ end
188
+
189
+ end
190
+
191
+ begin
192
+ require 'gettext/rgettext'
193
+ rescue LoadError
194
+ begin
195
+ require 'gettext/tools/rgettext'
196
+ rescue LoadError
197
+ raise 'Ruby-GetText-Package are not installed.'
198
+ end
199
+ end
200
+
201
+ GetText::RGetText.add_parser(KDERubyParser)
202
+
203
+ if __FILE__ == $0
204
+ GetText.rgettext
205
+ end
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{kdegettext}
8
+ s.version = "0.9.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robert Riemann"]
12
+ s.date = %q{2009-08-05}
13
+ s.default_executable = %q{kdegettext.rb}
14
+ s.description = %q{KDEgettext.rb is a parser that extends ruby gettext to work with the Qt/KDE framework provided by korundum. It allows creating catalog files (po-file) with the GNU GetText format.}
15
+ s.email = %q{robert.riemann@physik.hu-berlin.de}
16
+ s.executables = ["kdegettext.rb"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README"
20
+ ]
21
+ s.files = [
22
+ "Changelog",
23
+ "LICENSE",
24
+ "README",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/kdegettext.rb",
28
+ "kdegettext.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/saLOUt/KDEgettext.rb/}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.1}
34
+ s.summary = %q{KDEgettext.rb is a tool to localize KDE programs implemented in ruby.}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 2
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<gettext>, [">= 2.0.4"])
42
+ s.add_runtime_dependency(%q<locale>, [">= 2.0.4"])
43
+ s.add_runtime_dependency(%q<ruby_parser>, [">= 2.0.3"])
44
+ s.add_runtime_dependency(%q<sexp_processor>, [">= 3.0.2"])
45
+ else
46
+ s.add_dependency(%q<gettext>, [">= 2.0.4"])
47
+ s.add_dependency(%q<locale>, [">= 2.0.4"])
48
+ s.add_dependency(%q<ruby_parser>, [">= 2.0.3"])
49
+ s.add_dependency(%q<sexp_processor>, [">= 3.0.2"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<gettext>, [">= 2.0.4"])
53
+ s.add_dependency(%q<locale>, [">= 2.0.4"])
54
+ s.add_dependency(%q<ruby_parser>, [">= 2.0.3"])
55
+ s.add_dependency(%q<sexp_processor>, [">= 3.0.2"])
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saLOUt-kdegettext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Riemann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-05 00:00:00 -07:00
13
+ default_executable: kdegettext.rb
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gettext
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: locale
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: ruby_parser
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.3
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: sexp_processor
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.2
54
+ version:
55
+ description: KDEgettext.rb is a parser that extends ruby gettext to work with the Qt/KDE framework provided by korundum. It allows creating catalog files (po-file) with the GNU GetText format.
56
+ email: robert.riemann@physik.hu-berlin.de
57
+ executables:
58
+ - kdegettext.rb
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README
64
+ files:
65
+ - Changelog
66
+ - LICENSE
67
+ - README
68
+ - Rakefile
69
+ - VERSION
70
+ - bin/kdegettext.rb
71
+ - kdegettext.gemspec
72
+ has_rdoc: false
73
+ homepage: http://github.com/saLOUt/KDEgettext.rb/
74
+ licenses:
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.5
96
+ signing_key:
97
+ specification_version: 2
98
+ summary: KDEgettext.rb is a tool to localize KDE programs implemented in ruby.
99
+ test_files: []
100
+