Merge pull request #771 from bhollis/i18n
Handle non-english default languages
This commit is contained in:
commit
3db5d0ca6a
|
@ -103,6 +103,51 @@ Feature: i18n Preview
|
||||||
Then I should see "Como Esta?"
|
Then I should see "Como Esta?"
|
||||||
When I go to "/spanish/hola.html"
|
When I go to "/spanish/hola.html"
|
||||||
Then I should see "Hola World"
|
Then I should see "Hola World"
|
||||||
|
|
||||||
|
Scenario: Running localize with a non-English mount config
|
||||||
|
Given a fixture app "i18n-test-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :i18n, :mount_at_root => :es
|
||||||
|
"""
|
||||||
|
Given the Server is running at "i18n-test-app"
|
||||||
|
When I go to "/en/index.html"
|
||||||
|
Then I should see "Howdy"
|
||||||
|
When I go to "/en/hello.html"
|
||||||
|
Then I should see "Hello World"
|
||||||
|
When I go to "/"
|
||||||
|
Then I should see "Como Esta?"
|
||||||
|
When I go to "/hola.html"
|
||||||
|
Then I should see "Hola World"
|
||||||
|
When I go to "/hello.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/es/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/es/hola.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
Scenario: Running localize with a non-English lang subset
|
||||||
|
Given a fixture app "i18n-test-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :i18n, :langs => :es
|
||||||
|
"""
|
||||||
|
Given the Server is running at "i18n-test-app"
|
||||||
|
When I go to "/en/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/en/hello.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/"
|
||||||
|
Then I should see "Como Esta?"
|
||||||
|
When I go to "/hola.html"
|
||||||
|
Then I should see "Hola World"
|
||||||
|
When I go to "/hello.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/es/index.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
When I go to "/es/hola.html"
|
||||||
|
Then I should see "File Not Found"
|
||||||
|
|
||||||
|
|
||||||
Scenario: Running localize with the no mount config
|
Scenario: Running localize with the no mount config
|
||||||
Given a fixture app "i18n-test-app"
|
Given a fixture app "i18n-test-app"
|
||||||
|
|
|
@ -43,7 +43,7 @@ module Middleman
|
||||||
@mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
|
@mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
|
||||||
|
|
||||||
if !@app.build?
|
if !@app.build?
|
||||||
logger.info "== Locales: #{langs.join(", ")}"
|
logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Don't output localizable files
|
# Don't output localizable files
|
||||||
|
@ -52,15 +52,20 @@ module Middleman
|
||||||
@app.sitemap.provides_metadata_for_path do |url|
|
@app.sitemap.provides_metadata_for_path do |url|
|
||||||
if d = get_localization_data(url)
|
if d = get_localization_data(url)
|
||||||
lang, page_id = d
|
lang, page_id = d
|
||||||
instance_vars = Proc.new {
|
|
||||||
::I18n.locale = lang
|
|
||||||
@lang = lang
|
|
||||||
@page_id = page_id
|
|
||||||
}
|
|
||||||
{ :blocks => [instance_vars] }
|
|
||||||
else
|
else
|
||||||
{}
|
# Default to the @mount_at_root lang
|
||||||
|
page_id = nil
|
||||||
|
lang = @mount_at_root
|
||||||
end
|
end
|
||||||
|
|
||||||
|
instance_vars = Proc.new do
|
||||||
|
::I18n.locale = lang
|
||||||
|
@lang = lang
|
||||||
|
@page_id = page_id
|
||||||
|
end
|
||||||
|
|
||||||
|
locals = { :lang => lang, :page_id => page_id }
|
||||||
|
{ :blocks => [instance_vars], :locals => locals }
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.sitemap.register_resource_list_manipulator(
|
@app.sitemap.register_resource_list_manipulator(
|
||||||
|
@ -79,7 +84,9 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def langs
|
def langs
|
||||||
@options[:langs] || begin
|
if @options[:langs]
|
||||||
|
Array(@options[:langs]).map(&:to_sym)
|
||||||
|
else
|
||||||
Dir[File.join(@app.root, @locales_glob)].map { |file|
|
Dir[File.join(@app.root, @locales_glob)].map { |file|
|
||||||
File.basename(file).sub(/\.yml$/, "").sub(/\.rb$/, "")
|
File.basename(file).sub(/\.yml$/, "").sub(/\.rb$/, "")
|
||||||
}.sort.map(&:to_sym)
|
}.sort.map(&:to_sym)
|
||||||
|
|
Loading…
Reference in a new issue