perfectline-locale_routing 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +20 -16
- data/VERSION.yml +2 -2
- data/init.rb +1 -0
- data/install.rb +2 -0
- data/lib/locale_routing/locale.rb +7 -1
- data/locale_routing.gemspec +44 -0
- metadata +8 -3
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 PerfectLine LLC (www.perfectline.co.uk)
|
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.markdown
CHANGED
@@ -4,11 +4,11 @@ LocaleRouting makes using I18N locale from an url parameter or hostname seamless
|
|
4
4
|
It taps into the route recognition and generation methods and checks or adds the locale when nessecary.
|
5
5
|
|
6
6
|
The plugin loads its available locales from Rails default I18N class.
|
7
|
-
For every request, it check the configured part the URL match any of the locale definitions exposed by I18n.available_locales
|
8
|
-
If a locale string is found, the application I18n.
|
7
|
+
For every request, it check the configured part the URL match any of the locale definitions exposed by `I18n.available_locales`.
|
8
|
+
If a locale string is found, the application `I18n.local`e is changed and the locale is passed via `params[:locale]`.
|
9
9
|
|
10
10
|
Access to mapped URLs is wrapped also, the current I18n.locale is always prepended to the generated URLs parameters.
|
11
|
-
Additionally you can pass a {:locale => "en} option to your link helpers, which will inject the given locale into the output URL.
|
11
|
+
Additionally you can pass a `{:locale => "en}` option to your link helpers, which will inject the given locale into the output URL.
|
12
12
|
This parameter defaults to I18n.locale.
|
13
13
|
|
14
14
|
No routes have to be changed to use this functionality.
|
@@ -19,32 +19,36 @@ There are several different ways to install this plugin.
|
|
19
19
|
|
20
20
|
### Installing as Rails gem dependency
|
21
21
|
|
22
|
-
To add **locale_routing** as a gem dependecy, add this to your
|
23
|
-
|
22
|
+
To add **locale_routing** as a gem dependecy, add this to your `config/environment.rb` like this:
|
23
|
+
Rails::Initializer.run do |config| block
|
24
|
+
...
|
25
|
+
config.gem 'perfectline-locale_routing', :lib => 'locale_routing', :source => 'http://gems.github.com'
|
26
|
+
...
|
27
|
+
end
|
24
28
|
|
25
|
-
To install this gem (and other missing gem dependencies) run
|
29
|
+
To install this gem (and other missing gem dependencies) run `rake gems:install`.
|
26
30
|
|
27
31
|
### Installing the gem manually
|
28
32
|
|
29
|
-
This requires you to have at least RubyGems version 1.2 (run
|
30
|
-
As the
|
33
|
+
This requires you to have at least RubyGems version 1.2 (run `gem -v` to check your current version).
|
34
|
+
As the gem is built by GitHub, you have to add GitHub as a gem source on your environment (if you havent done it already):
|
31
35
|
sudo gem sources -a http://gems.github.com
|
32
36
|
|
33
37
|
Install the plugin library:
|
34
38
|
sudo gem install perfectline-locale_routing
|
35
39
|
|
36
|
-
To include them gem in your application, add this to the bottom of your
|
40
|
+
To include them gem in your application, add this to the bottom of your `environment.rb` or in an initializer:
|
37
41
|
require 'locale_routing'
|
38
42
|
|
39
43
|
### Install as a plugin via Git
|
40
44
|
|
41
|
-
Alternatively you can use
|
45
|
+
Alternatively you can use `script/plugin` to export the code into your applications `vendor/plugins` directory.
|
42
46
|
'script/plugin install git://github.com/perfectline/locale_routing.git'
|
43
47
|
|
44
48
|
## Configuration
|
45
49
|
|
46
|
-
To enable or disable the locale routing set
|
47
|
-
To specifiy which part of the URL should be matched for the locale identifier, set
|
50
|
+
To enable or disable the locale routing set `Perfectline::LocaleRouting::Config.enabled = true/false`.
|
51
|
+
To specifiy which part of the URL should be matched for the locale identifier, set `Perfectline::LocaleRouting::Config.match_from = option`
|
48
52
|
|
49
53
|
### Available options for match_from are:
|
50
54
|
* **:params**
|
@@ -61,7 +65,7 @@ To specifiy which part of the URL should be matched for the locale identifier, s
|
|
61
65
|
Searches for configured matches in the domain name. If a match is found, the configured locale is then checked against I18n.available_locales.
|
62
66
|
If the configured locale does not exist in available locales, it will fall back to the default locale.
|
63
67
|
|
64
|
-
Configuring host to locale mappings is done via
|
68
|
+
Configuring host to locale mappings is done via `Perfectline::LocaleRouting::Config.mapping do |block|`.
|
65
69
|
Hash key must be the hostname pattern to be matched and value is the locale string.
|
66
70
|
Hostname patterns are like simplified regexp patterns with * wildcard support.
|
67
71
|
Mappings matching is similar to route config - first match found is used, rest is ignored.
|
@@ -80,11 +84,11 @@ As you can see there are no tests yet either, although they will be created as s
|
|
80
84
|
So if you do run into issues or have any improvement ideas, feel free to contact the authors.
|
81
85
|
|
82
86
|
## Honorable mentions
|
83
|
-
This plugin is
|
87
|
+
This plugin is inspired by the "routing-filter" plugin by **Sven Fuchs**.
|
84
88
|
|
85
89
|
## Authors:
|
86
|
-
Tanel Suurhans - tanel.suurhans_at_perfectline_d0t_ee
|
87
|
-
Tarmo Lehtpuu - tarmo.lehtpuu_at_perfectline_d0t_ee
|
90
|
+
**Tanel Suurhans** - tanel.suurhans_at_perfectline_d0t_ee
|
91
|
+
**Tarmo Lehtpuu** - tarmo.lehtpuu_at_perfectline_d0t_ee
|
88
92
|
|
89
93
|
## License
|
90
94
|
Copyright 2009 by PerfectLine LLC (<http://www.perfectline.co.uk>) and is released under the MIT license.
|
data/VERSION.yml
CHANGED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'locale_routing'
|
data/install.rb
ADDED
@@ -21,7 +21,13 @@ module Perfectline
|
|
21
21
|
locale = I18n.locale if locale.nil?
|
22
22
|
|
23
23
|
# substitute the locale
|
24
|
-
url.sub!(self.match_url)
|
24
|
+
url.sub!(self.match_url) do
|
25
|
+
|
26
|
+
hostname = $1
|
27
|
+
path = $2 == '/' ? '' : $2
|
28
|
+
|
29
|
+
"#{hostname}/#{locale}#{path}"
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
# extract and set locale
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{locale_routing}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Tanel Suurhans", "Tarmo Lehtpuu"]
|
9
|
+
s.date = %q{2009-05-26}
|
10
|
+
s.description = %q{A library for configuring/parsin locales from url params or hostname for I18n.}
|
11
|
+
s.email = %q{tanel.suurhans@perfectline.ee}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"MIT-LICENSE",
|
18
|
+
"README.markdown",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION.yml",
|
21
|
+
"init.rb",
|
22
|
+
"install.rb",
|
23
|
+
"lib/locale_routing.rb",
|
24
|
+
"lib/locale_routing/config.rb",
|
25
|
+
"lib/locale_routing/locale.rb",
|
26
|
+
"lib/locale_routing/locale_route_set.rb",
|
27
|
+
"locale_routing.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/perfectline/locale_routing/tree/master}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.3}
|
33
|
+
s.summary = %q{LocaleRouting makes parsing I18N locale from an url parameters/hostname seamless.}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
40
|
+
else
|
41
|
+
end
|
42
|
+
else
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perfectline-locale_routing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tanel Suurhans
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-05-
|
13
|
+
date: 2009-05-26 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -23,14 +23,19 @@ extensions: []
|
|
23
23
|
extra_rdoc_files:
|
24
24
|
- README.markdown
|
25
25
|
files:
|
26
|
+
- .gitignore
|
27
|
+
- MIT-LICENSE
|
26
28
|
- README.markdown
|
27
29
|
- Rakefile
|
28
30
|
- VERSION.yml
|
31
|
+
- init.rb
|
32
|
+
- install.rb
|
29
33
|
- lib/locale_routing.rb
|
30
34
|
- lib/locale_routing/config.rb
|
31
35
|
- lib/locale_routing/locale.rb
|
32
36
|
- lib/locale_routing/locale_route_set.rb
|
33
|
-
|
37
|
+
- locale_routing.gemspec
|
38
|
+
has_rdoc: false
|
34
39
|
homepage: http://github.com/perfectline/locale_routing/tree/master
|
35
40
|
post_install_message:
|
36
41
|
rdoc_options:
|