mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Reload i18n files when they change, closes #616
This commit is contained in:
parent
c53c46729a
commit
3a4c063535
3 changed files with 48 additions and 5 deletions
|
@ -2,6 +2,7 @@ Master
|
|||
===
|
||||
* Bundled Normalize.css updated to 2.0.1
|
||||
* Fixed encoding extension activation
|
||||
* Reload i18n on file changes (#616)
|
||||
|
||||
3.0.5
|
||||
====
|
||||
|
|
|
@ -19,6 +19,36 @@ Feature: i18n Preview
|
|||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
||||
|
||||
Scenario: A template changes i18n during preview
|
||||
Given a fixture app "i18n-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
And the file "locales/en.yml" has the contents
|
||||
"""
|
||||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
||||
"""
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When the file "locales/en.yml" has the contents
|
||||
"""
|
||||
---
|
||||
en:
|
||||
greetings: "How You Doin"
|
||||
hi: "Sup"
|
||||
"""
|
||||
When I go to "/"
|
||||
Then I should see "How You Doin"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Sup World"
|
||||
|
||||
Scenario: Running localize with the alt path config
|
||||
Given a fixture app "i18n-test-app"
|
||||
And a file named "config.rb" with:
|
||||
|
|
|
@ -13,10 +13,12 @@ module Middleman
|
|||
|
||||
# Needed for helpers as well
|
||||
app.after_configuration do
|
||||
::I18n.load_path += Dir[File.join(root, locales_dir, "*.yml")]
|
||||
locales_glob = File.join(locales_dir, "*.yml");
|
||||
|
||||
::I18n.load_path += Dir[File.join(root, locales_glob)]
|
||||
::I18n.reload!
|
||||
|
||||
Localizer.new(self, options)
|
||||
Localizer.new(self, locales_glob, options)
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
@ -27,8 +29,9 @@ module Middleman
|
|||
attr_reader :app
|
||||
delegate :logger, :to => :app
|
||||
|
||||
def initialize(app, options={})
|
||||
def initialize(app, locales_glob, options={})
|
||||
@app = app
|
||||
@locales_glob = locales_glob
|
||||
@maps = {}
|
||||
@options = options
|
||||
|
||||
|
@ -62,11 +65,20 @@ module Middleman
|
|||
:i18n,
|
||||
self
|
||||
)
|
||||
|
||||
@app.files.changed(&method(:on_file_changed))
|
||||
@app.files.deleted(&method(:on_file_changed))
|
||||
end
|
||||
|
||||
def on_file_changed(file)
|
||||
if File.fnmatch(@locales_glob, file)
|
||||
::I18n.reload!
|
||||
end
|
||||
end
|
||||
|
||||
def langs
|
||||
@options[:langs] || begin
|
||||
Dir[File.join(@app.root, @app.locales_dir, "*.yml")].map { |file|
|
||||
Dir[File.join(@app.root, @locales_glob)].map { |file|
|
||||
File.basename(file).gsub(".yml", "")
|
||||
}.sort.map(&:to_sym)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue