From 18da6362baae5676f4f64e659d2d7821f3ac1753 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 11 Jan 2013 17:00:41 -0800 Subject: [PATCH] Allow multi-level i18n files. Fixes #725 --- CHANGELOG.md | 7 ++++++ Gemfile | 3 +++ .../middleman-more/core_extensions/i18n.rb | 22 ++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 489c1033..65602443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Master === +3.0.10 +==== + +* Avoid looking in binary files for frontmatter. #728 +* Allow nested i18n files. #725 +* Better adapt to Rack interface. #709 + 3.0.9 ==== diff --git a/Gemfile b/Gemfile index 3e48c783..5ef1b259 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,9 @@ group :test do gem "liquid", "~> 2.2" gem "cane" + gem "pry" + gem "pry-debugger" + platforms :ruby do gem "therubyracer", "0.10.2" diff --git a/middleman-more/lib/middleman-more/core_extensions/i18n.rb b/middleman-more/lib/middleman-more/core_extensions/i18n.rb index eb23e70f..534f4ad8 100644 --- a/middleman-more/lib/middleman-more/core_extensions/i18n.rb +++ b/middleman-more/lib/middleman-more/core_extensions/i18n.rb @@ -13,12 +13,7 @@ module Middleman # Needed for helpers as well app.after_configuration do - locales_glob = File.join(locales_dir, "*.yml"); - - ::I18n.load_path += Dir[File.join(root, locales_glob)] - ::I18n.reload! - - Localizer.new(self, locales_glob, options) + Localizer.new(self, options) end end alias :included :registered @@ -29,12 +24,19 @@ module Middleman attr_reader :app delegate :logger, :to => :app - def initialize(app, locales_glob, options={}) + def initialize(app, options={}) @app = app - @locales_glob = locales_glob + @locales_glob = File.join(app.locales_dir, "**", "*.{rb,yml}") + + regex = @locales_glob.sub(/\./, '\.').sub(File.join("**", "*"), ".*").sub(/\//, '\/').sub("{rb,yml}", "rb|yml") + @locales_regex = %r{^#{regex}} + @maps = {} @options = options + ::I18n.load_path += Dir[File.join(app.root, @locales_glob)] + ::I18n.reload! + @lang_map = @options[:lang_map] || {} @path = @options[:path] || "/:locale/" @templates_dir = @options[:templates_dir] || "localizable" @@ -71,7 +73,7 @@ module Middleman end def on_file_changed(file) - if File.fnmatch(@locales_glob, file) + if @locales_regex.match(file) ::I18n.reload! end end @@ -79,7 +81,7 @@ module Middleman def langs @options[:langs] || begin Dir[File.join(@app.root, @locales_glob)].map { |file| - File.basename(file).gsub(".yml", "") + File.basename(file).sub(/\.yml$/, "").sub(/\.rb$/, "") }.sort.map(&:to_sym) end end