mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
I18n: Keep fragment and query in url_for (#2062)
* Add Cucumber Feature for url_for with query and fragment * Keep query and fragment when i18n-ing a path
This commit is contained in:
parent
448e179542
commit
fde9e8c04a
2 changed files with 16 additions and 4 deletions
|
@ -176,6 +176,7 @@ Feature: i18n Paths
|
||||||
es:
|
es:
|
||||||
paths:
|
paths:
|
||||||
hello: "hola"
|
hello: "hola"
|
||||||
|
form: "formulario"
|
||||||
msg: Hola
|
msg: Hola
|
||||||
"""
|
"""
|
||||||
And a file named "source/localizable/hello.html.erb" with:
|
And a file named "source/localizable/hello.html.erb" with:
|
||||||
|
@ -186,6 +187,10 @@ Feature: i18n Paths
|
||||||
Other: <%= url_for "/#{p}", locale: ::I18n.locale == :en ? :es : :en %>
|
Other: <%= url_for "/#{p}", locale: ::I18n.locale == :en ? :es : :en %>
|
||||||
<% end %>
|
<% end %>
|
||||||
"""
|
"""
|
||||||
|
And a file named "source/localizable/form.html.erb" with:
|
||||||
|
"""
|
||||||
|
Other: <%= url_for "/form.html", query: { foo: 'bar' }, fragment: "deep", locale: ::I18n.locale == :en ? :es : :en %>
|
||||||
|
"""
|
||||||
And a file named "source/localizable/article.html.erb" with:
|
And a file named "source/localizable/article.html.erb" with:
|
||||||
"""
|
"""
|
||||||
Page Lang: Default
|
Page Lang: Default
|
||||||
|
@ -213,6 +218,10 @@ Feature: i18n Paths
|
||||||
Then I should see "Page: Hola"
|
Then I should see "Page: Hola"
|
||||||
Then I should see 'Current: /es/hola.html'
|
Then I should see 'Current: /es/hola.html'
|
||||||
Then I should see 'Other: /hello.html'
|
Then I should see 'Other: /hello.html'
|
||||||
|
When I go to "/form.html"
|
||||||
|
Then I should see 'Other: /es/formulario.html?foo=bar#deep'
|
||||||
|
When I go to "/es/formulario.html"
|
||||||
|
Then I should see 'Other: /form.html?foo=bar#deep'
|
||||||
When I go to "/article.html"
|
When I go to "/article.html"
|
||||||
Then I should see "Page Lang: Default"
|
Then I should see "Page Lang: Default"
|
||||||
Then I should see 'Current: /article.html'
|
Then I should see 'Current: /article.html'
|
||||||
|
|
|
@ -200,10 +200,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
|
|
||||||
Contract String, Symbol => Maybe[String]
|
Contract String, Symbol => Maybe[String]
|
||||||
def localized_path(path, locale)
|
def localized_path(path, locale)
|
||||||
lookup_path = path.dup
|
begin
|
||||||
lookup_path << app.config[:index_file] if lookup_path.end_with?('/')
|
lookup = ::Middleman::Util.parse_uri(path)
|
||||||
|
lookup.path << app.config[:index_file] if lookup.path && lookup.path.end_with?('/')
|
||||||
@lookup[lookup_path] && @lookup[lookup_path][locale]
|
lookup.to_s if @lookup[lookup.path] && lookup.path = @lookup[lookup.path][locale]
|
||||||
|
rescue ::Addressable::URI::InvalidURIError
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Contract Symbol => String
|
Contract Symbol => String
|
||||||
|
|
Loading…
Reference in a new issue