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:
|
||||
"""
|
||||
- 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'
|
||||
|
|
|
@ -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] ||= {}
|
||||
|
|
Loading…
Reference in a new issue