forked from sniemela/radiant-globalize2-extension
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jerrod Blavos
committed
May 5, 2010
1 parent
974957b
commit 394649f
Showing
29 changed files
with
1,874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
doc | ||
spec/spec/db/* | ||
vendor | ||
NOTES | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2008, 2009 Joshua Harvey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
h1. Globalize2 | ||
|
||
Globalize2 is the successor of Globalize for Rails. | ||
|
||
It is compatible with and builds on the new "I18n api in Ruby on Rails":http://guides.rubyonrails.org/i18n.html. and adds model translations to ActiveRecord. | ||
|
||
Globalize2 is much more lightweight and compatible than its predecessor was. Model translations in Globalize2 use default ActiveRecord features and do not limit any ActiveRecord functionality any more. | ||
|
||
h2. Requirements | ||
|
||
ActiveRecord | ||
I18n | ||
|
||
(or Rails > 2.2) | ||
|
||
h2. Installation | ||
|
||
To install Globalize2 with its default setup just use: | ||
|
||
<pre><code> | ||
script/plugin install git://github.com/joshmh/globalize2.git | ||
</code></pre> | ||
|
||
h2. Model translations | ||
|
||
Model translations allow you to translate your models' attribute values. E.g. | ||
|
||
<pre><code> | ||
class Post < ActiveRecord::Base | ||
translates :title, :text | ||
end | ||
</code></pre> | ||
|
||
Allows you to values for the attributes :title and :text per locale: | ||
|
||
<pre><code> | ||
I18n.locale = :en | ||
post.title # => Globalize2 rocks! | ||
|
||
I18n.locale = :he | ||
post.title # => גלובאלייז2 שולט! | ||
</code></pre> | ||
|
||
In order to make this work, you'll need to add the appropriate translation tables. Globalize2 comes with a handy helper method to help you do this. It's called @create_translation_table!@. Here's an example: | ||
|
||
<pre><code> | ||
class CreatePosts < ActiveRecord::Migration | ||
def self.up | ||
create_table :posts do |t| | ||
t.timestamps | ||
end | ||
Post.create_translation_table! :title => :string, :text => :text | ||
end | ||
def self.down | ||
drop_table :posts | ||
Post.drop_translation_table! | ||
end | ||
end | ||
</code></pre> | ||
|
||
Note that the ActiveRecord model @Post@ must already exist and have a @translates@ directive listing the translated fields. | ||
|
||
h2. Migration from Globalize | ||
|
||
See this script by Tomasz Stachewicz: http://gist.github.com/120867 | ||
|
||
h2. Changes since Globalize2 v0.1.0 | ||
|
||
* The association globalize_translations has been renamed to translations. | ||
|
||
h2. Alternative Solutions | ||
|
||
* "Veger's fork":http://github.com/veger/globalize2 - uses default AR schema for the default locale, delegates to the translations table for other locales only | ||
* "TranslatableColumns":http://github.com/iain/translatable_columns - have multiple languages of the same attribute in a model (Iain Hecker) | ||
* "localized_record":http://github.com/glennpow/localized_record - allows records to have localized attributes without any modifications to the database (Glenn Powell) | ||
* "model_translations":http://github.com/janne/model_translations - Minimal implementation of Globalize2 style model translations (Jan Andersson) | ||
|
||
h2. Related solutions | ||
|
||
* "globalize2_versioning":http://github.com/joshmh/globalize2_versioning - acts_as_versioned style versioning for Globalize2 (Joshua Harvey) | ||
* "i18n_multi_locales_validations":http://github.com/ZenCocoon/i18n_multi_locales_validations - multi-locales attributes validations to validates attributes from Globalize2 translations models (Sébastien Grosjean) | ||
* "Globalize2 Demo App":http://github.com/svenfuchs/globalize2-demo - demo application for Globalize2 (Sven Fuchs)</li> | ||
* "migrate_from_globalize1":http://gist.github.com/120867 - migrate model translations from Globalize1 to Globalize2 (Tomasz Stachewicz)</li> | ||
* "easy_globalize2_accessors":http://github.com/astropanic/easy_globalize2_accessors - easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)</li> | ||
* "globalize2-easy-translate":http://github.com/bsamman/globalize2-easy-translate - adds methods to easily access or set translated attributes to your model (bsamman)</li> | ||
* "batch_translations":http://github.com/alvarezrilla/batch_translations - allow saving multiple Globalize2 translations in the same request (Jose Alvarez Rilla)</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the globalize2 plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the globalize2 plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'Globalize2' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |s| | ||
s.name = "globalize2" | ||
s.summary = "Rails I18n: de-facto standard library for ActiveRecord data translation" | ||
s.description = "Rails I18n: de-facto standard library for ActiveRecord data translation" | ||
s.email = "joshmh@gmail.com" | ||
s.homepage = "http://github.com/joshmh/globalize2" | ||
# s.rubyforge_project = '' | ||
s.authors = ["Sven Fuchs, Joshua Harvey, Clemens Kofler, John-Paul Bader"] | ||
# s.add_development_dependency '' | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.2.1 |
Empty file.
25 changes: 25 additions & 0 deletions
25
vendor/plugins/globalize2/generators/templates/db_backend_migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class ActsAsTaggableMigration < ActiveRecord::Migration | ||
def self.up | ||
create_table :globalize_translations do |t| | ||
t.string :locale, :null => false | ||
t.string :key, :null => false | ||
t.string :translation | ||
t.timestamps | ||
end | ||
|
||
# TODO: FINISH DOING MIGRATION -- stopped in the middle | ||
|
||
create_table :globalize_translations_map do |t| | ||
t.string :key, :null => false | ||
t.integer :translation_id, :null => false | ||
end | ||
|
||
add_index :taggings, :tag_id | ||
add_index :taggings, [:taggable_id, :taggable_type] | ||
end | ||
|
||
def self.down | ||
drop_table :globalize_translations | ||
drop_table :tags | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{globalize2} | ||
s.version = "0.2.0" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Sven Fuchs, Joshua Harvey, Clemens Kofler, John-Paul Bader"] | ||
s.date = %q{2010-04-22} | ||
s.description = %q{Rails I18n: de-facto standard library for ActiveRecord data translation} | ||
s.email = %q{joshmh@gmail.com} | ||
s.extra_rdoc_files = [ | ||
"LICENSE", | ||
"README.textile" | ||
] | ||
s.files = [ | ||
".gitignore", | ||
"LICENSE", | ||
"README.textile", | ||
"Rakefile", | ||
"VERSION", | ||
"generators/db_backend.rb", | ||
"generators/templates/db_backend_migration.rb", | ||
"globalize2.gemspec", | ||
"init.rb", | ||
"lib/globalize.rb", | ||
"lib/globalize/active_record.rb", | ||
"lib/globalize/active_record/adapter.rb", | ||
"lib/globalize/active_record/attributes.rb", | ||
"lib/globalize/active_record/migration.rb", | ||
"lib/i18n/missing_translations_log_handler.rb", | ||
"lib/i18n/missing_translations_raise_handler.rb", | ||
"test/active_record/fallbacks_test.rb", | ||
"test/active_record/migration_test.rb", | ||
"test/active_record/sti_translated_test.rb", | ||
"test/active_record/translates_test.rb", | ||
"test/active_record/translation_class_test.rb", | ||
"test/active_record/validation_tests.rb", | ||
"test/active_record_test.rb", | ||
"test/all.rb", | ||
"test/data/models.rb", | ||
"test/data/no_globalize_schema.rb", | ||
"test/data/schema.rb", | ||
"test/i18n/missing_translations_test.rb", | ||
"test/test_helper.rb" | ||
] | ||
s.homepage = %q{http://github.com/joshmh/globalize2} | ||
s.rdoc_options = ["--charset=UTF-8"] | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.3.6} | ||
s.summary = %q{Rails I18n: de-facto standard library for ActiveRecord data translation} | ||
s.test_files = [ | ||
"test/active_record/fallbacks_test.rb", | ||
"test/active_record/migration_test.rb", | ||
"test/active_record/sti_translated_test.rb", | ||
"test/active_record/translates_test.rb", | ||
"test/active_record/translation_class_test.rb", | ||
"test/active_record/validation_tests.rb", | ||
"test/active_record_test.rb", | ||
"test/all.rb", | ||
"test/data/models.rb", | ||
"test/data/no_globalize_schema.rb", | ||
"test/data/schema.rb", | ||
"test/i18n/missing_translations_test.rb", | ||
"test/test_helper.rb" | ||
] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | ||
else | ||
end | ||
else | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'globalize' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Globalize | ||
autoload :ActiveRecord, 'globalize/active_record' | ||
|
||
class << self | ||
def fallbacks? | ||
I18n.respond_to?(:fallbacks) | ||
end | ||
|
||
def fallbacks(locale) | ||
fallbacks? ? I18n.fallbacks[locale] : [locale.to_sym] | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Base.send(:include, Globalize::ActiveRecord) |
Oops, something went wrong.