i18n_label 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +40 -0
- data/Rakefile +28 -0
- data/init.rb +1 -0
- data/lib/i18n_label.rb +29 -0
- data/spec/i18n_label_spec.rb +26 -0
- data/spec/spec_helper.rb +7 -0
- metadata +70 -0
data/README.textile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
h1. I18nLabel
|
2
|
+
|
3
|
+
*This is a gem version for "iain/i18n_label":http://github.com/iain/i18n_label plugin.*
|
4
|
+
|
5
|
+
Since labels don't use I18n in Rails 2.2 (I was too late in submitting the
|
6
|
+
patch), we'd have to make due with a plugin.
|
7
|
+
|
8
|
+
Installation and configuration consists of 1 easy steps:
|
9
|
+
|
10
|
+
# Run:
|
11
|
+
|
12
|
+
./script/plugin install git://github.com/iain/i18n_label.git
|
13
|
+
|
14
|
+
|
15
|
+
h1. Example
|
16
|
+
|
17
|
+
In your translation file:
|
18
|
+
|
19
|
+
en-US:
|
20
|
+
activerecord:
|
21
|
+
attributes:
|
22
|
+
topic:
|
23
|
+
name: A nice name
|
24
|
+
|
25
|
+
In your view:
|
26
|
+
|
27
|
+
<% form_for @topic do |f| %>
|
28
|
+
<%= f.label :name %>
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
The result is:
|
32
|
+
|
33
|
+
<label for="topic_name">A nice name</label> (please ignore the minor problem with html in github)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
For more information about where to put your translations,
|
38
|
+
visit "my blog":http://iain.nl/2008/09/translating-activerecord/
|
39
|
+
|
40
|
+
Copyright (c) 2008 "Iain Hecker":http://iain.nl/, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
desc 'Default: run specs.'
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
desc 'Run the specs'
|
9
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
|
+
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
11
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
gem.name = "i18n_label"
|
19
|
+
gem.summary = "Adds translated form labels to Rails 2.2"
|
20
|
+
gem.email = "Sunteya@gmail.com"
|
21
|
+
gem.homepage = "http://github.com/sunteya/i18n_label"
|
22
|
+
gem.authors = ["Sunteya"]
|
23
|
+
gem.add_dependency "actionpack"
|
24
|
+
end
|
25
|
+
Jeweler::RubyforgeTasks.new
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
28
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init.rb"
|
data/lib/i18n_label.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Just replace the method...
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
class InstanceTag
|
5
|
+
def to_label_tag(text = nil, options = {})
|
6
|
+
options = options.stringify_keys
|
7
|
+
tag_value = options.delete("value")
|
8
|
+
name_and_id = options.dup
|
9
|
+
name_and_id["id"] = name_and_id["for"]
|
10
|
+
add_default_name_and_id_for_value(tag_value, name_and_id)
|
11
|
+
options.delete("index")
|
12
|
+
options["for"] ||= name_and_id["id"]
|
13
|
+
|
14
|
+
if text.blank?
|
15
|
+
content = method_name.humanize
|
16
|
+
if object.respond_to?(:human_attribute_name)
|
17
|
+
content = object.human_attribute_name(method_name)
|
18
|
+
elsif object.class.respond_to?(:human_attribute_name)
|
19
|
+
content = object.class.human_attribute_name(method_name)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
content = text.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
label_tag(name_and_id["id"], content, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'i18n_label'
|
3
|
+
|
4
|
+
class Reply
|
5
|
+
|
6
|
+
def self.human_attribute_name(name)
|
7
|
+
"i18n #{name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def human_attribute_name(name)
|
11
|
+
self.class.human_attribute_name(name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ActionView::Helpers do
|
16
|
+
include ActionView::Helpers
|
17
|
+
|
18
|
+
it "label should call human_attribute_name" do
|
19
|
+
reply = Reply.new
|
20
|
+
tag = ActionView::Helpers::InstanceTag.new(:reply, :title, nil, reply)
|
21
|
+
tag.to_label_tag.should eql "<label for=\"reply_title\">i18n title</label>"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_label
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunteya
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-22 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionpack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: Sunteya@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.textile
|
33
|
+
files:
|
34
|
+
- README.textile
|
35
|
+
- Rakefile
|
36
|
+
- init.rb
|
37
|
+
- lib/i18n_label.rb
|
38
|
+
- spec/i18n_label_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/sunteya/i18n_label
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Adds translated form labels to Rails 2.2
|
68
|
+
test_files:
|
69
|
+
- spec/i18n_label_spec.rb
|
70
|
+
- spec/spec_helper.rb
|