rack-r18n 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +5 -0
  3. data/lib/rack-r18n.rb +34 -0
  4. metadata +87 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Simon Hafner aka Tass
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.
data/README.textile ADDED
@@ -0,0 +1,5 @@
1
+ h1. Rack-R18n
2
+
3
+ A small Rack middleware taking care of setting up your R18n locales.
4
+ You may pass @:default@ for a default locale and @:dirs@ for translation dirs,
5
+ defaults to "i18n".
data/lib/rack-r18n.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'r18n-core'
2
+ require 'pathname'
3
+
4
+ module Rack
5
+ class R18n
6
+ # Avaible options:
7
+ # :default => en
8
+ # :dirs => "i18n"
9
+ attr_reader :options, :dirs
10
+ def initialize(app, options = {})
11
+ @app = app
12
+ @options = options
13
+
14
+ ::R18n::I18n.default = @options[:default] || "en"
15
+ @options[:dirs] ||= "i18n"
16
+ @dirs = Array(@options[:dirs]).map do |dir|
17
+ (Pathname(__FILE__).dirname + dir).expand_path
18
+ end
19
+ end
20
+
21
+ def call(env)
22
+ set_r18n(env)
23
+ @app.call(env)
24
+ end
25
+
26
+ def set_r18n(env)
27
+ request = Rack::Request.new(env)
28
+ locales = ::R18n::I18n.parse_http(env['HTTP_ACCEPT_LANGUAGE'])
29
+ locales.insert(0, request.params[:locale]) if request.params[:locale]
30
+ ::R18n.set(::R18n::I18n.new(locales, @dirs))
31
+ end
32
+
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-r18n
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Simon Hafner aka Tass
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ date: 2010-03-20 00:00:00 +01:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rack
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ version: "0"
29
+ type: :runtime
30
+ version_requirements: *id001
31
+ - !ruby/object:Gem::Dependency
32
+ name: r18n-core
33
+ prerelease: false
34
+ requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ segments:
39
+ - 0
40
+ version: "0"
41
+ type: :runtime
42
+ version_requirements: *id002
43
+ description:
44
+ email: hafnersimon@gmail.com
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files: []
50
+
51
+ files:
52
+ - lib/rack-r18n.rb
53
+ - LICENSE
54
+ - README.textile
55
+ has_rdoc: true
56
+ homepage: http://github.com/Tass/rack-r18n
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 1
70
+ - 9
71
+ version: "1.9"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.6
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A small Rack middleware taking care of setting up your R18n locales.
86
+ test_files: []
87
+