diff --git a/middleman-core/features/i18n_link_to.feature b/middleman-core/features/i18n_link_to.feature index b6f4101e..7a7b9cad 100644 --- a/middleman-core/features/i18n_link_to.feature +++ b/middleman-core/features/i18n_link_to.feature @@ -176,6 +176,7 @@ Feature: i18n Paths es: paths: hello: "hola" + form: "formulario" msg: Hola """ 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 %> <% 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: """ Page Lang: Default @@ -213,6 +218,10 @@ Feature: i18n Paths Then I should see "Page: Hola" Then I should see 'Current: /es/hola.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" Then I should see "Page Lang: Default" Then I should see 'Current: /article.html' diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 679fccbd..f1bf3229 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -200,10 +200,13 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension Contract String, Symbol => Maybe[String] def localized_path(path, locale) - lookup_path = path.dup - lookup_path << app.config[:index_file] if lookup_path.end_with?('/') - - @lookup[lookup_path] && @lookup[lookup_path][locale] + begin + lookup = ::Middleman::Util.parse_uri(path) + lookup.path << app.config[:index_file] if lookup.path && lookup.path.end_with?('/') + lookup.to_s if @lookup[lookup.path] && lookup.path = @lookup[lookup.path][locale] + rescue ::Addressable::URI::InvalidURIError + nil + end end Contract Symbol => String