diff --git a/middleman-core/features/i18n_link_to.feature b/middleman-core/features/i18n_link_to.feature index 200188ef..ceccec5c 100644 --- a/middleman-core/features/i18n_link_to.feature +++ b/middleman-core/features/i18n_link_to.feature @@ -53,6 +53,7 @@ Feature: i18n Paths And a file named "data/pages.yml" with: """ - hello.html + - article.html """ And a file named "locales/en.yml" with: """ @@ -76,6 +77,20 @@ Feature: i18n Paths Other: <%= url_for "/#{p}", locale: ::I18n.locale == :en ? :es : :en %> <% end %> """ + And a file named "source/localizable/article.html.erb" with: + """ + Page Lang: Default + + Current: <%= url_for "/article.html" %> + Other: <%= url_for "/article.html", locale: ::I18n.locale == :en ? :es : :en %> + """ + And a file named "source/localizable/article.es.html.erb" with: + """ + Page Lang: Spanish + + Current: <%= url_for "/article.html" %> + Other: <%= url_for "/article.html", locale: :en %> + """ And a file named "config.rb" with: """ activate :i18n @@ -89,3 +104,11 @@ 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 "/article.html" + Then I should see "Page Lang: Default" + Then I should see 'Current: /article.html' + Then I should see 'Other: /es/article.html' + When I go to "/es/article.html" + Then I should see "Page Lang: Spanish" + Then I should see 'Current: /es/article.html' + Then I should see 'Other: /article.html' diff --git a/middleman-core/lib/middleman-more/core_extensions/i18n.rb b/middleman-core/lib/middleman-more/core_extensions/i18n.rb index c679c52e..554c8867 100644 --- a/middleman-core/lib/middleman-more/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-more/core_extensions/i18n.rb @@ -79,23 +79,31 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension new_resources = [] - resources.each do |resource| - # If it uses file extension localization - if parse_locale_extension(resource.path) - result = parse_locale_extension(resource.path) - ext_lang, path, page_id = result - new_resources << build_resource(path, resource.path, page_id, ext_lang) - # If it's a "localizable template" - elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path) - page_id = File.basename(resource.path, File.extname(resource.path)) - langs.each do |lang| - # Remove folder name - path = resource.path.sub(options[:templates_dir], '') - new_resources << build_resource(path, resource.path, page_id, lang) - end + file_extension_resources = resources.select do |resource| + parse_locale_extension(resource.path) + end + + localizable_folder_resources = resources.select do |resource| + !file_extension_resources.include?(resource) && File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path) + end + + # If it's a "localizable template" + localizable_folder_resources.map do |resource| + page_id = File.basename(resource.path, File.extname(resource.path)) + langs.each do |lang| + # Remove folder name + path = resource.path.sub(options[:templates_dir], '') + new_resources << build_resource(path, resource.path, page_id, lang) end end + # If it uses file extension localization + file_extension_resources.map do |resource| + result = parse_locale_extension(resource.path) + ext_lang, path, page_id = result + new_resources << build_resource(path, resource.path, page_id, ext_lang) + end + @lookup = new_resources.each_with_object({}) do |desc, sum| abs_path = desc.source_path.sub(options[:templates_dir], '') sum[abs_path] ||= {}