Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
|
8909d9cbbf |
55 changed files with 536 additions and 52 deletions
|
@ -1,13 +1,13 @@
|
|||
Feature: i18n Builder
|
||||
Feature: i18n v3 Builder
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: Running localize with the default config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
activate :i18n_v3
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
|
@ -46,12 +46,12 @@ Feature: i18n Builder
|
|||
And the file "password.txt" should contain "hunter2"
|
||||
|
||||
Scenario: Running localize with the alt path config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :path => "/lang_:locale/"
|
||||
activate :i18n_v3, :path => "/lang_:locale/"
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
|
@ -66,12 +66,12 @@ Feature: i18n Builder
|
|||
And the file "lang_es/hola.html" should contain "Hola World"
|
||||
|
||||
Scenario: Running localize with the alt root config
|
||||
Given a fixture app "i18n-alt-root-app"
|
||||
Given a fixture app "i18n-v3-alt-root-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :templates_dir => "lang_data"
|
||||
activate :i18n_v3, :templates_dir => "lang_data"
|
||||
"""
|
||||
Given a successfully built app at "i18n-alt-root-app"
|
||||
Given a successfully built app at "i18n-v3-alt-root-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
|
@ -86,12 +86,12 @@ Feature: i18n Builder
|
|||
And the file "es/hola.html" should contain "Hola World"
|
||||
|
||||
Scenario: Running localize with the lang map config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :lang_map => { :en => :english, :es => :spanish }
|
||||
activate :i18n_v3, :lang_map => { :en => :english, :es => :spanish }
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
|
@ -106,12 +106,12 @@ Feature: i18n Builder
|
|||
And the file "spanish/hola.html" should contain "Hola World"
|
||||
|
||||
Scenario: Running localize with the no mount config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :mount_at_root => false
|
||||
activate :i18n_v3, :mount_at_root => false
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| en/index.html |
|
||||
|
@ -127,12 +127,12 @@ Feature: i18n Builder
|
|||
And the file "es/hola.html" should contain "Hola World"
|
||||
|
||||
Scenario: Running localize with the subset config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :langs => [:en]
|
||||
activate :i18n_v3, :langs => [:en]
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
|
@ -145,13 +145,13 @@ Feature: i18n Builder
|
|||
And the file "hello.html" should contain "Hello World"
|
||||
|
||||
Scenario: Running localize with relative_assets
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
activate :i18n_v3
|
||||
activate :relative_assets
|
||||
"""
|
||||
Given a successfully built app at "i18n-test-app"
|
||||
Given a successfully built app at "i18n-v3-test-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
|
@ -1,7 +1,7 @@
|
|||
Feature: i18n manually setting locale
|
||||
Feature: i18n v3 manually setting locale
|
||||
|
||||
Scenario: Setting I18n.locale in a block (see issue #809) or with the :lang option
|
||||
Given the Server is running at "i18n-force-locale"
|
||||
Given the Server is running at "i18n-v3-force-locale"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "Hello"
|
||||
Then I should see "I18n.locale: en"
|
252
middleman-core/features/i18n_v3_preview.feature
Normal file
252
middleman-core/features/i18n_v3_preview.feature
Normal file
|
@ -0,0 +1,252 @@
|
|||
Feature: i18n v3 Preview
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: Running localize with the default config
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When I go to "/morning.html"
|
||||
Then I should see "Good morning"
|
||||
When I go to "/one.html"
|
||||
Then I should see "Only one"
|
||||
When I go to "/defaults_en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/en/morning.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/defaults_es/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
||||
When I go to "/es/manana.html"
|
||||
Then I should see "Buenos días"
|
||||
When I go to "/es/una.html"
|
||||
Then I should see "Solamente una"
|
||||
|
||||
Scenario: A template changes i18n during preview
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-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-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :path => "/lang_:locale/"
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When I go to "/lang_en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/lang_es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
When I go to "/lang_es/hola.html"
|
||||
Then I should see "Hola World"
|
||||
|
||||
|
||||
Scenario: Running localize with the alt root config
|
||||
Given a fixture app "i18n-v3-alt-root-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :templates_dir => "lang_data"
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-alt-root-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with the lang map config
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :lang_map => { :en => :english, :es => :spanish }
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When I go to "/english/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/spanish/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
When I go to "/spanish/hola.html"
|
||||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with a non-English mount config
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :mount_at_root => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-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 "/manana.html"
|
||||
Then I should see "Buenos días"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/en/morning.html"
|
||||
Then I should see "Good morning"
|
||||
When I go to "/es/manana.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-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :langs => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-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
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :mount_at_root => false
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-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 "File Not Found"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with the subset config
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :langs => [:en]
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
When I go to "/en/index.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 relative_assets
|
||||
Given a fixture app "i18n-v3-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3
|
||||
activate :relative_assets
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-test-app"
|
||||
When I go to "/"
|
||||
Then I should see '"stylesheets/site.css"'
|
||||
When I go to "/hello.html"
|
||||
Then I should see '"stylesheets/site.css"'
|
||||
When I go to "/es/index.html"
|
||||
Then I should see '"../stylesheets/site.css"'
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see '"../stylesheets/site.css"'
|
||||
|
||||
Scenario: Missing translations fall back to the default locale
|
||||
Given a fixture app "i18n-v3-default-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3, :mount_at_root => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-default-app"
|
||||
When I go to "/en/"
|
||||
Then I should see "Default locale: es"
|
||||
Then I should see "Current locale: en"
|
||||
Then I should see "Buenos días"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: Nested i18n yaml
|
||||
Given a fixture app "i18n-v3-nested-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n_v3
|
||||
"""
|
||||
Given the Server is running at "i18n-v3-nested-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
Then I should see "More"
|
||||
When I go to "/es/"
|
||||
Then I should see "Como Esta?"
|
||||
Then I should see "Mucho"
|
|
@ -1,13 +1,14 @@
|
|||
Feature: i18n Preview
|
||||
@wip
|
||||
Feature: i18n v4 Preview
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: Running localize with the default config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
|
@ -34,12 +35,12 @@ Feature: i18n Preview
|
|||
Then I should see "Solamente una"
|
||||
|
||||
Scenario: A template changes i18n during preview
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
And the file "locales/en.yml" has the contents
|
||||
"""
|
||||
---
|
||||
|
@ -64,12 +65,12 @@ Feature: i18n Preview
|
|||
Then I should see "Sup World"
|
||||
|
||||
Scenario: Running localize with the alt path config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :path => "/lang_:locale/"
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
|
@ -83,12 +84,12 @@ Feature: i18n Preview
|
|||
|
||||
|
||||
Scenario: Running localize with the alt root config
|
||||
Given a fixture app "i18n-alt-root-app"
|
||||
Given a fixture app "i18n-v4-alt-root-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :templates_dir => "lang_data"
|
||||
"""
|
||||
Given the Server is running at "i18n-alt-root-app"
|
||||
Given the Server is running at "i18n-v4-alt-root-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
|
@ -101,12 +102,12 @@ Feature: i18n Preview
|
|||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with the lang map config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :lang_map => { :en => :english, :es => :spanish }
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
|
@ -119,12 +120,12 @@ Feature: i18n Preview
|
|||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with a non-English mount config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :mount_at_root => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/en/hello.html"
|
||||
|
@ -147,12 +148,12 @@ Feature: i18n Preview
|
|||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Running localize with a non-English lang subset
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :langs => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
When I go to "/en/hello.html"
|
||||
|
@ -170,12 +171,12 @@ Feature: i18n Preview
|
|||
|
||||
|
||||
Scenario: Running localize with the no mount config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :mount_at_root => false
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/en/hello.html"
|
||||
|
@ -190,12 +191,12 @@ Feature: i18n Preview
|
|||
Then I should see "Hola World"
|
||||
|
||||
Scenario: Running localize with the subset config
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :langs => [:en]
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
When I go to "/hello.html"
|
||||
|
@ -208,13 +209,13 @@ Feature: i18n Preview
|
|||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Running localize with relative_assets
|
||||
Given a fixture app "i18n-test-app"
|
||||
Given a fixture app "i18n-v4-test-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
activate :relative_assets
|
||||
"""
|
||||
Given the Server is running at "i18n-test-app"
|
||||
Given the Server is running at "i18n-v4-test-app"
|
||||
When I go to "/"
|
||||
Then I should see '"stylesheets/site.css"'
|
||||
When I go to "/hello.html"
|
||||
|
@ -225,12 +226,12 @@ Feature: i18n Preview
|
|||
Then I should see '"../stylesheets/site.css"'
|
||||
|
||||
Scenario: Missing translations fall back to the default locale
|
||||
Given a fixture app "i18n-default-app"
|
||||
Given a fixture app "i18n-v4-default-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n, :mount_at_root => :es
|
||||
"""
|
||||
Given the Server is running at "i18n-default-app"
|
||||
Given the Server is running at "i18n-v4-default-app"
|
||||
When I go to "/en/"
|
||||
Then I should see "Default locale: es"
|
||||
Then I should see "Current locale: en"
|
||||
|
@ -238,12 +239,12 @@ Feature: i18n Preview
|
|||
Then I should see "Howdy"
|
||||
|
||||
Scenario: Nested i18n yaml
|
||||
Given a fixture app "i18n-nested-app"
|
||||
Given a fixture app "i18n-v4-nested-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :i18n
|
||||
"""
|
||||
Given the Server is running at "i18n-nested-app"
|
||||
Given the Server is running at "i18n-v4-nested-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
Then I should see "More"
|
|
@ -4,7 +4,7 @@ end
|
|||
|
||||
proxy "/fr/index.html", "index.html", :lang => :fr
|
||||
|
||||
activate :i18n
|
||||
activate :i18n_v3
|
||||
|
||||
# This is what breaks i18n, just because it adds a resource list manipulator that
|
||||
# forces a rebuild of the resource list.
|
4
middleman-core/fixtures/i18n-v4-test-app/locales/en.yml
Normal file
4
middleman-core/fixtures/i18n-v4-test-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
9
middleman-core/fixtures/i18n-v4-test-app/locales/es.yml
Normal file
9
middleman-core/fixtures/i18n-v4-test-app/locales/es.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
morning: "manana"
|
||||
one: "una"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/i18n-v4-test-app/source/CNAME
Normal file
1
middleman-core/fixtures/i18n-v4-test-app/source/CNAME
Normal file
|
@ -0,0 +1 @@
|
|||
test.github.com
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<%= stylesheet_link_tag :site %>
|
||||
</head>
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
Good morning
|
|
@ -0,0 +1 @@
|
|||
Buenos días
|
|
@ -0,0 +1 @@
|
|||
Only one
|
|
@ -0,0 +1 @@
|
|||
Solamente una
|
|
@ -0,0 +1 @@
|
|||
hunter2
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
hello: world;
|
||||
}
|
|
@ -45,8 +45,13 @@ end
|
|||
# Setup Optional Extensions
|
||||
###
|
||||
|
||||
Middleman::Extensions.register :i18n_v3 do
|
||||
require 'middleman-core/core_extensions/i18n_v3'
|
||||
Middleman::CoreExtensions::InternationalizationV3
|
||||
end
|
||||
|
||||
Middleman::Extensions.register :i18n do
|
||||
require 'middleman-core/core_extensions/i18n'
|
||||
require 'middleman-core/core_extensions/i18n_v4'
|
||||
Middleman::CoreExtensions::Internationalization
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||
class Middleman::CoreExtensions::InternationalizationV3 < ::Middleman::Extension
|
||||
option :no_fallbacks, false, 'Disable I18n fallbacks'
|
||||
option :langs, nil, 'List of langs, will autodiscover by default'
|
||||
option :lang_map, {}, 'Language shortname map'
|
194
middleman-core/lib/middleman-core/core_extensions/i18n_v4.rb
Normal file
194
middleman-core/lib/middleman-core/core_extensions/i18n_v4.rb
Normal file
|
@ -0,0 +1,194 @@
|
|||
class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||
option :no_fallbacks, false, 'Disable I18n fallbacks'
|
||||
option :langs, nil, 'List of langs, will autodiscover by default'
|
||||
option :lang_map, {}, 'Language shortname map'
|
||||
option :path, '/:locale/', 'URL prefix path'
|
||||
option :files_glob, ["**/*.html"], 'Files to automatically localize'
|
||||
option :mount_at_root, nil, 'Mount a specific language at the root of the site'
|
||||
option :data, 'locales', 'The directory holding your locale configurations'
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
super
|
||||
|
||||
# See https://github.com/svenfuchs/i18n/wiki/Fallbacks
|
||||
unless options[:no_fallbacks]
|
||||
require 'i18n/backend/fallbacks'
|
||||
::I18n::Backend::Simple.send(:include, ::I18n::Backend::Fallbacks)
|
||||
end
|
||||
|
||||
app.send :include, LocaleHelpers
|
||||
end
|
||||
|
||||
def after_configuration
|
||||
# app.files.reload_path(app.config[:locals_dir] || options[:data])
|
||||
|
||||
# @locales_glob = File.join(app.config[:locals_dir] || options[:data], '**', '*.{rb,yml,yaml}')
|
||||
# @locales_regex = convert_glob_to_regex(@locales_glob)
|
||||
|
||||
# @maps = {}
|
||||
# @mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root]
|
||||
|
||||
# configure_i18n
|
||||
|
||||
# if !app.build?
|
||||
# logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})"
|
||||
# end
|
||||
|
||||
# app.sitemap.provides_metadata_for_path(&method(:metadata_for_path))
|
||||
# app.files.changed(&method(:on_file_changed))
|
||||
# app.files.deleted(&method(:on_file_changed))
|
||||
end
|
||||
|
||||
helpers do
|
||||
def t(*args)
|
||||
::I18n.t(*args)
|
||||
end
|
||||
end
|
||||
|
||||
delegate :logger, :to => :app
|
||||
|
||||
def langs
|
||||
@_langs ||= get_known_languages
|
||||
end
|
||||
|
||||
# Update the main sitemap resource list
|
||||
# @return [void]
|
||||
# def manipulate_resource_list(resources)
|
||||
# @_localization_data = {}
|
||||
|
||||
# new_resources = []
|
||||
|
||||
# resources.each do |resource|
|
||||
# # If it uses file extension localization
|
||||
# if !parse_locale_extension(resource.path).nil?
|
||||
# result = parse_locale_extension(resource.path)
|
||||
# lang, path, page_id = result
|
||||
# new_resources << build_resource(path, resource.path, page_id, lang)
|
||||
# # If it's a "localizable template"
|
||||
# elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
||||
# page_id = File.basename(resource.path, File.extname(resource.path))
|
||||
# langs.each do |lang|
|
||||
# # Remove folder name
|
||||
# path = resource.path.sub(options[:templates_dir], '')
|
||||
# new_resources << build_resource(path, resource.path, page_id, lang)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# resources + new_resources
|
||||
# end
|
||||
|
||||
private
|
||||
|
||||
def on_file_changed(file)
|
||||
if @locales_regex =~ file
|
||||
@_langs = nil # Clear langs cache
|
||||
::I18n.reload!
|
||||
end
|
||||
end
|
||||
|
||||
def convert_glob_to_regex(glob)
|
||||
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
||||
regex = @locales_glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
|
||||
%r{^#{regex}}
|
||||
end
|
||||
|
||||
def configure_i18n
|
||||
::I18n.load_path += Dir[File.join(app.root, @locales_glob)]
|
||||
::I18n.reload!
|
||||
|
||||
::I18n.default_locale = @mount_at_root
|
||||
# Reset fallbacks to fall back to our new default
|
||||
if ::I18n.respond_to? :fallbacks
|
||||
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new
|
||||
end
|
||||
end
|
||||
|
||||
def metadata_for_path(url)
|
||||
if d = get_localization_data(url)
|
||||
lang, page_id = d
|
||||
else
|
||||
# Default to the @mount_at_root lang
|
||||
page_id = nil
|
||||
lang = @mount_at_root
|
||||
end
|
||||
|
||||
{
|
||||
:locals => {
|
||||
:lang => lang,
|
||||
:page_id => page_id
|
||||
},
|
||||
:options => { :lang => lang }
|
||||
}
|
||||
end
|
||||
|
||||
def get_known_languages
|
||||
if options[:langs]
|
||||
Array(options[:langs]).map(&:to_sym)
|
||||
else
|
||||
known_langs = app.files.known_paths.select do |p|
|
||||
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length === 2)
|
||||
end.map { |p|
|
||||
File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '')
|
||||
}.sort.map(&:to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
def get_localization_data(path)
|
||||
@_localization_data ||= {}
|
||||
@_localization_data[path]
|
||||
end
|
||||
|
||||
# Parse locale extension filename
|
||||
# @return [lang, path, basename]
|
||||
# will return +nil+ if no locale extension
|
||||
def parse_locale_extension(path)
|
||||
path_bits = path.split('.')
|
||||
return nil if path_bits.size < 3
|
||||
|
||||
lang = path_bits.delete_at(-2).to_sym
|
||||
return nil unless langs.include?(lang)
|
||||
|
||||
path = path_bits.join('.')
|
||||
basename = File.basename(path_bits[0..-2].join('.'))
|
||||
[lang, path, basename]
|
||||
end
|
||||
|
||||
def build_resource(path, source_path, page_id, lang)
|
||||
old_locale = ::I18n.locale
|
||||
::I18n.locale = lang
|
||||
localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id, :fallback => [])
|
||||
|
||||
prefix = if (options[:mount_at_root] == lang) || (options[:mount_at_root] == nil && langs[0] == lang)
|
||||
'/'
|
||||
else
|
||||
replacement = options[:lang_map].fetch(lang, lang)
|
||||
options[:path].sub(':locale', replacement.to_s)
|
||||
end
|
||||
|
||||
# path needs to be changed if file has a localizable extension. (options[mount_at_root] == lang)
|
||||
path = ::Middleman::Util.normalize_path(
|
||||
File.join(prefix, path.sub(page_id, localized_page_id))
|
||||
)
|
||||
|
||||
path.gsub!(options[:templates_dir]+'/', '')
|
||||
|
||||
@_localization_data[path] = [lang, path, localized_page_id]
|
||||
|
||||
p = ::Middleman::Sitemap::Resource.new(app.sitemap, path)
|
||||
p.proxy_to(source_path)
|
||||
|
||||
::I18n.locale = old_locale
|
||||
p
|
||||
end
|
||||
|
||||
module LocaleHelpers
|
||||
# Access the list of languages supported by this Middleman application
|
||||
# @return [Array<Symbol>]
|
||||
def langs
|
||||
extensions[:i18n].langs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Middleman::CoreExtensions::Internationalization.register(:i18n)
|
Loading…
Add table
Reference in a new issue