gettext_activerecord 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +55 -0
- data/ChangeLog +4 -0
- data/README.rdoc +172 -0
- data/Rakefile +110 -0
- data/data/locale/bg/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/bs/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/ca/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/de/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/el/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/es/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/et/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/hr/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/hu/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/it/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/lv/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/nb/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/ua/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/vi/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/gettext_activerecord.mo +0 -0
- data/lib/gettext_activerecord/base.rb +66 -0
- data/lib/gettext_activerecord/i18n.rb +27 -0
- data/lib/gettext_activerecord/migration.rb +16 -0
- data/lib/gettext_activerecord/parser.rb +216 -0
- data/lib/gettext_activerecord/schema_definitions.rb +28 -0
- data/lib/gettext_activerecord/tools.rb +25 -0
- data/lib/gettext_activerecord/validations.rb +189 -0
- data/lib/gettext_activerecord/version.rb +12 -0
- data/lib/gettext_activerecord.rb +19 -0
- data/po/bg/gettext_activerecord.po +115 -0
- data/po/bs/gettext_activerecord.po +125 -0
- data/po/ca/gettext_activerecord.po +116 -0
- data/po/cs/gettext_activerecord.po +124 -0
- data/po/de/gettext_activerecord.po +117 -0
- data/po/el/gettext_activerecord.po +115 -0
- data/po/eo/gettext_activerecord.po +116 -0
- data/po/es/gettext_activerecord.po +116 -0
- data/po/et/gettext_activerecord.po +116 -0
- data/po/fr/gettext_activerecord.po +118 -0
- data/po/gettext_activerecord.pot +113 -0
- data/po/hr/gettext_activerecord.po +125 -0
- data/po/hu/gettext_activerecord.po +116 -0
- data/po/it/gettext_activerecord.po +122 -0
- data/po/ja/gettext_activerecord.po +116 -0
- data/po/ko/gettext_activerecord.po +123 -0
- data/po/lv/gettext_activerecord.po +116 -0
- data/po/nb/gettext_activerecord.po +117 -0
- data/po/nl/gettext_activerecord.po +123 -0
- data/po/pt_BR/gettext_activerecord.po +117 -0
- data/po/ru/gettext_activerecord.po +117 -0
- data/po/sr/gettext_activerecord.po +117 -0
- data/po/test.rb +8 -0
- data/po/ua/gettext_activerecord.po +120 -0
- data/po/vi/gettext_activerecord.po +116 -0
- data/po/zh/gettext_activerecord.po +119 -0
- data/po/zh_TW/gettext_activerecord.po +119 -0
- data/replace.rb +21 -0
- data/sample/README.rdoc +9 -0
- data/sample/Rakefile +32 -0
- data/sample/book.rb +3 -0
- data/sample/config/database.yml +3 -0
- data/sample/data/locale/ja/LC_MESSAGES/sample_ar.mo +0 -0
- data/sample/db/development.sqlite3 +0 -0
- data/sample/db/schema.rb +5 -0
- data/sample/locale/ja/LC_MESSAGES/sample_ar.mo +0 -0
- data/sample/po/ja/sample_ar.po +29 -0
- data/sample/po/sample_ar.pot +29 -0
- data/sample/sample.rb +22 -0
- data/test/Rakefile +43 -0
- data/test/db/migrate.rb +41 -0
- data/test/db/sqlite.rb +8 -0
- data/test/helper.rb +38 -0
- data/test/locale/ja/LC_MESSAGES/active_record.mo +0 -0
- data/test/models/book.rb +3 -0
- data/test/models/developer.rb +5 -0
- data/test/models/inept_wizard.rb +3 -0
- data/test/models/reply.rb +40 -0
- data/test/models/topic.rb +68 -0
- data/test/models/user.rb +3 -0
- data/test/models/wizard.rb +5 -0
- data/test/po/active_record.pot +388 -0
- data/test/po/ja/active_record.po +387 -0
- data/test/test_parser.rb +95 -0
- data/test/test_validations.rb +2575 -0
- data/test/vendor/repair_helper.rb +50 -0
- data/test.rb +2 -0
- metadata +268 -0
data/sample/db/schema.rb
ADDED
Binary file
|
@@ -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
|
data/test/db/migrate.rb
ADDED
@@ -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
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
|
+
|
Binary file
|
data/test/models/book.rb
ADDED
@@ -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
|
data/test/models/user.rb
ADDED