mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
i18n not ready for primetime yet
This commit is contained in:
parent
08f5e64858
commit
7d7f9a20ef
52 changed files with 593 additions and 1 deletions
37
middleman-core/features/i18n_builder_alt_path.feature
Normal file
37
middleman-core/features/i18n_builder_alt_path.feature
Normal file
|
@ -0,0 +1,37 @@
|
|||
@wip
|
||||
Feature: Builder Alt Path
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a successfully built app at "alt-path-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| index.html |
|
||||
And the file "index.html" should contain "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a successfully built app at "alt-path-app"
|
||||
When I cd to "build"
|
||||
Then the following files should not exist:
|
||||
| lang_en/index.html |
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a successfully built app at "alt-path-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| hello.html |
|
||||
And the file "hello.html" should contain "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a successfully built app at "alt-path-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| lang_es/index.html |
|
||||
And the file "lang_es/index.html" should contain "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a successfully built app at "alt-path-app"
|
||||
When I cd to "build"
|
||||
Then the following files should exist:
|
||||
| lang_es/hola.html |
|
||||
And the file "lang_es/hola.html" should contain "Hola World"
|
23
middleman-core/features/i18n_builder_alt_root.feature
Normal file
23
middleman-core/features/i18n_builder_alt_root.feature
Normal file
|
@ -0,0 +1,23 @@
|
|||
@wip
|
||||
Feature: Builder Alt Root
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a built app at "alt-root-app"
|
||||
Then "index.html" should exist at "alt-root-app" and include "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "alt-root-app"
|
||||
Then "en/index.html" should not exist at "alt-root-app"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a built app at "alt-root-app"
|
||||
Then "hello.html" should exist at "alt-root-app" and include "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a built app at "alt-root-app"
|
||||
Then "es/index.html" should exist at "alt-root-app" and include "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a built app at "alt-root-app"
|
||||
Then "es/hola.html" should exist at "alt-root-app" and include "Hola World"
|
23
middleman-core/features/i18n_builder_default.feature
Normal file
23
middleman-core/features/i18n_builder_default.feature
Normal file
|
@ -0,0 +1,23 @@
|
|||
@wip
|
||||
Feature: Builder Default
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "index.html" should exist at "i18n-test-app" and include "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "en/index.html" should not exist at "i18n-test-app"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "hello.html" should exist at "i18n-test-app" and include "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "es/index.html" should exist at "i18n-test-app" and include "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "es/hola.html" should exist at "i18n-test-app" and include "Hola World"
|
23
middleman-core/features/i18n_builder_lang_map.feature
Normal file
23
middleman-core/features/i18n_builder_lang_map.feature
Normal file
|
@ -0,0 +1,23 @@
|
|||
@wip
|
||||
Feature: Builder Lang Map
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a built app at "name-map-app"
|
||||
Then "index.html" should exist at "name-map-app" and include "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "name-map-app"
|
||||
Then "english/index.html" should not exist at "name-map-app"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a built app at "name-map-app"
|
||||
Then "hello.html" should exist at "name-map-app" and include "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a built app at "name-map-app"
|
||||
Then "spanish/index.html" should exist at "name-map-app" and include "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a built app at "name-map-app"
|
||||
Then "spanish/hola.html" should exist at "name-map-app" and include "Hola World"
|
27
middleman-core/features/i18n_builder_no_mount.feature
Normal file
27
middleman-core/features/i18n_builder_no_mount.feature
Normal file
|
@ -0,0 +1,27 @@
|
|||
@wip
|
||||
Feature: Builder No Mount
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a built app at "no-mount-app"
|
||||
Then "en/index.html" should exist at "no-mount-app" and include "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "no-mount-app"
|
||||
Then "index.html" should not exist at "no-mount-app"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a built app at "no-mount-app"
|
||||
Then "en/hello.html" should exist at "no-mount-app" and include "Hello World"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "no-mount-app"
|
||||
Then "hello.html" should not exist at "no-mount-app"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "es/index.html" should exist at "i18n-test-app" and include "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a built app at "i18n-test-app"
|
||||
Then "es/hola.html" should exist at "i18n-test-app" and include "Hola World"
|
23
middleman-core/features/i18n_builder_subset.feature
Normal file
23
middleman-core/features/i18n_builder_subset.feature
Normal file
|
@ -0,0 +1,23 @@
|
|||
@wip
|
||||
Feature: Builder Subset
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given a built app at "subset-app"
|
||||
Then "index.html" should exist at "subset-app" and include "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given a built app at "subset-app"
|
||||
Then "en/index.html" should not exist at "subset-app"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given a built app at "subset-app"
|
||||
Then "hello.html" should exist at "subset-app" and include "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given a built app at "subset-app"
|
||||
Then "es/index.html" should not exist at "subset-app"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given a built app at "subset-app"
|
||||
Then "es/hola.html" should not exist at "subset-app"
|
38
middleman-core/features/i18n_preview_alt_path.feature
Normal file
38
middleman-core/features/i18n_preview_alt_path.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview Alt Path
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/lang_en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/lang_es/"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/lang_es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "alt-path-app"
|
||||
When I go to "/lang_es/hola.html"
|
||||
Then I should see "Hola World"
|
38
middleman-core/features/i18n_preview_alt_root.feature
Normal file
38
middleman-core/features/i18n_preview_alt_root.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview Alt Root
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/es/"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "alt-root-app"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
38
middleman-core/features/i18n_preview_default.feature
Normal file
38
middleman-core/features/i18n_preview_default.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview Default
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/es/"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "i18n-test-app"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
38
middleman-core/features/i18n_preview_lang_map.feature
Normal file
38
middleman-core/features/i18n_preview_lang_map.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview Lang Map
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/english/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/spanish/"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/spanish/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "name-map-app"
|
||||
When I go to "/spanish/hola.html"
|
||||
Then I should see "Hola World"
|
38
middleman-core/features/i18n_preview_no_mount.feature
Normal file
38
middleman-core/features/i18n_preview_no_mount.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview No Mount
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/en/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/en/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/es/"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "Como Esta?"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "no-mount-app"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "Hola World"
|
38
middleman-core/features/i18n_preview_subset.feature
Normal file
38
middleman-core/features/i18n_preview_subset.feature
Normal file
|
@ -0,0 +1,38 @@
|
|||
@wip
|
||||
Feature: Preview Subset
|
||||
In order to preview localized html
|
||||
|
||||
Scenario: EN should be at root
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN should be at root 2
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/index.html"
|
||||
Then I should see "Howdy"
|
||||
|
||||
Scenario: EN mounted at root should not be in directory
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/en/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized EN
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/hello.html"
|
||||
Then I should see "Hello World"
|
||||
|
||||
Scenario: ES should be under namespace
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/es/"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: ES should be under namespace 2
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/es/index.html"
|
||||
Then I should see "File Not Found"
|
||||
|
||||
Scenario: Paths can be localized ES
|
||||
Given the Server is running at "subset-app"
|
||||
When I go to "/es/hola.html"
|
||||
Then I should see "File Not Found"
|
1
middleman-core/fixtures/alt-path-app/.mm-pid-4567
Normal file
1
middleman-core/fixtures/alt-path-app/.mm-pid-4567
Normal file
|
@ -0,0 +1 @@
|
|||
12945
|
2
middleman-core/fixtures/alt-path-app/config.rb
Normal file
2
middleman-core/fixtures/alt-path-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize :path => "/lang_:locale/"
|
4
middleman-core/fixtures/alt-path-app/locales/en.yml
Normal file
4
middleman-core/fixtures/alt-path-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/alt-path-app/locales/es.yml
Normal file
7
middleman-core/fixtures/alt-path-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/alt-path-app/source/layout.erb
Normal file
1
middleman-core/fixtures/alt-path-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
2
middleman-core/fixtures/alt-root-app/config.rb
Normal file
2
middleman-core/fixtures/alt-root-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize :templates_dir => "lang_data"
|
4
middleman-core/fixtures/alt-root-app/locales/en.yml
Normal file
4
middleman-core/fixtures/alt-root-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/alt-root-app/locales/es.yml
Normal file
7
middleman-core/fixtures/alt-root-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
1
middleman-core/fixtures/alt-root-app/source/layout.erb
Normal file
1
middleman-core/fixtures/alt-root-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
2
middleman-core/fixtures/i18n-test-app/config.rb
Normal file
2
middleman-core/fixtures/i18n-test-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize
|
4
middleman-core/fixtures/i18n-test-app/locales/en.yml
Normal file
4
middleman-core/fixtures/i18n-test-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/i18n-test-app/locales/es.yml
Normal file
7
middleman-core/fixtures/i18n-test-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/i18n-test-app/source/layout.erb
Normal file
1
middleman-core/fixtures/i18n-test-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
2
middleman-core/fixtures/name-map-app/config.rb
Normal file
2
middleman-core/fixtures/name-map-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize :lang_map => { :en => :english, :es => :spanish }
|
4
middleman-core/fixtures/name-map-app/locales/en.yml
Normal file
4
middleman-core/fixtures/name-map-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/name-map-app/locales/es.yml
Normal file
7
middleman-core/fixtures/name-map-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/name-map-app/source/layout.erb
Normal file
1
middleman-core/fixtures/name-map-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
2
middleman-core/fixtures/no-mount-app/config.rb
Normal file
2
middleman-core/fixtures/no-mount-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize :mount_at_root => false
|
4
middleman-core/fixtures/no-mount-app/locales/en.yml
Normal file
4
middleman-core/fixtures/no-mount-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/no-mount-app/locales/es.yml
Normal file
7
middleman-core/fixtures/no-mount-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/no-mount-app/source/layout.erb
Normal file
1
middleman-core/fixtures/no-mount-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
2
middleman-core/fixtures/subset-app/config.rb
Normal file
2
middleman-core/fixtures/subset-app/config.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
activate :i18n
|
||||
localize :langs => [:en]
|
4
middleman-core/fixtures/subset-app/locales/en.yml
Normal file
4
middleman-core/fixtures/subset-app/locales/en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
en:
|
||||
greetings: "Howdy"
|
||||
hi: "Hello"
|
7
middleman-core/fixtures/subset-app/locales/es.yml
Normal file
7
middleman-core/fixtures/subset-app/locales/es.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
es:
|
||||
paths:
|
||||
hello: "hola"
|
||||
|
||||
greetings: "Como Esta?"
|
||||
hi: "Hola"
|
1
middleman-core/fixtures/subset-app/source/layout.erb
Normal file
1
middleman-core/fixtures/subset-app/source/layout.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:hi) %> World
|
|
@ -0,0 +1 @@
|
|||
<%= I18n.t(:greetings) %>
|
|
@ -14,7 +14,7 @@ module Middleman::CoreExtensions::DefaultHelpers
|
|||
app.helpers ::Padrino::Helpers::FormatHelpers
|
||||
app.helpers ::Padrino::Helpers::RenderHelpers
|
||||
app.helpers ::Padrino::Helpers::NumberHelpers
|
||||
app.helpers ::Padrino::Helpers::TranslationHelpers
|
||||
# app.helpers ::Padrino::Helpers::TranslationHelpers
|
||||
|
||||
app.helpers Helpers
|
||||
|
||||
|
|
|
@ -97,6 +97,9 @@ module Middleman::CoreExtensions::Extensions
|
|||
# @param [Symbol, Module] ext Which extension to activate
|
||||
# @return [void]
|
||||
def activate(ext, options={}, &block)
|
||||
# Make :i18n a no-op
|
||||
return if ext == :i18n
|
||||
|
||||
ext_module = if ext.is_a?(Module)
|
||||
ext
|
||||
else
|
||||
|
|
108
middleman-core/lib/middleman-core/core_extensions/i18n.rb
Normal file
108
middleman-core/lib/middleman-core/core_extensions/i18n.rb
Normal file
|
@ -0,0 +1,108 @@
|
|||
# i18n Namespace
|
||||
module Middleman::CoreExtensions::I18n
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registerd
|
||||
def registered(app)
|
||||
app.set :locales_dir, "locales"
|
||||
|
||||
app.send :include, InstanceMethods
|
||||
|
||||
app.after_configuration do
|
||||
::I18n.load_path += Dir[File.join(root, locales_dir, "*.yml")]
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
class Localizer
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@maps = {}
|
||||
end
|
||||
|
||||
def setup(options)
|
||||
@options = options
|
||||
|
||||
@lang_map = @options[:lang_map] || {}
|
||||
@path = @options[:path] || "/:locale/"
|
||||
@templates_dir = @options[:templates_dir] || "localizable"
|
||||
@mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
|
||||
|
||||
if !@app.build?
|
||||
puts "== Locales: #{langs.join(", ")}"
|
||||
end
|
||||
|
||||
# Don't output localizable files
|
||||
ignore File.join(@templates_dir, "**/*")
|
||||
|
||||
provides_metadata_for_path do |url|
|
||||
if d = get_localization_data(url)
|
||||
lang, page_id = d
|
||||
instance_vars = Proc.new {
|
||||
::I18n.locale = lang
|
||||
@lang = lang
|
||||
@page_id = page_id
|
||||
}
|
||||
{ :blocks => [instance_vars] }
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def langs
|
||||
@options[:langs] || begin
|
||||
Dir[File.join(@app.root, @app.locales_dir, "*.yml")].map do |file|
|
||||
File.basename(file).gsub(".yml", "").to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_localization_data(url)
|
||||
if @mount_at_root
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
# def paths_for_file(file)
|
||||
# url = @app.sitemap.source_map.index(file)
|
||||
# page_id = File.basename(url, File.extname(url))
|
||||
#
|
||||
# langs.map do |lang|
|
||||
# ::I18n.locale = lang
|
||||
#
|
||||
# # Build lang path
|
||||
# if @mount_at_root == lang
|
||||
# prefix = "/"
|
||||
# else
|
||||
# replacement = @lang_map.has_key?(lang) ? @lang_map[lang] : lang
|
||||
# prefix = @path.sub(":locale", replacement.to_s)
|
||||
# end
|
||||
#
|
||||
# localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id)
|
||||
#
|
||||
# path = File.join(prefix, url.sub(page_id, localized_page_id))
|
||||
# [lang, path, localized_page_id]
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
# Frontmatter class methods
|
||||
module InstanceMethods
|
||||
|
||||
# Initialize the i18n
|
||||
def i18n
|
||||
@i18n ||= Localizer.new(self)
|
||||
end
|
||||
|
||||
# Main i18n API
|
||||
def localize(options={})
|
||||
settings.after_configuration do
|
||||
i18n.setup(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue