Allow multi-level i18n files. Fixes #725
This commit is contained in:
parent
2e2516b95a
commit
18da6362ba
|
@ -1,6 +1,13 @@
|
||||||
Master
|
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
|
3.0.9
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -19,6 +19,9 @@ group :test do
|
||||||
gem "liquid", "~> 2.2"
|
gem "liquid", "~> 2.2"
|
||||||
gem "cane"
|
gem "cane"
|
||||||
|
|
||||||
|
gem "pry"
|
||||||
|
gem "pry-debugger"
|
||||||
|
|
||||||
platforms :ruby do
|
platforms :ruby do
|
||||||
gem "therubyracer", "0.10.2"
|
gem "therubyracer", "0.10.2"
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,7 @@ module Middleman
|
||||||
|
|
||||||
# Needed for helpers as well
|
# Needed for helpers as well
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
locales_glob = File.join(locales_dir, "*.yml");
|
Localizer.new(self, options)
|
||||||
|
|
||||||
::I18n.load_path += Dir[File.join(root, locales_glob)]
|
|
||||||
::I18n.reload!
|
|
||||||
|
|
||||||
Localizer.new(self, locales_glob, options)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
|
@ -29,12 +24,19 @@ module Middleman
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
delegate :logger, :to => :app
|
delegate :logger, :to => :app
|
||||||
|
|
||||||
def initialize(app, locales_glob, options={})
|
def initialize(app, options={})
|
||||||
@app = app
|
@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 = {}
|
@maps = {}
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
|
::I18n.load_path += Dir[File.join(app.root, @locales_glob)]
|
||||||
|
::I18n.reload!
|
||||||
|
|
||||||
@lang_map = @options[:lang_map] || {}
|
@lang_map = @options[:lang_map] || {}
|
||||||
@path = @options[:path] || "/:locale/"
|
@path = @options[:path] || "/:locale/"
|
||||||
@templates_dir = @options[:templates_dir] || "localizable"
|
@templates_dir = @options[:templates_dir] || "localizable"
|
||||||
|
@ -71,7 +73,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_file_changed(file)
|
def on_file_changed(file)
|
||||||
if File.fnmatch(@locales_glob, file)
|
if @locales_regex.match(file)
|
||||||
::I18n.reload!
|
::I18n.reload!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,7 +81,7 @@ module Middleman
|
||||||
def langs
|
def langs
|
||||||
@options[:langs] || begin
|
@options[:langs] || begin
|
||||||
Dir[File.join(@app.root, @locales_glob)].map { |file|
|
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)
|
}.sort.map(&:to_sym)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue