mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
More i18n tests and make sure templates with locale in file name take precedence over the default.
This commit is contained in:
parent
d3c7436647
commit
f7ba4ada20
2 changed files with 45 additions and 14 deletions
|
@ -53,6 +53,7 @@ Feature: i18n Paths
|
||||||
And a file named "data/pages.yml" with:
|
And a file named "data/pages.yml" with:
|
||||||
"""
|
"""
|
||||||
- hello.html
|
- hello.html
|
||||||
|
- article.html
|
||||||
"""
|
"""
|
||||||
And a file named "locales/en.yml" with:
|
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 %>
|
Other: <%= url_for "/#{p}", locale: ::I18n.locale == :en ? :es : :en %>
|
||||||
<% end %>
|
<% 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:
|
And a file named "config.rb" with:
|
||||||
"""
|
"""
|
||||||
activate :i18n
|
activate :i18n
|
||||||
|
@ -89,3 +104,11 @@ 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 "/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'
|
||||||
|
|
|
@ -79,23 +79,31 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
|
|
||||||
new_resources = []
|
new_resources = []
|
||||||
|
|
||||||
resources.each do |resource|
|
file_extension_resources = resources.select do |resource|
|
||||||
# If it uses file extension localization
|
parse_locale_extension(resource.path)
|
||||||
if parse_locale_extension(resource.path)
|
end
|
||||||
result = parse_locale_extension(resource.path)
|
|
||||||
ext_lang, path, page_id = result
|
localizable_folder_resources = resources.select do |resource|
|
||||||
new_resources << build_resource(path, resource.path, page_id, ext_lang)
|
!file_extension_resources.include?(resource) && File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
||||||
# If it's a "localizable template"
|
end
|
||||||
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
|
||||||
page_id = File.basename(resource.path, File.extname(resource.path))
|
# If it's a "localizable template"
|
||||||
langs.each do |lang|
|
localizable_folder_resources.map do |resource|
|
||||||
# Remove folder name
|
page_id = File.basename(resource.path, File.extname(resource.path))
|
||||||
path = resource.path.sub(options[:templates_dir], '')
|
langs.each do |lang|
|
||||||
new_resources << build_resource(path, resource.path, page_id, lang)
|
# Remove folder name
|
||||||
end
|
path = resource.path.sub(options[:templates_dir], '')
|
||||||
|
new_resources << build_resource(path, resource.path, page_id, lang)
|
||||||
end
|
end
|
||||||
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|
|
@lookup = new_resources.each_with_object({}) do |desc, sum|
|
||||||
abs_path = desc.source_path.sub(options[:templates_dir], '')
|
abs_path = desc.source_path.sub(options[:templates_dir], '')
|
||||||
sum[abs_path] ||= {}
|
sum[abs_path] ||= {}
|
||||||
|
|
Loading…
Reference in a new issue