rkj-merb-i18n 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ log/*
3
+ tmp/*
4
+ *~
5
+ .#*
6
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tymon Tobolski (http://teamon.eu)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ merb-i18n
2
+ =========
3
+
4
+ A plugin for the Merb framework that provides i18n support to translate your site in several languages.
5
+
6
+ It is just a wrap for R18n core library. See R18n documentation for more information. (http://github.com/ai/r18n)
7
+
8
+ Features
9
+ --------
10
+ - Nice Ruby-style syntax.
11
+ - Filters.
12
+ - Flexible locales.
13
+ - Custom translations loaders.
14
+ - Translation support for any classes.
15
+ - Time and number localization.
16
+ - Several user language support.
17
+
18
+ Instalation
19
+ -----------
20
+ gem sources -a http://gemcutter.org
21
+ sudo gem install merb-i18n
22
+
23
+ # config/dependencies.rb
24
+ dependency "merb-i18n"
25
+
26
+ Usage
27
+ -----
28
+
29
+ - Create directory Merb.root/app/i18n and put there
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "rkj-merb-i18n"
5
+ gemspec.summary = gemspec.description = "Merb plugin that provides bindings to r18n"
6
+ gemspec.email = "roman.kamyk@itiner.pl"
7
+ gemspec.homepage = "http://github.com/rkj/merb-i18n"
8
+ gemspec.authors = ['Andrey "A.I." Sitnik', "Tymon Tobolski"]
9
+ gemspec.add_dependency('merb-core', '>= 1.0')
10
+ gemspec.add_dependency('r18n-core', '~> 0.4.8')
11
+ end
12
+ Jeweler::GemcutterTasks.new
13
+ rescue LoadError
14
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
15
+ end
16
+
17
+ desc "Run specs"
18
+ task :spec do
19
+ system("spec -O spec/spec.opts spec")
20
+ end
data/TODO ADDED
File without changes
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.3
@@ -0,0 +1,89 @@
1
+ require 'r18n-core'
2
+ # make sure we're running inside Merb
3
+ if defined?(Merb::Plugins)
4
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
+ Merb::Plugins.config[:merb_i18n] = {
6
+ :default_locale => 'pl',
7
+ :untranslated => '<span style="color: red">%s</span>',
8
+ }
9
+
10
+ Merb.push_path(:i18n, Merb.root / :app / :i18n) unless Merb.load_paths.include?(:i18n)
11
+
12
+ module MerbI18n
13
+
14
+ module Controller
15
+ # Return tool for i18n support. It will be R18n::I18n object, see it
16
+ # documentation for more information.
17
+ def i18n
18
+ @i18n
19
+ end
20
+
21
+ def _set_i18n
22
+ R18n::I18n.default = Merb::Plugins.config[:merb_i18n][:default_locale]
23
+
24
+ locales = R18n::I18n.parse_http(request.env['HTTP_ACCEPT_LANGUAGE'])
25
+ cookies[:locale] = params[:locale] if params[:locale]
26
+ locales.insert(0, cookies[:locale]) if cookies[:locale]
27
+ @i18n = R18n::I18n.new(locales.flatten, self.i18n_dirs)
28
+ R18n.set(@i18n)
29
+ end
30
+
31
+ # Namespaced i18n with controller and action name
32
+ def ni18n
33
+ @n18n ||= i18n[params[:controller]][params[:action]]
34
+ end
35
+
36
+ # Dirs to load translations
37
+ def i18n_dirs
38
+ Merb.dir_for(:i18n)
39
+ end
40
+ end
41
+
42
+ module Helpers
43
+ def error_messages_for(obj = nil, opts = {})
44
+ current_form_context.error_messages_for(obj, opts[:error_class] || "error",
45
+ opts[:build_li] || "<li>%s</li>",
46
+ opts[:header] || "<h2>#{i18n.merb.error_messages_for_header}</h2>",
47
+ opts.key?(:before) ? opts[:before] : true)
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ class Merb::Controller
54
+ include MerbI18n::Controller
55
+ before :_set_i18n
56
+ end
57
+
58
+ if defined?(Merb::Helpers)
59
+ module Merb::Helpers::Form
60
+ include MerbI18n::Helpers
61
+ end
62
+ end
63
+
64
+ Merb::BootLoader.before_app_loads do
65
+ R18n::Filters.add(R18n::Untranslated, :hide_untranslated) do |v, c, translated, untranslated|
66
+ Merb::Plugins.config[:merb_i18n][:untranslated] % untranslated
67
+ end
68
+ end
69
+
70
+ Merb::BootLoader.after_app_loads do
71
+ if defined? Merb::Slices
72
+ Merb::Slices.each_slice do |slice|
73
+ unless slice.slice_paths.include? :i18n
74
+ slice.push_path :i18n, slice.root_path('app' / 'i18n')
75
+ end
76
+ end
77
+
78
+ module Merb::Slices::ControllerMixin::MixinMethods::InstanceMethods
79
+ protected
80
+ def i18n_dirs
81
+ [self.slice.dir_for(:i18n), Merb.dir_for(:i18n)]
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ Merb::Plugins.add_rakefiles "merb-i18n/merbtasks"
88
+
89
+ end
@@ -0,0 +1,8 @@
1
+ namespace :merb_i18n do
2
+ desc "Create i18n folder"
3
+ task :install do
4
+ dir = Merb.root / :app / :i18n
5
+ Dir.mkdir(dir) unless File.exist?(dir)
6
+ File.open(dir / 'en.yml', 'w') {|f| f.puts "foo: bar" } unless File.exist?(dir / 'en.yml')
7
+ end
8
+ end
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{merb-i18n}
8
+ s.version = "0.2.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrey \"A.I.\" Sitnik", "Tymon Tobolski"]
12
+ s.date = %q{2009-12-02}
13
+ s.description = %q{Merb plugin that provides bindings to r18n}
14
+ s.email = %q{i@teamon.eu}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.markdown",
23
+ "Rakefile",
24
+ "TODO",
25
+ "VERSION",
26
+ "lib/merb-i18n.rb",
27
+ "lib/merb-i18n/merbtasks.rb",
28
+ "merb-i18n.gemspec",
29
+ "spec/app/controllers/i18n.rb",
30
+ "spec/app/i18n/en.yml",
31
+ "spec/app/i18n/ru.yml",
32
+ "spec/app/slice/app/i18n/en.yml",
33
+ "spec/app/slice/application.rb",
34
+ "spec/app/slice/lib/slice.rb",
35
+ "spec/app/views/i18n/code.html.erb",
36
+ "spec/app/views/i18n/find_me.html.erb",
37
+ "spec/app/views/i18n/index.html.erb",
38
+ "spec/app/views/i18n/untranslated.html.erb",
39
+ "spec/app/views/i18n/use_t.html.erb",
40
+ "spec/merb-i18n_spec.rb",
41
+ "spec/spec.opts",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/teamon/merb-i18n}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.5}
48
+ s.summary = %q{Merb plugin that provides bindings to r18n}
49
+ s.test_files = [
50
+ "spec/app/controllers/i18n.rb",
51
+ "spec/app/slice/application.rb",
52
+ "spec/app/slice/lib/slice.rb",
53
+ "spec/merb-i18n_spec.rb",
54
+ "spec/spec_helper.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<merb-core>, [">= 1.0"])
63
+ s.add_runtime_dependency(%q<r18n-core>, [">= 0.3.2"])
64
+ else
65
+ s.add_dependency(%q<merb-core>, [">= 1.0"])
66
+ s.add_dependency(%q<r18n-core>, [">= 0.3.2"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<merb-core>, [">= 1.0"])
70
+ s.add_dependency(%q<r18n-core>, [">= 0.3.2"])
71
+ end
72
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ class I18n < Merb::Controller
3
+ self._template_root = File.dirname(__FILE__) / "../views"
4
+
5
+ def index
6
+ @article = i18n.l 10000
7
+ @created = Time.at(0).utc
8
+
9
+ render
10
+ end
11
+
12
+ def code
13
+ render
14
+ end
15
+
16
+ def untranslated
17
+ render
18
+ end
19
+
20
+ def find_me
21
+ render
22
+ end
23
+
24
+ def use_t
25
+ render
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ title: Article %1
2
+
3
+ created:
4
+ at: Created at %1
5
+
6
+ other: "Translations: %1"
7
+
8
+ app: APP
9
+
10
+ i18n:
11
+ find_me:
12
+ hidden: "Hurray!"
13
+
14
+ I am a string: I am translated string!
15
+ "I see numbers: %1": I am translated with %1
@@ -0,0 +1,4 @@
1
+ created:
2
+ at: Написана %1
3
+
4
+ other: "Переводы: %1"
@@ -0,0 +1 @@
1
+ slice: SLICE
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ module Slice
3
+ class Main < Merb::Controller
4
+ controller_for_slice
5
+ def index
6
+ render i18n.slice + ' and ' + i18n.app
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ if defined? Merb::Plugins
3
+ dependency 'merb-slices', '~> 1.0'
4
+ Merb::Slices::register(__FILE__)
5
+
6
+ module Slice
7
+ self.description = 'Test i18n for slices'
8
+ self.version = '0.0.1'
9
+ self.author = 'Andrey A.I. Sitnik'
10
+
11
+ def self.loaded; end
12
+ def self.activate; end
13
+ def self.deactivate; end
14
+
15
+ def self.setup_router(scope)
16
+ scope.default_routes
17
+ end
18
+ end
19
+
20
+ require File.dirname(__FILE__) / '../application'
21
+ end
@@ -0,0 +1 @@
1
+ <%= i18n.locale.code %>
@@ -0,0 +1 @@
1
+ <%= ni18n.hidden %>
@@ -0,0 +1,3 @@
1
+ <h1><%= i18n.title(@article) %></h1>
2
+ <p><%= i18n.created.at i18n.l(@created, :standard) %></p>
3
+ <p><%= i18n.other(i18n.translations.values.join(', ')) %></p>
@@ -0,0 +1 @@
1
+ <%= i18n.i.dont.exist %>
@@ -0,0 +1,2 @@
1
+ <%= "I am a string".t %>
2
+ <%= "I see numbers: %1".t(5) %>
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb-i18n" do
4
+
5
+ it "should provide i18n support in merb controller" do
6
+ c = dispatch_to(I18n, :index, {}, "HTTP_ACCEPT_LANGUAGE" => "ru_RU")
7
+
8
+ c.body.should == "<h1>Article 10 000</h1>\n" +
9
+ "<p>Написана 01.01.1970 00:00</p>\n" +
10
+ "<p>Переводы: Русский, English</p>\n"
11
+ end
12
+
13
+ it "should set locale manually" do
14
+ c = dispatch_to(I18n, :code, {}, "HTTP_ACCEPT_LANGUAGE" => "ru")
15
+ c.body.should == "ru\n"
16
+
17
+ c = dispatch_to(I18n, :code, {:locale => "en"}, "HTTP_ACCEPT_LANGUAGE" => "ru")
18
+ c.body.should == "en\n"
19
+ end
20
+
21
+ it "should provide i18n support in slice controller" do
22
+ dispatch_to(Slice::Main, :index).body.should == 'SLICE and APP'
23
+ end
24
+
25
+ it "should try to find translation using controller and action name" do
26
+ dispatch_to(I18n, :find_me).body.should == "Hurray!\n"
27
+ end
28
+
29
+ it "should mark untranslated string with custom pattern string" do
30
+ Merb::Plugins.config[:merb_i18n][:untranslated] = "[T]%s[/T]"
31
+ Merb::BootLoader::BeforeAppLoads.run
32
+ dispatch_to(I18n, :untranslated).body.should == "[T]i.dont.exist[/T]\n"
33
+ end
34
+
35
+ # describe MerbI18n::Helpers do
36
+ # it "should have translated error header" do
37
+ # pending
38
+ # end
39
+ # end
40
+
41
+ end
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format specdoc
@@ -0,0 +1,25 @@
1
+ require "rubygems"
2
+
3
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require "merb-core"
6
+ require "merb-slices"
7
+ require "merb-helpers"
8
+ require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
9
+
10
+ require File.dirname(__FILE__) / '../lib/merb-i18n'
11
+ require File.dirname(__FILE__) / 'app/controllers/i18n'
12
+
13
+ Merb.push_path(:i18n, File.dirname(__FILE__) / 'app/i18n')
14
+
15
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
16
+ Merb::Plugins.config[:merb_slices][:search_path] = File.dirname(__FILE__) / 'app/'
17
+ Merb::Router.prepare { add_slice(:slice) }
18
+
19
+ Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test', :session_store => "memory")
20
+
21
+ Spec::Runner.configure do |config|
22
+ config.include(Merb::Test::ViewHelper)
23
+ config.include(Merb::Test::RouteHelper)
24
+ config.include(Merb::Test::ControllerHelper)
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rkj-merb-i18n
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 3
9
+ version: 0.2.3
10
+ platform: ruby
11
+ authors:
12
+ - Andrey "A.I." Sitnik
13
+ - Tymon Tobolski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-27 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: merb-core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ version: "1.0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: r18n-core
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 4
44
+ - 8
45
+ version: 0.4.8
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Merb plugin that provides bindings to r18n
49
+ email: roman.kamyk@itiner.pl
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.markdown
57
+ - TODO
58
+ files:
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.markdown
62
+ - Rakefile
63
+ - TODO
64
+ - VERSION
65
+ - lib/merb-i18n.rb
66
+ - lib/merb-i18n/merbtasks.rb
67
+ - merb-i18n.gemspec
68
+ - spec/app/controllers/i18n.rb
69
+ - spec/app/i18n/en.yml
70
+ - spec/app/i18n/ru.yml
71
+ - spec/app/slice/app/i18n/en.yml
72
+ - spec/app/slice/application.rb
73
+ - spec/app/slice/lib/slice.rb
74
+ - spec/app/views/i18n/code.html.erb
75
+ - spec/app/views/i18n/find_me.html.erb
76
+ - spec/app/views/i18n/index.html.erb
77
+ - spec/app/views/i18n/untranslated.html.erb
78
+ - spec/app/views/i18n/use_t.html.erb
79
+ - spec/merb-i18n_spec.rb
80
+ - spec/spec.opts
81
+ - spec/spec_helper.rb
82
+ has_rdoc: true
83
+ homepage: http://github.com/rkj/merb-i18n
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --charset=UTF-8
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.6
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Merb plugin that provides bindings to r18n
112
+ test_files:
113
+ - spec/merb-i18n_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/app/controllers/i18n.rb
116
+ - spec/app/slice/application.rb
117
+ - spec/app/slice/lib/slice.rb