gettext_activerecord 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/COPYING +55 -0
  2. data/ChangeLog +4 -0
  3. data/README.rdoc +172 -0
  4. data/Rakefile +110 -0
  5. data/data/locale/bg/LC_MESSAGES/gettext_activerecord.mo +0 -0
  6. data/data/locale/bs/LC_MESSAGES/gettext_activerecord.mo +0 -0
  7. data/data/locale/ca/LC_MESSAGES/gettext_activerecord.mo +0 -0
  8. data/data/locale/cs/LC_MESSAGES/gettext_activerecord.mo +0 -0
  9. data/data/locale/de/LC_MESSAGES/gettext_activerecord.mo +0 -0
  10. data/data/locale/el/LC_MESSAGES/gettext_activerecord.mo +0 -0
  11. data/data/locale/eo/LC_MESSAGES/gettext_activerecord.mo +0 -0
  12. data/data/locale/es/LC_MESSAGES/gettext_activerecord.mo +0 -0
  13. data/data/locale/et/LC_MESSAGES/gettext_activerecord.mo +0 -0
  14. data/data/locale/fr/LC_MESSAGES/gettext_activerecord.mo +0 -0
  15. data/data/locale/hr/LC_MESSAGES/gettext_activerecord.mo +0 -0
  16. data/data/locale/hu/LC_MESSAGES/gettext_activerecord.mo +0 -0
  17. data/data/locale/it/LC_MESSAGES/gettext_activerecord.mo +0 -0
  18. data/data/locale/ja/LC_MESSAGES/gettext_activerecord.mo +0 -0
  19. data/data/locale/ko/LC_MESSAGES/gettext_activerecord.mo +0 -0
  20. data/data/locale/lv/LC_MESSAGES/gettext_activerecord.mo +0 -0
  21. data/data/locale/nb/LC_MESSAGES/gettext_activerecord.mo +0 -0
  22. data/data/locale/nl/LC_MESSAGES/gettext_activerecord.mo +0 -0
  23. data/data/locale/pt_BR/LC_MESSAGES/gettext_activerecord.mo +0 -0
  24. data/data/locale/ru/LC_MESSAGES/gettext_activerecord.mo +0 -0
  25. data/data/locale/sr/LC_MESSAGES/gettext_activerecord.mo +0 -0
  26. data/data/locale/ua/LC_MESSAGES/gettext_activerecord.mo +0 -0
  27. data/data/locale/vi/LC_MESSAGES/gettext_activerecord.mo +0 -0
  28. data/data/locale/zh/LC_MESSAGES/gettext_activerecord.mo +0 -0
  29. data/data/locale/zh_TW/LC_MESSAGES/gettext_activerecord.mo +0 -0
  30. data/lib/gettext_activerecord/base.rb +66 -0
  31. data/lib/gettext_activerecord/i18n.rb +27 -0
  32. data/lib/gettext_activerecord/migration.rb +16 -0
  33. data/lib/gettext_activerecord/parser.rb +216 -0
  34. data/lib/gettext_activerecord/schema_definitions.rb +28 -0
  35. data/lib/gettext_activerecord/tools.rb +25 -0
  36. data/lib/gettext_activerecord/validations.rb +189 -0
  37. data/lib/gettext_activerecord/version.rb +12 -0
  38. data/lib/gettext_activerecord.rb +19 -0
  39. data/po/bg/gettext_activerecord.po +115 -0
  40. data/po/bs/gettext_activerecord.po +125 -0
  41. data/po/ca/gettext_activerecord.po +116 -0
  42. data/po/cs/gettext_activerecord.po +124 -0
  43. data/po/de/gettext_activerecord.po +117 -0
  44. data/po/el/gettext_activerecord.po +115 -0
  45. data/po/eo/gettext_activerecord.po +116 -0
  46. data/po/es/gettext_activerecord.po +116 -0
  47. data/po/et/gettext_activerecord.po +116 -0
  48. data/po/fr/gettext_activerecord.po +118 -0
  49. data/po/gettext_activerecord.pot +113 -0
  50. data/po/hr/gettext_activerecord.po +125 -0
  51. data/po/hu/gettext_activerecord.po +116 -0
  52. data/po/it/gettext_activerecord.po +122 -0
  53. data/po/ja/gettext_activerecord.po +116 -0
  54. data/po/ko/gettext_activerecord.po +123 -0
  55. data/po/lv/gettext_activerecord.po +116 -0
  56. data/po/nb/gettext_activerecord.po +117 -0
  57. data/po/nl/gettext_activerecord.po +123 -0
  58. data/po/pt_BR/gettext_activerecord.po +117 -0
  59. data/po/ru/gettext_activerecord.po +117 -0
  60. data/po/sr/gettext_activerecord.po +117 -0
  61. data/po/test.rb +8 -0
  62. data/po/ua/gettext_activerecord.po +120 -0
  63. data/po/vi/gettext_activerecord.po +116 -0
  64. data/po/zh/gettext_activerecord.po +119 -0
  65. data/po/zh_TW/gettext_activerecord.po +119 -0
  66. data/replace.rb +21 -0
  67. data/sample/README.rdoc +9 -0
  68. data/sample/Rakefile +32 -0
  69. data/sample/book.rb +3 -0
  70. data/sample/config/database.yml +3 -0
  71. data/sample/data/locale/ja/LC_MESSAGES/sample_ar.mo +0 -0
  72. data/sample/db/development.sqlite3 +0 -0
  73. data/sample/db/schema.rb +5 -0
  74. data/sample/locale/ja/LC_MESSAGES/sample_ar.mo +0 -0
  75. data/sample/po/ja/sample_ar.po +29 -0
  76. data/sample/po/sample_ar.pot +29 -0
  77. data/sample/sample.rb +22 -0
  78. data/test/Rakefile +43 -0
  79. data/test/db/migrate.rb +41 -0
  80. data/test/db/sqlite.rb +8 -0
  81. data/test/helper.rb +38 -0
  82. data/test/locale/ja/LC_MESSAGES/active_record.mo +0 -0
  83. data/test/models/book.rb +3 -0
  84. data/test/models/developer.rb +5 -0
  85. data/test/models/inept_wizard.rb +3 -0
  86. data/test/models/reply.rb +40 -0
  87. data/test/models/topic.rb +68 -0
  88. data/test/models/user.rb +3 -0
  89. data/test/models/wizard.rb +5 -0
  90. data/test/po/active_record.pot +388 -0
  91. data/test/po/ja/active_record.po +387 -0
  92. data/test/test_parser.rb +95 -0
  93. data/test/test_validations.rb +2575 -0
  94. data/test/vendor/repair_helper.rb +50 -0
  95. data/test.rb +2 -0
  96. metadata +268 -0
@@ -0,0 +1,5 @@
1
+ ActiveRecord::Schema.define(:version => 1) do
2
+ create_table :books do |t|
3
+ t.string :title, :author_name
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # Japanese translations for PACKAGE package
2
+ # PACKAGE パッケージに対する英訳.
3
+ # Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER
4
+ # This file is distributed under the same license as the PACKAGE package.
5
+ # Masao Mutoh <mutoh@sowhat.com>, 2009.
6
+ #
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: sample AR 1.0.0\n"
10
+ "POT-Creation-Date: 2009-02-28 02:12+0900\n"
11
+ "PO-Revision-Date: 2009-02-15 22:42+0900\n"
12
+ "Last-Translator: Masao Mutoh <mutoh@sowhat.com>\n"
13
+ "Language-Team: Japanese\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=1; plural=0;\n"
18
+
19
+ #: book.rb:-
20
+ msgid "book"
21
+ msgstr "書籍"
22
+
23
+ #: book.rb:-
24
+ msgid "Book|Title"
25
+ msgstr "タイトル"
26
+
27
+ #: book.rb:-
28
+ msgid "Book|Author name"
29
+ msgstr "著者"
@@ -0,0 +1,29 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: sample AR 1.0.0\n"
10
+ "POT-Creation-Date: 2009-02-28 02:12+0900\n"
11
+ "PO-Revision-Date: 2009-02-15 22:33+0900\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: book.rb:-
20
+ msgid "book"
21
+ msgstr ""
22
+
23
+ #: book.rb:-
24
+ msgid "Book|Title"
25
+ msgstr ""
26
+
27
+ #: book.rb:-
28
+ msgid "Book|Author name"
29
+ msgstr ""
data/sample/sample.rb ADDED
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require 'rubygems'
4
+ require 'gettext'
5
+ require 'gettext_activerecord'
6
+ require 'yaml'
7
+
8
+ require 'book'
9
+
10
+ config = YAML.load(IO.read("config/database.yml"))["development"]
11
+ ActiveRecord::Base.establish_connection(config)
12
+
13
+ GetText.bindtextdomain_to(ActiveRecord, "sample_ar", :path => "locale")
14
+
15
+ GetText.set_locale "ja_JP.UTF-8"
16
+ book = Book.new
17
+ book.title = "Foo"
18
+ book.save
19
+ puts book.errors.full_messages #puts Japanese error message.
20
+
21
+ GetText.set_locale "en"
22
+ puts book.errors.full_messages #puts English error message.
data/test/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+ require 'rubygems'
3
+
4
+ gettext_path = File.join(ENV["GETTEXT_PATH"] || "../../gettext/", "lib")
5
+ $LOAD_PATH.unshift gettext_path
6
+
7
+ task :default => :test
8
+
9
+ desc "Create mo files"
10
+ task :makemo do
11
+ require 'activerecord'
12
+ require 'gettext_activerecord/tools'
13
+ GetText.create_mofiles(:mo_root => "locale")
14
+ end
15
+
16
+ SCHEMA_PATH = File.join(File.dirname(__FILE__), "db")
17
+
18
+ desc "Update pot/po files for ActiveRecord test."
19
+ task :updatepo do
20
+ require 'activerecord'
21
+ require 'db/sqlite'
22
+ require 'db/migrate'
23
+ require 'gettext_activerecord/tools'
24
+ GetText::ActiveRecordParser.init(
25
+ :adapter => "sqlite3",
26
+ :encoding => "utf8",
27
+ :activerecord_classes => ["ActiveRecord::Base", "Reply"],
28
+ :database => ':memory:'
29
+ )
30
+ GetText.update_pofiles("active_record", [
31
+ "models/developer.rb",
32
+ "models/topic.rb",
33
+ "models/reply.rb",
34
+ "test_validations.rb"
35
+ ], "active_record 1.0.0")
36
+ end
37
+
38
+ desc 'Run all tests'
39
+ task :test do
40
+ Dir.glob("test_*.rb").each do |path|
41
+ ruby "-I../lib", "-I#{gettext_path}", "-rubygems", path rescue nil
42
+ end
43
+ end
@@ -0,0 +1,41 @@
1
+ ActiveRecord::Schema.define(:version => 1) do
2
+ create_table :topics do |t|
3
+ t.string :title, :author_name, :author_email_address
4
+ t.datetime :written_on
5
+ t.timestamp :bonus_time
6
+ t.date :last_read
7
+ t.text :content
8
+ t.boolean :approved
9
+ t.integer :replies_count, :default=>0, :null=>false
10
+ t.integer :parent_id
11
+ t.string :type, :limit=>50
12
+ end
13
+
14
+ create_table :developers do |t|
15
+ t.string :name, :limit=>100
16
+ t.integer :salary, :default=>70_000, :null=>false
17
+ t.timestamps
18
+ end
19
+
20
+ create_table :books do |t|
21
+ t.string :title, :limit=>100
22
+ t.integer :price, :default=>70_000, :null=>false
23
+ t.timestamps
24
+ end
25
+
26
+ create_table :users do |t|
27
+ t.string :first_name, :last_name, :limit=>100
28
+ t.timestamps
29
+ end
30
+
31
+ create_table :people do |t|
32
+ t.string :first_name, :limit=>100
33
+ t.integer :lock_version, :null=>false
34
+ t.timestamps
35
+ end
36
+
37
+ create_table :inept_wizards do |t|
38
+ t.string :name,:city,:type, :limit=>100
39
+ t.timestamps
40
+ end
41
+ end
data/test/db/sqlite.rb ADDED
@@ -0,0 +1,8 @@
1
+ #create a connection
2
+ ActiveRecord::Base.configurations = {"test" => {
3
+ :adapter => "sqlite3",
4
+ :database => ":memory:"
5
+ }.with_indifferent_access}
6
+
7
+ ActiveRecord::Base.logger = Logger.new('/dev/null')
8
+ ActiveRecord::Base.establish_connection(:test)
data/test/helper.rb ADDED
@@ -0,0 +1,38 @@
1
+ $KCODE = "UTF8"
2
+ $LOAD_PATH.unshift "."
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '/../lib')
4
+
5
+ require 'rubygems'
6
+ require 'test/unit'
7
+ require 'active_record'
8
+
9
+ # use local gettext or current gettext gem
10
+ begin
11
+ $LOAD_PATH.unshift ENV["GETTEXT_LIB_PATH"] || "../../gettext/lib"
12
+ require 'gettext'
13
+ rescue LoadError
14
+ gem 'gettext', '>=2.0.0'
15
+ require 'gettext'
16
+ end
17
+
18
+ require 'gettext_activerecord'
19
+
20
+ # load database and setup parser
21
+ require 'db/sqlite'
22
+ require 'db/migrate'
23
+
24
+ # do something strange with AR_6657
25
+ AR_TEST_VERSION = /activerecord-([^\/]+)/.match($LOAD_PATH.join)[1]
26
+ if AR_TEST_VERSION > "2.0.0"
27
+ #ticket 6657 on dev.rubyonrails.org require this but it becames removed(?)
28
+ AR_6657 = true
29
+ else
30
+ AR_6657 = false
31
+ end
32
+ puts "The activerecord svn version is #{$1}"
33
+
34
+ # Make with_scope public for tests
35
+ class << ActiveRecord::Base
36
+ public :with_scope, :with_exclusive_scope
37
+ end
38
+
@@ -0,0 +1,3 @@
1
+ class Book < ActiveRecord::Base
2
+ untranslate :title
3
+ end
@@ -0,0 +1,5 @@
1
+ class Developer < ActiveRecord::Base
2
+ N_("Developer|Non existent")
3
+ validates_inclusion_of :salary, :in => 50000..200000
4
+ validates_length_of :name, :within => 3..20
5
+ end
@@ -0,0 +1,3 @@
1
+ class IneptWizard < Wizard #ActiveRecord::Base
2
+ validates_uniqueness_of :city
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'models/topic'
2
+
3
+ class Reply < Topic
4
+ N_("Reply|Topic") # Need to define relation table names explicity
5
+ # if you use it in validations.
6
+
7
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
8
+ has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
9
+
10
+ validate :errors_on_empty_content
11
+ validate_on_create :title_is_wrong_create
12
+
13
+ attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
14
+
15
+ def validate
16
+ errors.add("title", N_("Empty")) unless attribute_present? "title"
17
+ end
18
+
19
+ def errors_on_empty_content
20
+ errors.add("content", N_("Empty")) unless attribute_present? "content"
21
+ end
22
+
23
+ def validate_on_create
24
+ if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
25
+ errors.add("title", N_("is Content Mismatch"))
26
+ end
27
+ end
28
+
29
+ def title_is_wrong_create
30
+ errors.add("title", N_("is Wrong Create")) if attribute_present?("title") && title == "Wrong Create"
31
+ end
32
+
33
+ def validate_on_update
34
+ errors.add("title", N_("is Wrong Update")) if attribute_present?("title") && title == "Wrong Update"
35
+ end
36
+ end
37
+
38
+ class SillyReply < Reply
39
+ belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
40
+ end
@@ -0,0 +1,68 @@
1
+ class Topic < ActiveRecord::Base
2
+ named_scope :base
3
+ named_scope :written_before, lambda { |time|
4
+ { :conditions => ['written_on < ?', time] }
5
+ }
6
+ named_scope :approved, :conditions => {:approved => true}
7
+ named_scope :replied, :conditions => ['replies_count > 0']
8
+ named_scope :anonymous_extension do
9
+ def one
10
+ 1
11
+ end
12
+ end
13
+
14
+ module NamedExtension
15
+ def two
16
+ 2
17
+ end
18
+ end
19
+ module MultipleExtensionOne
20
+ def extension_one
21
+ 1
22
+ end
23
+ end
24
+ module MultipleExtensionTwo
25
+ def extension_two
26
+ 2
27
+ end
28
+ end
29
+ named_scope :named_extension, :extend => NamedExtension
30
+ named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
31
+
32
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
33
+ serialize :content
34
+
35
+ N_("Topic|Terms of service")
36
+ N_("must be abided")
37
+
38
+ before_create :default_written_on
39
+ before_destroy :destroy_children
40
+
41
+ def parent
42
+ Topic.find(parent_id)
43
+ end
44
+
45
+ def topic_id
46
+ id
47
+ end
48
+
49
+ protected
50
+ def approved=(val)
51
+ @custom_approved = val
52
+ write_attribute(:approved, val)
53
+ end
54
+
55
+ def default_written_on
56
+ self.written_on = Time.now unless attribute_present?("written_on")
57
+ end
58
+
59
+ def destroy_children
60
+ self.class.delete_all "parent_id = #{id}"
61
+ end
62
+
63
+ def after_initialize
64
+ if self.new_record?
65
+ self.author_email_address = 'test@test.com'
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ untranslate_all
3
+ end
@@ -0,0 +1,5 @@
1
+ class Wizard < ActiveRecord::Base
2
+ self.abstract_class = true
3
+
4
+ validates_uniqueness_of :name
5
+ end