Fix a bad i18n regression

This commit is contained in:
Thomas Reynolds 2015-09-28 14:52:16 -07:00
parent 04c133c90f
commit d9fc7a95e1
4 changed files with 19 additions and 10 deletions

View file

@ -1,3 +1,5 @@
<%= ::I18n.locale %>
Site: <%= partial :site %> Site: <%= partial :site %>
Country: <%= partial :country %> Country: <%= partial :country %>
Greeting: <%= partial :greeting %> Greeting: <%= partial :greeting %>

View file

@ -50,9 +50,6 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
@maps = {} @maps = {}
@mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root] @mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root]
# Don't output localizable files
app.ignore File.join(options[:templates_dir], '**')
configure_i18n configure_i18n
logger.info "== Locales: #{langs.join(', ')} (Default #{@mount_at_root})" logger.info "== Locales: #{langs.join(', ')} (Default #{@mount_at_root})"
@ -96,7 +93,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
# Try /localizable # Try /localizable
partials_path = File.join(locals_dir, partial_name) partials_path = File.join(locals_dir, partial_name)
lang_suffix = current_resource.metadata[:locals] && current_resource.metadata[:locals][:lang] lang_suffix = ::I18n.locale
extname = File.extname(partial_name) extname = File.extname(partial_name)
maybe_static = extname.length > 0 maybe_static = extname.length > 0
@ -138,7 +135,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
end end
# If it's a "localizable template" # If it's a "localizable template"
localizable_folder_resources.map do |resource| localizable_folder_resources.each do |resource|
page_id = File.basename(resource.path, File.extname(resource.path)) page_id = File.basename(resource.path, File.extname(resource.path))
langs.each do |lang| langs.each do |lang|
# Remove folder name # Remove folder name
@ -146,18 +143,23 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
new_resources << build_resource(path, resource.path, page_id, lang) new_resources << build_resource(path, resource.path, page_id, lang)
end end
resource.ignore!
# This is for backwards compatibility with the old provides_metadata-based code # This is for backwards compatibility with the old provides_metadata-based code
# that used to be in this extension, but I don't know how much sense it makes. # that used to be in this extension, but I don't know how much sense it makes.
next if resource.options[:lang] # next if resource.options[:lang]
resource.add_metadata options: { lang: @mount_at_root }, locals: { lang: @mount_at_root } # $stderr.puts "Defaulting #{resource.path} to #{@mount_at_root}"
# resource.add_metadata options: { lang: @mount_at_root }, locals: { lang: @mount_at_root }
end end
# If it uses file extension localization # If it uses file extension localization
file_extension_resources.map do |resource| file_extension_resources.each do |resource|
result = parse_locale_extension(resource.path) result = parse_locale_extension(resource.path)
ext_lang, path, page_id = result ext_lang, path, page_id = result
new_resources << build_resource(path, resource.path, page_id, ext_lang) new_resources << build_resource(path, resource.path, page_id, ext_lang)
resource.ignore!
end end
@lookup = new_resources.each_with_object({}) do |desc, sum| @lookup = new_resources.each_with_object({}) do |desc, sum|

View file

@ -141,6 +141,11 @@ module Middleman
target_resource.content_type target_resource.content_type
end end
def to_s
"#<#{self.class.to_s} path=#{@path} target=#{@target}>"
end
alias_method :inspect, :to_s
end end
end end
end end

View file

@ -194,7 +194,7 @@ module Middleman
end end
def to_s def to_s
"#<Middleman::Sitemap::Resource path=#{@path}>" "#<#{self.class.to_s} path=#{@path}>"
end end
alias_method :inspect, :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s alias_method :inspect, :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
end end