i18n_column 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,12 +4,19 @@
4
4
 
5
5
  This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are stored as a JSON object i.e. {"en":"Home","de":"Zuhause"}.
6
6
 
7
- The current and default language are stored within the class <tt>I18nColumn::Language</tt>. On each request the current language must be set via <tt>I18nColumn::Language.current_lang = 'en'</tt>. If not set the default language is taken. <tt>I18nColumn::Language.current_lang</tt> is used as the JSON key to store a translation i.e. "en":"Home".
7
+ The current and default locale are retrieved from the {Rails Internationalization (I18n) API}[http://guides.rubyonrails.org/i18n.html]. Set the current locale on each request with i.e. <tt>I18n.locale = :de</tt>. If not set the default locale will be taken: <tt>I18n.default_locale</tt>. <tt>I18n.locale</tt> is used as the JSON key to store a translation i.e. <tt>"en":"Home"</tt>.
8
+
9
+ <tt>i18n_column</tt> is tested with rails version 3.
8
10
 
9
11
  == Installation
10
12
 
11
- * Recently a gem version will be provided on gemcutter.
12
- * Run <tt>rails generate i18n_column:install</tt>. It will generate a i18n_column initializer file in order to set the default language.
13
+ <b>Gem</b>
14
+
15
+ gem install i18n_column
16
+
17
+ <b>Bundler</b>
18
+
19
+ gem('i18n_column')
13
20
 
14
21
  == Example
15
22
 
@@ -23,7 +30,7 @@ The current and default language are stored within the class <tt>I18nColumn::Lan
23
30
  end
24
31
 
25
32
  def self.down
26
- drop_table :nodes
33
+ drop_table(:nodes)
27
34
  end
28
35
  end
29
36
 
@@ -36,21 +43,25 @@ The current and default language are stored within the class <tt>I18nColumn::Lan
36
43
  <b>Controller</b>
37
44
 
38
45
  class ApplicationController < ActionController::Base
39
- before_filter(:set_i18n_column_lang)
46
+ before_filter(:set_locale)
40
47
 
41
48
  private
42
49
 
43
- def set_i18n_column_lang
44
- I18nColumn::Language.current_lang = params[:lang]
50
+ def set_locale
51
+ I18n.locale = params[:locale]
45
52
  end
46
53
  end
47
54
 
55
+ <b>Set the default locale in config/application.rb file</b>
56
+
57
+ config.i18n.default_locale = :de
58
+
48
59
  <b>Console</b>
49
60
 
50
- I18nColumn::Language.current_lang = 'en'
61
+ I18n.locale = :en
51
62
  node = Node.create!(:name => 'Home') => {"en":"Home"}
52
63
  node.name => 'Home'
53
- I18nColumn::Language.current_lang = 'de'
64
+ I18n.locale = :de
54
65
  node.name = 'Zuhause'
55
66
  node.save! => {"en":"Home","de":"Zuhause"}
56
67
  node.name => 'Zuhause'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/i18n_column.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{i18n_column}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philipp Ullmann"]
12
- s.date = %q{2010-10-13}
12
+ s.date = %q{2010-10-14}
13
13
  s.description = %q{This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are serialized using JSON.}
14
14
  s.email = %q{philipp.ullmann@create.at}
15
15
  s.extra_rdoc_files = [
@@ -24,11 +24,8 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "i18n_column.gemspec",
27
- "lib/generators/i18n_column/install/install_generator.rb",
28
- "lib/generators/i18n_column/install/templates/config/initializers/i18n_column.rb",
29
27
  "lib/i18n_column.rb",
30
28
  "lib/i18n_column/base.rb",
31
- "lib/i18n_column/language.rb",
32
29
  "spec/.rspec",
33
30
  "spec/i18n_column_spec.rb",
34
31
  "spec/spec_helper.rb"
@@ -19,12 +19,12 @@ module I18nColumn
19
19
  class_eval <<-EOV
20
20
  def #{col_name}
21
21
  json = #{col_name}_to_json
22
- json.nil? ? nil : json[::I18nColumn::Language.current_lang]
22
+ json.nil? ? nil : json[::I18n.locale.to_s]
23
23
  end
24
24
 
25
25
  def #{col_name}=(value)
26
26
  json = #{col_name}_to_json || {}
27
- json[::I18nColumn::Language.current_lang] = value
27
+ json[::I18n.locale.to_s] = value
28
28
  self[:#{col_name}] = json.to_json
29
29
  value
30
30
  end
data/lib/i18n_column.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require('active_record')
2
2
  require('i18n_column/base')
3
- require('i18n_column/language')
@@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe(I18nColumn::Base) do
4
4
  before(:each) do
5
+ I18n.locale = :en
5
6
  setup_db
6
7
  end
7
8
 
@@ -11,7 +12,6 @@ describe(I18nColumn::Base) do
11
12
 
12
13
  context('with no translation') do
13
14
  before(:each) do
14
- I18nColumn::Language.current_lang = 'en'
15
15
  @node = Node.new
16
16
  end
17
17
 
@@ -31,7 +31,6 @@ describe(I18nColumn::Base) do
31
31
 
32
32
  context('with an english name only') do
33
33
  before(:each) do
34
- I18nColumn::Language.current_lang = 'en'
35
34
  @node = Node.create!(:name => 'Home')
36
35
  end
37
36
 
@@ -48,7 +47,7 @@ describe(I18nColumn::Base) do
48
47
  end
49
48
 
50
49
  it('translates the name into german') do
51
- I18nColumn::Language.current_lang = 'de'
50
+ I18n.locale = :de
52
51
  @node.name = 'Zuhause'
53
52
  @node.name.should == 'Zuhause'
54
53
  end
@@ -57,38 +56,37 @@ describe(I18nColumn::Base) do
57
56
 
58
57
  context('with an english and german name') do
59
58
  before(:each) do
60
- I18nColumn::Language.current_lang = 'en'
61
59
  @node = Node.create!(:name => 'Home')
62
- I18nColumn::Language.current_lang = 'de'
60
+ I18n.locale = :de
63
61
  @node.update_attribute(:name, 'Zuhause')
64
62
  end
65
63
 
66
64
  describe('#name') do
67
65
  it('returns the english name') do
68
- I18nColumn::Language.current_lang = 'en'
66
+ I18n.locale = :en
69
67
  @node.name.should == 'Home'
70
68
  end
71
69
 
72
70
  it('returns the german name') do
73
- I18nColumn::Language.current_lang = 'de'
71
+ I18n.locale = :de
74
72
  @node.name.should == 'Zuhause'
75
73
  end
76
74
  end
77
75
 
78
76
  describe('#name=') do
79
77
  it('overrides the english name only') do
80
- I18nColumn::Language.current_lang = 'en'
78
+ I18n.locale = :en
81
79
  @node.name = 'Home overridden'
82
80
  @node.name.should == 'Home overridden'
83
- I18nColumn::Language.current_lang = 'de'
81
+ I18n.locale = :de
84
82
  @node.name.should == 'Zuhause'
85
83
  end
86
84
 
87
85
  it('overrides the german name only') do
88
- I18nColumn::Language.current_lang = 'de'
86
+ I18n.locale = :de
89
87
  @node.name = 'Zuhause ueberschrieben'
90
88
  @node.name.should == 'Zuhause ueberschrieben'
91
- I18nColumn::Language.current_lang = 'en'
89
+ I18n.locale = :en
92
90
  @node.name.should == 'Home'
93
91
  end
94
92
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_column
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philipp Ullmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-13 00:00:00 +02:00
18
+ date: 2010-10-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -83,11 +83,8 @@ files:
83
83
  - Rakefile
84
84
  - VERSION
85
85
  - i18n_column.gemspec
86
- - lib/generators/i18n_column/install/install_generator.rb
87
- - lib/generators/i18n_column/install/templates/config/initializers/i18n_column.rb
88
86
  - lib/i18n_column.rb
89
87
  - lib/i18n_column/base.rb
90
- - lib/i18n_column/language.rb
91
88
  - spec/.rspec
92
89
  - spec/i18n_column_spec.rb
93
90
  - spec/spec_helper.rb
@@ -1,19 +0,0 @@
1
- module I18nColumn
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
-
5
- desc <<DESC
6
- Description:
7
- Copy initialize file to your application.
8
- DESC
9
-
10
- def self.source_root
11
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
12
- end
13
-
14
- def copy_initializer_file
15
- template('config/initializers/i18n_column.rb')
16
- end
17
- end
18
- end
19
- end
@@ -1,2 +0,0 @@
1
- # On each request the current language must be set via I18nColumn::Language.current_lang = 'de'. If not set the default language ('en') is returned by I18nColumn::Language.current_lang.
2
- I18nColumn::Language.default_lang = 'en'
@@ -1,21 +0,0 @@
1
- # Saves the current and default language.
2
- module I18nColumn
3
- class Language
4
- @@default_lang = 'en'
5
-
6
- # Sets the default language.
7
- def self.default_lang=(lang)
8
- @@default_lang = lang
9
- end
10
-
11
- # Returns the current language.
12
- def self.current_lang
13
- ::Thread.current[:i18n_column_current_lang] || @@default_lang
14
- end
15
-
16
- # Sets the current language. Must be set by each request.
17
- def self.current_lang=(lang)
18
- ::Thread.current[:i18n_column_current_lang] = lang
19
- end
20
- end
21
- end