More i18n tests and make sure templates with locale in file name take precedence over the default.

This commit is contained in:
Thomas Reynolds 2015-05-16 13:44:00 -07:00
parent d3c7436647
commit f7ba4ada20
2 changed files with 45 additions and 14 deletions

View file

@ -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'

View file

@ -79,14 +79,16 @@ 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)
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"
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
localizable_folder_resources.map do |resource|
page_id = File.basename(resource.path, File.extname(resource.path))
langs.each do |lang|
# Remove folder name
@ -94,6 +96,12 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
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|