hallelujah-gettext_activerecord 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/COPYING +55 -0
  2. data/ChangeLog +21 -0
  3. data/README.rdoc +175 -0
  4. data/Rakefile +120 -0
  5. data/lib/gettext_activerecord.rb +24 -0
  6. data/lib/gettext_activerecord/base.rb +73 -0
  7. data/lib/gettext_activerecord/i18n.rb +27 -0
  8. data/lib/gettext_activerecord/migration.rb +16 -0
  9. data/lib/gettext_activerecord/parser.rb +215 -0
  10. data/lib/gettext_activerecord/schema_definitions.rb +28 -0
  11. data/lib/gettext_activerecord/tools.rb +30 -0
  12. data/lib/gettext_activerecord/validations.rb +191 -0
  13. data/lib/gettext_activerecord/version.rb +12 -0
  14. data/po/bg/gettext_activerecord.po +115 -0
  15. data/po/bs/gettext_activerecord.po +125 -0
  16. data/po/ca/gettext_activerecord.po +116 -0
  17. data/po/cs/gettext_activerecord.po +124 -0
  18. data/po/de/gettext_activerecord.po +117 -0
  19. data/po/el/gettext_activerecord.po +115 -0
  20. data/po/eo/gettext_activerecord.po +116 -0
  21. data/po/es/gettext_activerecord.po +116 -0
  22. data/po/et/gettext_activerecord.po +116 -0
  23. data/po/fr/gettext_activerecord.po +118 -0
  24. data/po/gettext_activerecord.pot +113 -0
  25. data/po/hr/gettext_activerecord.po +125 -0
  26. data/po/hu/gettext_activerecord.po +116 -0
  27. data/po/it/gettext_activerecord.po +122 -0
  28. data/po/ja/gettext_activerecord.po +116 -0
  29. data/po/ko/gettext_activerecord.po +123 -0
  30. data/po/lv/gettext_activerecord.po +116 -0
  31. data/po/nb/gettext_activerecord.po +117 -0
  32. data/po/nl/gettext_activerecord.po +117 -0
  33. data/po/pt_BR/gettext_activerecord.po +117 -0
  34. data/po/ru/gettext_activerecord.po +117 -0
  35. data/po/sr/gettext_activerecord.po +117 -0
  36. data/po/ua/gettext_activerecord.po +120 -0
  37. data/po/vi/gettext_activerecord.po +116 -0
  38. data/po/zh/gettext_activerecord.po +119 -0
  39. data/po/zh_TW/gettext_activerecord.po +119 -0
  40. data/sample/README.rdoc +9 -0
  41. data/sample/Rakefile +32 -0
  42. data/sample/book.rb +3 -0
  43. data/sample/config/database.yml +3 -0
  44. data/sample/db/schema.rb +5 -0
  45. data/sample/po/ja/sample_ar.po +29 -0
  46. data/sample/po/sample_ar.pot +29 -0
  47. data/sample/sample.rb +22 -0
  48. metadata +119 -0
data/COPYING ADDED
@@ -0,0 +1,55 @@
1
+ You can redistribute this program and/or modify it under either the terms of
2
+ the LGPL (see the file LGPL), or the conditions below:
3
+
4
+ 1. You may make and give away verbatim copies of the source form of the
5
+ software without restriction, provided that you duplicate all of the
6
+ original copyright notices and associated disclaimers.
7
+
8
+ 2. You may modify your copy of the software in any way, provided that
9
+ you do at least ONE of the following:
10
+
11
+ a) place your modifications in the Public Domain or otherwise
12
+ make them Freely Available, such as by posting said
13
+ modifications to Usenet or an equivalent medium, or by allowing
14
+ the author to include your modifications in the software.
15
+
16
+ b) use the modified software only within your corporation or
17
+ organization.
18
+
19
+ c) rename any non-standard executables so the names do not conflict
20
+ with standard executables, which must also be provided.
21
+
22
+ d) make other distribution arrangements with the author.
23
+
24
+ 3. You may distribute the software in object code or executable
25
+ form, provided that you do at least ONE of the following:
26
+
27
+ a) distribute the executables and library files of the software,
28
+ together with instructions (in the manual page or equivalent)
29
+ on where to get the original distribution.
30
+
31
+ b) accompany the distribution with the machine-readable source of
32
+ the software.
33
+
34
+ c) give non-standard executables non-standard names, with
35
+ instructions on where to get the original software distribution.
36
+
37
+ d) make other distribution arrangements with the author.
38
+
39
+ 4. You may modify and include the part of the software into any other
40
+ software (possibly commercial). But some files in the distribution
41
+ are not written by the author, so that they are not under these terms.
42
+
43
+ For the list of those files and their copying conditions, see the
44
+ file LEGAL.
45
+
46
+ 5. The scripts and library files supplied as input to or produced as
47
+ output from the software do not automatically fall under the
48
+ copyright of the software, but belong to whomever generated them,
49
+ and may be sold commercially, and may be aggregated with this
50
+ software.
51
+
52
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
53
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
54
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55
+ PURPOSE.
@@ -0,0 +1,21 @@
1
+ = gettext_activerecord-2.0.4 (2009-05-23)
2
+ * Updated version/dependencies.
3
+
4
+ = gettext_activerecord-2.0.3 (2009-05-09)
5
+ * Fixed the dependencies. [Reported by Hans de Graaff]
6
+ * Add the test task to Rakefile.
7
+
8
+ = gettext_activerecord-2.0.2 (2009-05-07)
9
+
10
+ * Update version.
11
+ * Update Dutch translation [by Bart ten Brinke]
12
+ * Enhance ruby-1.9.1 support.
13
+
14
+ = gettext_activerecord-2.0.1 (2009-04-18)
15
+
16
+ * parser.rb: skip anonymous classes by TieTew.
17
+
18
+ = gettext_activerecord-2.0.0 (2009-03-22)
19
+
20
+ * Separated from Ruby-GetText-Package-1.93.0.
21
+ * Support activerecord-2.3.2.
@@ -0,0 +1,175 @@
1
+ = gettext_activerecord
2
+
3
+ gettext_activerecord provides the localization for ActiveRecord-2.2 or later
4
+ using Ruby-GetText-Package.
5
+
6
+ * Validation messages translation
7
+ * Model translation
8
+ * extract messages from models with the rake task.
9
+
10
+ == Website
11
+ * homepage[http://www.yotabanana.com/hiki/ruby-gettext.html]
12
+ * on rubyforge[http://gettext/rubyforge.org/]
13
+ * on github[http://github.com/gettext_activerecord/]
14
+
15
+ == Requirements
16
+ * {Ruby 1.8.3 or later}[http://www.ruby-lang.org]
17
+ * {Rubygems}[http://www.rubygems.org/]
18
+ * {locale gem}[http://rubyforge.org/projects/locale/]
19
+ * $ gem install locale
20
+ * {gettext gem}[http://rubyforge.org/projects/gettext/]
21
+ * $ gem install gettext
22
+
23
+ == Install
24
+ #Uninstall old gettext if exists.
25
+ (sudo/su on POSIX system)
26
+ gem uninstall gettext
27
+
28
+ #from github (edge/unstable)
29
+ (sudo/su on POSIX system)
30
+ gem install locale
31
+ gem install mutoh-gettext -s http://gems.github.com/
32
+
33
+ #from rubyforge (stable)
34
+ (sudo/su on POSIX system)
35
+ gem install locale
36
+ gem install gettext
37
+
38
+ == Usage
39
+ === without Rails
40
+ ==== Rakefile
41
+ require 'rubygems'
42
+
43
+ desc "Create mo files"
44
+ task :makemo do
45
+ require 'gettext_activerecord/tools'
46
+ GetText.create_mofiles
47
+ end
48
+
49
+ task :updatepo do
50
+ require 'gettext_activerecord/tools'
51
+ # Need to access DB to find Model table/column names.
52
+ # Use config/database.yml which is the same style with rails.
53
+ GetText.update_pofiles("sample_ar", ["topic.rb"], "sample AR 1.0.0")
54
+ end
55
+
56
+ ==== topic.rb
57
+ class Topic < ActiveRecord::Base
58
+ validates_length_of :title, :minimum => 10
59
+ end
60
+
61
+ ==== sample.rb
62
+ require 'gettext_activerecord'
63
+ require 'topic'
64
+
65
+ # Use config/database.yml which is the same style with rails.
66
+ config = YAML.load(IO.read("config/database.yml"))["development"]
67
+ ActiveRecord::Base.establish_connection(config)
68
+
69
+ GetText.bindtextdomain_to(ActiveRecord, "sample_ar", :path => "locale")
70
+
71
+ GetText.set_locale "ja_JP.UTF-8"
72
+ a = Topic.new
73
+ a.title = "Foo"
74
+ a.save
75
+ puts a.errors.full_messages #puts Japanese error message.
76
+
77
+ ==== Then ...
78
+ $ rake updatepo
79
+ $ cd po
80
+ $ mkdir ja
81
+ $ msginit -l ja_JP.UTF-8 -i sample_ar.pot -o ja/sample_ar.po
82
+ $ Edit ja/sample_ar.po
83
+ $ cd ../../
84
+ $ rake makemo
85
+ $ ruby sample.rb
86
+
87
+ === with Rails
88
+ See gettext_rails [http://github.com/mutoh/gettext_rails/tree/master]
89
+
90
+ == Support matrix
91
+ * gettext_activerecord-2.0.2 - rails-2.3.2
92
+ * gettext_activerecord-2.0.1 - rails-2.3.2
93
+ * gettext_activerecord-2.0.0 - rails-2.3.2
94
+
95
+ == License
96
+ This program is licenced under the same licence as Ruby.
97
+ (See the file 'COPYING'.)
98
+
99
+ * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
100
+ == Translators
101
+ * Bosnian(bs) - Sanjin Sehic <saserr at gmail.com>
102
+ * Bulgarian(bg) - Sava Chankov <sava.chankov at gmail.com>
103
+ * Catalan(ca) - Ramon Salvadó <rsalvado at gnuine.com>
104
+ * Chinese(Simplified)(zh_CN)
105
+ * Yang Bob <bob.yang.dev at gmail.com> (current)
106
+ * Yingfeng <blogyingfeng at gmail.com>
107
+ * Chinese(Traditional)(zh_TW)
108
+ * Yang Bob <bob.yang.dev at gmail.com> (current)
109
+ * LIN CHUNG-YI <xmarsh at gmail.com>
110
+ * Croatian(hr) - Sanjin Sehic <saserr at gmail.com>
111
+ * Czech(cs) - Karel Miarka <kajism at yahoo.com>
112
+ * Dutch(nl) - Bart ten Brinke <info at retrosync.com> (current)
113
+ Menno Jonkers <ruby-gettext at jonkers.com>
114
+ * Esperanto(eo) - Malte Milatz <malte at gmx-topmail.de>
115
+ * Estonian(et) - Erkki Eilonen <erkki at itech.ee>
116
+ * French(fr)
117
+ * Vincent Isambart <vincent.isambart at gmail.com> (current)
118
+ * David Sulc <davidsulc at gmail.com>
119
+ * David Sulc <davidsulc at gmail.com>
120
+ * Laurent Sansonetti <laurent.sansonetti at gmail.com>
121
+ * German(de)
122
+ * Patrick Lenz <patrick at limited-overload.de> (current)
123
+ * Detlef Reichl <detlef.reichl at gmx.org>
124
+ * Sven Herzberg <herzi at abi02.de>
125
+ * Sascha Ebach <se at digitale-wertschoepfung.de>
126
+ * Greek(el) - Vassilis Rizopoulos <damphyr at gmx.net>
127
+ * Hungarian(hu) - Tamás Tompa <tompata at gmail.com>
128
+ * Italian(it)
129
+ * Marco Lazzeri <marco.lazzeri at gmail.com>
130
+ * Gabriele Renzi <surrender_it at yahoo.it>
131
+ * Japanese(ja) - Masao Mutoh <mutomasa at gmail.com>
132
+ * Korean(ko) - Gyoung-Yoon Noh <nohmad at gmail.com>
133
+ * Latvian(lv) - Aivars Akots <aivars.akots at gmail.com>
134
+ * Norwegian(nb) - Runar Ingebrigtsen <runar at mopo.no>
135
+ * Portuguese(Brazil)(pt_BR)
136
+ * Antonio S. de A. Terceiro <terceiro at softwarelivre.org> (current)
137
+ * Joao Pedrosa <joaopedrosa at gmail.com>
138
+ * Russian(ru) - Yuri Kozlov <kozlov.y at gmail.com>
139
+ * Serbian(sr) - Slobodan Paunović" <slobodan.paunovic at gmail.com>
140
+ * Spanish(es)
141
+ * David Espada <davinci at escomposlinux.org> (current)
142
+ * David Moreno Garza <damog at damog.net>
143
+ * Ukrainian(ua) - Alex Rootoff <rootoff at pisem.net>
144
+ * Vietnamese(vi) - Ngoc Dao Thanh <ngocdaothanh at gmail.com>
145
+
146
+ == Status of translations
147
+ * Bosnian(bs) - 1.90.0 (old)
148
+ * Bulgarian(bg) - 2.0.0
149
+ * Catalan(ca) - 2.0.0
150
+ * Croatian(hr) - 1.90.0 (old)
151
+ * Chinese(zh_CN) - 2.0.0
152
+ * Chinese(zh_TW) - 2.0.0
153
+ * Czech(cs) - 1.9.0 (old)
154
+ * Dutch(nl) - 2.0.2
155
+ * English(default) - 1.90.0 (old)
156
+ * Esperanto(eo) - 2.0.0
157
+ * Estonian(et) - 2.0.0
158
+ * French(fr) - 2.0.0
159
+ * German(de) - 2.0.0
160
+ * Greek(el) - 2.0.0
161
+ * Hungarian(hu) - 2.0.0
162
+ * Italian(it) - 1.6.0 (old)
163
+ * Japanese(ja) - 2.0.2
164
+ * Korean(ko) - 1.9.0 (old)
165
+ * Latvian(lv) - 2.0.0
166
+ * Norwegian(nb) - 2.0.0
167
+ * Portuguese(Brazil)(pt_BR) - 2.0.0
168
+ * Russian(ru) - 2.0.0
169
+ * Serbian(sr) - 1.91.0 (old)
170
+ * Spanish(es) - 2.0.0
171
+ * Ukrainian(ua) - 2.0.0
172
+ * Vietnamese(vi) - 2.0.0
173
+
174
+ == Maintainer
175
+ Masao Mutoh <mutomasa at gmail.com>
@@ -0,0 +1,120 @@
1
+ #
2
+ # Rakefile for gettext_activerecord.
3
+ #
4
+ # Use setup.rb or gem for installation.
5
+ # You don't need to use this file directly.
6
+ #
7
+ # Copyright(c) 2009 Masao Mutoh
8
+ #
9
+ # This program is licenced under the same licence as Ruby.
10
+ #
11
+
12
+ #make lib and paralel gettext checkout available
13
+ $LOAD_PATH.unshift "./lib"
14
+ gettext_path = File.join(ENV["GETTEXT_PATH"] || "../gettext/", "lib")
15
+ $LOAD_PATH.unshift gettext_path
16
+
17
+ require 'rubygems'
18
+ require 'rake'
19
+ require 'rake/packagetask'
20
+ require 'rake/gempackagetask'
21
+ require 'rake/rdoctask'
22
+
23
+ gettext_path = File.join(ENV["GETTEXT_PATH"] || "../gettext/", "lib")
24
+ $LOAD_PATH.unshift gettext_path
25
+
26
+ require 'gettext_activerecord/version'
27
+
28
+ PKG_VERSION = GetTextActiveRecord::VERSION
29
+
30
+ task :default => [:makemo]
31
+
32
+ ############################################################
33
+ # Manage po/mo files
34
+ ############################################################
35
+ desc "Create *.mo from *.po"
36
+ task :makemo do
37
+ $stderr.puts "Create active_record mo files."
38
+ require 'gettext/tools'
39
+ GetText.create_mofiles
40
+ end
41
+
42
+ desc "Update pot/po files to match new version."
43
+ task :updatepo do
44
+ require 'gettext/tools'
45
+
46
+ GetText.update_pofiles("gettext_activerecord",
47
+ Dir.glob("lib/**/*.rb"),
48
+ "gettext_activerecord #{PKG_VERSION}")
49
+
50
+ end
51
+
52
+ ############################################################
53
+ # Package tasks
54
+ ############################################################
55
+
56
+ desc "Create gem and tar.gz"
57
+ spec = Gem::Specification.new do |s|
58
+ s.name = 'gettext_activerecord'
59
+ s.version = PKG_VERSION
60
+ s.summary = 'Localization support for ActiveRecord by Ruby-GetText-Package.'
61
+ s.author = 'Masao Mutoh'
62
+ s.email = 'mutomasa at gmail.com'
63
+ s.homepage = 'http://gettext.rubyforge.org/'
64
+ s.rubyforge_project = "gettext"
65
+ s.files = FileList['**/*'].to_a.select{|v| v !~ /pkg|git/}
66
+ s.require_path = 'lib'
67
+ s.add_dependency('gettext', '>= 2.0.4')
68
+ s.add_dependency('activerecord', '>= 2.3.2')
69
+ s.has_rdoc = true
70
+ s.description = 'Localization support for ActiveRecord by Ruby-GetText-Package.'
71
+ end
72
+
73
+ Rake::PackageTask.new("gettext_activerecord", PKG_VERSION) do |o|
74
+ o.package_files = FileList['**/*'].to_a.select{|v| v !~ /pkg|git/}
75
+ o.need_tar_gz = true
76
+ o.need_zip = false
77
+ end
78
+
79
+ Rake::GemPackageTask.new(spec) do |p|
80
+ p.gem_spec = spec
81
+ p.need_tar_gz = false
82
+ p.need_zip = false
83
+ end
84
+
85
+ ############################################################
86
+ # Misc tasks
87
+ ############################################################
88
+
89
+ Rake::RDocTask.new { |rdoc|
90
+ allison = `allison --path`.chop
91
+ rdoc.rdoc_dir = 'doc'
92
+ rdoc.title = "gettext_activerecord API Reference"
93
+ rdoc.options << '--line-numbers' << '--inline-source'
94
+ rdoc.rdoc_files.include('README.rdoc', 'ChangeLog')
95
+ rdoc.rdoc_files.include('lib/**/*.rb')
96
+ rdoc.template = allison if allison.size > 0
97
+ }
98
+
99
+ desc "Publish the release files to RubyForge."
100
+ task :release => [:makemo, :package ] do
101
+ require 'rubyforge'
102
+
103
+ rubyforge = RubyForge.new
104
+ rubyforge.configure
105
+ rubyforge.login
106
+ rubyforge.add_release("gettext", "gettext_activerecord",
107
+ PKG_VERSION,
108
+ "pkg/gettext_activerecord-#{PKG_VERSION}.gem",
109
+ "pkg/gettext_activerecord-#{PKG_VERSION}.tar.gz")
110
+ end
111
+
112
+ # Run the unit tests
113
+ desc 'Run tests'
114
+ task :test do
115
+ cd "test"
116
+ Dir.glob("test_*.rb").each do |v|
117
+ ruby "-Ilib:../../locale/lib:../../gettext/lib #{v}"
118
+ end
119
+ cd ".."
120
+ end
@@ -0,0 +1,24 @@
1
+ =begin
2
+ gettext_activerecord.rb - GetText for ActiveRecord
3
+
4
+ Copyright (C) 2009 Masao Mutoh
5
+
6
+ You may redistribute it and/or modify it under the same
7
+ license terms as Ruby.
8
+
9
+ =end
10
+
11
+ require 'gettext'
12
+ require 'active_record'
13
+ require 'gettext_activerecord/migration'
14
+ require 'gettext_activerecord/schema_definitions'
15
+ require 'gettext_activerecord/validations'
16
+ require 'gettext_activerecord/base'
17
+ require 'gettext_activerecord/i18n'
18
+ require 'gettext_activerecord/version'
19
+
20
+ class Class
21
+ def to_s_with_gettext
22
+ to_s
23
+ end
24
+ end
@@ -0,0 +1,73 @@
1
+ =begin
2
+ lib/gettext_activerecord/base.rb - GetText for ActiveRecord::Base
3
+
4
+ Copyright (C) 2009 Masao Mutoh
5
+
6
+ You may redistribute it and/or modify it under the same
7
+ license terms as Ruby.
8
+
9
+ $Id$
10
+ =end
11
+
12
+ module ActiveRecord #:nodoc:
13
+ class Base
14
+ include GetText
15
+ include Validations
16
+
17
+ @@gettext_untranslate = Hash.new(false)
18
+ @@gettext_untranslate_columns = {}
19
+
20
+ class << self
21
+ # Untranslate all of the tablename/fieldnames in this model class.
22
+ # (e.g.)
23
+ # Person < ActiveRecord::Base
24
+ # untranslate_all
25
+ # end
26
+ def untranslate_all
27
+ @@gettext_untranslate[self] = true
28
+ end
29
+
30
+ # Returns true if "untranslate_all" is called. Otherwise false.
31
+ def untranslate_all?
32
+ @@gettext_untranslate[self]
33
+ end
34
+
35
+ # Sets the untranslate columns.
36
+ # (e.g.)
37
+ # Person < ActiveRecord::Base
38
+ # untranslate :age, :address
39
+ # end
40
+ def untranslate(*w)
41
+ ary = @@gettext_untranslate_columns[self] || []
42
+ ary += w.collect{|v| v.to_s}
43
+ @@gettext_untranslate_columns[self] = ary
44
+ end
45
+
46
+ # Returns true if the column is set "untranslate".
47
+ # (e.g.) untranslate? :foo
48
+ def untranslate?(columnname)
49
+ ary = @@gettext_untranslate_columns[self] || []
50
+ ary.include?(columnname)
51
+ end
52
+
53
+ def untranslate_data #:nodoc:
54
+ [@@gettext_untranslate[self], @@gettext_untranslate_columns[self] || []]
55
+ end
56
+
57
+ def columns_with_gettext_activerecord
58
+ unless defined? @columns
59
+ @columns = nil
60
+ end
61
+ unless @columns
62
+ @columns = columns_without_gettext_activerecord
63
+ @columns.each {|column|
64
+ column.table_class = self
65
+ }
66
+ end
67
+ @columns
68
+ end
69
+ alias_method_chain :columns, :gettext_activerecord
70
+ end
71
+ end
72
+
73
+ end