Fix bone-headed link_to change

This commit is contained in:
Thomas Reynolds 2015-05-15 16:20:40 -07:00
parent b20d855f2c
commit ed5236ef37
3 changed files with 16 additions and 5 deletions

View file

@ -25,7 +25,7 @@ Feature: i18n Links
Page: <%= t(:msg) %>
<% data.pages.each_with_index do |p, i| %>
<%= link_to "Current #{p}", "/#{p}" %>
<%= link_to "Other #{p}", "/#{p}", ::I18n.locale == :en ? :es : :en %>
<%= link_to "Other #{p}", "/#{p}", lang: ::I18n.locale == :en ? :es : :en %>
<% end %>
"""
And a file named "config.rb" with:

View file

@ -1,5 +1,5 @@
module Middleman
# Current Version
# @return [String]
VERSION = '3.3.13' unless const_defined?(:VERSION)
VERSION = '3.3.14' unless const_defined?(:VERSION)
end

View file

@ -58,9 +58,20 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
::I18n.t(*args)
end
def link_to(text, target, lang=::I18n.locale)
url = extensions[:i18n].localized_path(target, lang)
url ? super(text, url) : super(text, target)
def link_to(*args, &block)
options = args.extract_options!
name = block_given? ? '' : args.shift
href = args.first
lang = options.delete(:lang) || ::I18n.locale
url = extensions[:i18n].localized_path(href, lang)
new_args = []
new_args << name unless block_given?
new_args << url || href
new_args << options
super(*new_args, &block)
end
end