diff --git a/TODO-BEFORE-3.0.md b/TODO-BEFORE-3.0.md index a0b1a946..6acee088 100644 --- a/TODO-BEFORE-3.0.md +++ b/TODO-BEFORE-3.0.md @@ -1,2 +1 @@ -* Finish i18n integration and documentation * Fix asset_hash ext with new sitemap \ No newline at end of file diff --git a/middleman-core/features/i18n_builder.feature b/middleman-core/features/i18n_builder.feature new file mode 100644 index 00000000..f3380be4 --- /dev/null +++ b/middleman-core/features/i18n_builder.feature @@ -0,0 +1,121 @@ +Feature: i18n Builder + In order to preview localized html + + Scenario: Running localize with the default config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize + """ + Given a successfully built app at "i18n-test-app" + When I cd to "build" + Then the following files should exist: + | index.html | + | hello.html | + | es/index.html | + | es/hola.html | + Then the following files should not exist: + | en/index.html | + And the file "index.html" should contain "Howdy" + And the file "hello.html" should contain "Hello World" + And the file "es/index.html" should contain "Como Esta?" + And the file "es/hola.html" should contain "Hola World" + + Scenario: Running localize with the alt path config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize :path => "/lang_:locale/" + """ + Given a successfully built app at "i18n-test-app" + When I cd to "build" + Then the following files should exist: + | index.html | + | hello.html | + | lang_es/index.html | + | lang_es/hola.html | + Then the following files should not exist: + | lang_en/index.html | + And the file "index.html" should contain "Howdy" + And the file "hello.html" should contain "Hello World" + And the file "lang_es/index.html" should contain "Como Esta?" + 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" + And a file named "config.rb" with: + """ + localize :templates_dir => "lang_data" + """ + Given a successfully built app at "i18n-alt-root-app" + When I cd to "build" + Then the following files should exist: + | index.html | + | hello.html | + | es/index.html | + | es/hola.html | + Then the following files should not exist: + | en/index.html | + And the file "index.html" should contain "Howdy" + And the file "hello.html" should contain "Hello World" + And the file "es/index.html" should contain "Como Esta?" + 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" + And a file named "config.rb" with: + """ + localize :lang_map => { :en => :english, :es => :spanish } + """ + Given a successfully built app at "i18n-test-app" + When I cd to "build" + Then the following files should exist: + | index.html | + | hello.html | + | spanish/index.html | + | spanish/hola.html | + Then the following files should not exist: + | english/index.html | + And the file "index.html" should contain "Howdy" + And the file "hello.html" should contain "Hello World" + And the file "spanish/index.html" should contain "Como Esta?" + 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" + And a file named "config.rb" with: + """ + localize :mount_at_root => false + """ + Given a successfully built app at "i18n-test-app" + When I cd to "build" + Then the following files should exist: + | en/index.html | + | en/hello.html | + | es/index.html | + | es/hola.html | + Then the following files should not exist: + | index.html | + | hello.html | + And the file "en/index.html" should contain "Howdy" + And the file "en/hello.html" should contain "Hello World" + And the file "es/index.html" should contain "Como Esta?" + And the file "es/hola.html" should contain "Hola World" + + Scenario: Running localize with the subset config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize :langs => [:en] + """ + Given a successfully built app at "i18n-test-app" + When I cd to "build" + Then the following files should exist: + | index.html | + | hello.html | + Then the following files should not exist: + | en/index.html | + | es/index.html | + | es/hola.html | + And the file "index.html" should contain "Howdy" + And the file "hello.html" should contain "Hello World" \ No newline at end of file diff --git a/middleman-core/features/i18n_builder_alt_path.feature b/middleman-core/features/i18n_builder_alt_path.feature deleted file mode 100644 index 07dddee2..00000000 --- a/middleman-core/features/i18n_builder_alt_path.feature +++ /dev/null @@ -1,36 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_builder_alt_root.feature b/middleman-core/features/i18n_builder_alt_root.feature deleted file mode 100644 index 062f6d5a..00000000 --- a/middleman-core/features/i18n_builder_alt_root.feature +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_builder_default.feature b/middleman-core/features/i18n_builder_default.feature deleted file mode 100644 index 025e111a..00000000 --- a/middleman-core/features/i18n_builder_default.feature +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_builder_lang_map.feature b/middleman-core/features/i18n_builder_lang_map.feature deleted file mode 100644 index f92d44f6..00000000 --- a/middleman-core/features/i18n_builder_lang_map.feature +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_builder_no_mount.feature b/middleman-core/features/i18n_builder_no_mount.feature deleted file mode 100644 index 595551a1..00000000 --- a/middleman-core/features/i18n_builder_no_mount.feature +++ /dev/null @@ -1,26 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_builder_subset.feature b/middleman-core/features/i18n_builder_subset.feature deleted file mode 100644 index 3388ddf7..00000000 --- a/middleman-core/features/i18n_builder_subset.feature +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/middleman-core/features/i18n_preview.feature b/middleman-core/features/i18n_preview.feature new file mode 100644 index 00000000..d228ebe7 --- /dev/null +++ b/middleman-core/features/i18n_preview.feature @@ -0,0 +1,113 @@ +Feature: i18n Preview + In order to preview localized html + + Scenario: Running localize with the default config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize + """ + Given the Server is running at "i18n-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 "Como Esta?" + When I go to "/es/hola.html" + Then I should see "Hola World" + + Scenario: Running localize with the alt path config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize :path => "/lang_:locale/" + """ + Given the Server is running at "i18n-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-alt-root-app" + And a file named "config.rb" with: + """ + localize :templates_dir => "lang_data" + """ + Given the Server is running at "i18n-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-test-app" + And a file named "config.rb" with: + """ + localize :lang_map => { :en => :english, :es => :spanish } + """ + Given the Server is running at "i18n-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 the no mount config + Given a fixture app "i18n-test-app" + And a file named "config.rb" with: + """ + localize :mount_at_root => false + """ + 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 "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-test-app" + And a file named "config.rb" with: + """ + localize :langs => [:en] + """ + Given the Server is running at "i18n-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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_alt_path.feature b/middleman-core/features/i18n_preview_alt_path.feature deleted file mode 100644 index 5f2b2ae0..00000000 --- a/middleman-core/features/i18n_preview_alt_path.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_alt_root.feature b/middleman-core/features/i18n_preview_alt_root.feature deleted file mode 100644 index 2ee6927b..00000000 --- a/middleman-core/features/i18n_preview_alt_root.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_default.feature b/middleman-core/features/i18n_preview_default.feature deleted file mode 100644 index 6b6ee3f3..00000000 --- a/middleman-core/features/i18n_preview_default.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_lang_map.feature b/middleman-core/features/i18n_preview_lang_map.feature deleted file mode 100644 index 50daa47f..00000000 --- a/middleman-core/features/i18n_preview_lang_map.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_no_mount.feature b/middleman-core/features/i18n_preview_no_mount.feature deleted file mode 100644 index c4be37b3..00000000 --- a/middleman-core/features/i18n_preview_no_mount.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_subset.feature b/middleman-core/features/i18n_preview_subset.feature deleted file mode 100644 index 5d4d7391..00000000 --- a/middleman-core/features/i18n_preview_subset.feature +++ /dev/null @@ -1,37 +0,0 @@ -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" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/config.rb b/middleman-core/fixtures/alt-path-app/config.rb deleted file mode 100644 index 77d8cbe7..00000000 --- a/middleman-core/fixtures/alt-path-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize :path => "/lang_:locale/" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/config.rb b/middleman-core/fixtures/alt-root-app/config.rb deleted file mode 100644 index ba5d0195..00000000 --- a/middleman-core/fixtures/alt-root-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize :templates_dir => "lang_data" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/locales/en.yml b/middleman-core/fixtures/alt-root-app/locales/en.yml deleted file mode 100644 index 91519342..00000000 --- a/middleman-core/fixtures/alt-root-app/locales/en.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -en: - greetings: "Howdy" - hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/locales/es.yml b/middleman-core/fixtures/alt-root-app/locales/es.yml deleted file mode 100644 index 06756f3d..00000000 --- a/middleman-core/fixtures/alt-root-app/locales/es.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -es: - paths: - hello: "hola" - - greetings: "Como Esta?" - hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/source/lang_data/hello.html.erb b/middleman-core/fixtures/alt-root-app/source/lang_data/hello.html.erb deleted file mode 100644 index a226480d..00000000 --- a/middleman-core/fixtures/alt-root-app/source/lang_data/hello.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/source/lang_data/index.html.erb b/middleman-core/fixtures/alt-root-app/source/lang_data/index.html.erb deleted file mode 100644 index c39d59f5..00000000 --- a/middleman-core/fixtures/alt-root-app/source/lang_data/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:greetings) %> \ No newline at end of file diff --git a/middleman-core/fixtures/alt-root-app/source/layout.erb b/middleman-core/fixtures/alt-root-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/alt-root-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/locales/en.yml b/middleman-core/fixtures/i18n-alt-root-app/locales/en.yml similarity index 100% rename from middleman-core/fixtures/alt-path-app/locales/en.yml rename to middleman-core/fixtures/i18n-alt-root-app/locales/en.yml diff --git a/middleman-core/fixtures/alt-path-app/locales/es.yml b/middleman-core/fixtures/i18n-alt-root-app/locales/es.yml similarity index 100% rename from middleman-core/fixtures/alt-path-app/locales/es.yml rename to middleman-core/fixtures/i18n-alt-root-app/locales/es.yml diff --git a/middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb b/middleman-core/fixtures/i18n-alt-root-app/source/lang_data/hello.html.erb similarity index 100% rename from middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb rename to middleman-core/fixtures/i18n-alt-root-app/source/lang_data/hello.html.erb diff --git a/middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb b/middleman-core/fixtures/i18n-alt-root-app/source/lang_data/index.html.erb similarity index 100% rename from middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb rename to middleman-core/fixtures/i18n-alt-root-app/source/lang_data/index.html.erb diff --git a/middleman-core/fixtures/alt-path-app/source/layout.erb b/middleman-core/fixtures/i18n-alt-root-app/source/layout.erb similarity index 100% rename from middleman-core/fixtures/alt-path-app/source/layout.erb rename to middleman-core/fixtures/i18n-alt-root-app/source/layout.erb diff --git a/middleman-core/fixtures/i18n-test-app/config.rb b/middleman-core/fixtures/i18n-test-app/config.rb deleted file mode 100644 index d113b9d8..00000000 --- a/middleman-core/fixtures/i18n-test-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/config.rb b/middleman-core/fixtures/name-map-app/config.rb deleted file mode 100644 index fdf8dc29..00000000 --- a/middleman-core/fixtures/name-map-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize :lang_map => { :en => :english, :es => :spanish } \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/locales/en.yml b/middleman-core/fixtures/name-map-app/locales/en.yml deleted file mode 100644 index 91519342..00000000 --- a/middleman-core/fixtures/name-map-app/locales/en.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -en: - greetings: "Howdy" - hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/locales/es.yml b/middleman-core/fixtures/name-map-app/locales/es.yml deleted file mode 100644 index 06756f3d..00000000 --- a/middleman-core/fixtures/name-map-app/locales/es.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -es: - paths: - hello: "hola" - - greetings: "Como Esta?" - hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/source/layout.erb b/middleman-core/fixtures/name-map-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/name-map-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/source/localizable/hello.html.erb b/middleman-core/fixtures/name-map-app/source/localizable/hello.html.erb deleted file mode 100644 index a226480d..00000000 --- a/middleman-core/fixtures/name-map-app/source/localizable/hello.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/name-map-app/source/localizable/index.html.erb b/middleman-core/fixtures/name-map-app/source/localizable/index.html.erb deleted file mode 100644 index c39d59f5..00000000 --- a/middleman-core/fixtures/name-map-app/source/localizable/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:greetings) %> \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/config.rb b/middleman-core/fixtures/no-mount-app/config.rb deleted file mode 100644 index 7e8276ad..00000000 --- a/middleman-core/fixtures/no-mount-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize :mount_at_root => false \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/locales/en.yml b/middleman-core/fixtures/no-mount-app/locales/en.yml deleted file mode 100644 index 91519342..00000000 --- a/middleman-core/fixtures/no-mount-app/locales/en.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -en: - greetings: "Howdy" - hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/locales/es.yml b/middleman-core/fixtures/no-mount-app/locales/es.yml deleted file mode 100644 index 06756f3d..00000000 --- a/middleman-core/fixtures/no-mount-app/locales/es.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -es: - paths: - hello: "hola" - - greetings: "Como Esta?" - hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/source/layout.erb b/middleman-core/fixtures/no-mount-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/no-mount-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/source/localizable/hello.html.erb b/middleman-core/fixtures/no-mount-app/source/localizable/hello.html.erb deleted file mode 100644 index a226480d..00000000 --- a/middleman-core/fixtures/no-mount-app/source/localizable/hello.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/no-mount-app/source/localizable/index.html.erb b/middleman-core/fixtures/no-mount-app/source/localizable/index.html.erb deleted file mode 100644 index c39d59f5..00000000 --- a/middleman-core/fixtures/no-mount-app/source/localizable/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:greetings) %> \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/config.rb b/middleman-core/fixtures/subset-app/config.rb deleted file mode 100644 index 5a8e071c..00000000 --- a/middleman-core/fixtures/subset-app/config.rb +++ /dev/null @@ -1,2 +0,0 @@ -activate :i18n -localize :langs => [:en] \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/locales/en.yml b/middleman-core/fixtures/subset-app/locales/en.yml deleted file mode 100644 index 91519342..00000000 --- a/middleman-core/fixtures/subset-app/locales/en.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -en: - greetings: "Howdy" - hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/locales/es.yml b/middleman-core/fixtures/subset-app/locales/es.yml deleted file mode 100644 index 06756f3d..00000000 --- a/middleman-core/fixtures/subset-app/locales/es.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -es: - paths: - hello: "hola" - - greetings: "Como Esta?" - hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/source/layout.erb b/middleman-core/fixtures/subset-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/subset-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/source/localizable/hello.html.erb b/middleman-core/fixtures/subset-app/source/localizable/hello.html.erb deleted file mode 100644 index a226480d..00000000 --- a/middleman-core/fixtures/subset-app/source/localizable/hello.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/subset-app/source/localizable/index.html.erb b/middleman-core/fixtures/subset-app/source/localizable/index.html.erb deleted file mode 100644 index c39d59f5..00000000 --- a/middleman-core/fixtures/subset-app/source/localizable/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= I18n.t(:greetings) %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 3e41c8b6..1ad59a28 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -10,9 +10,17 @@ module Middleman::CoreExtensions::I18n app.send :include, InstanceMethods + # Needed for helpers as well app.after_configuration do ::I18n.load_path += Dir[File.join(root, locales_dir, "*.yml")] end + + app.ready do + sitemap.register_resource_list_manipulator( + :i18n, + i18n + ) + end end alias :included :registered end @@ -36,9 +44,9 @@ module Middleman::CoreExtensions::I18n end # Don't output localizable files - ignore File.join(@templates_dir, "**/*") + @app.ignore File.join(@templates_dir, "**") - sitemap.provides_metadata_for_path do |url| + @app.sitemap.provides_metadata_for_path do |url| if d = get_localization_data(url) lang, page_id = d instance_vars = Proc.new { @@ -60,34 +68,56 @@ module Middleman::CoreExtensions::I18n end end end - - def get_localization_data(url) - if @mount_at_root - else - end + + def get_localization_data(path) + @_localization_data ||= {} + @_localization_data[path] 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 + # Update the main sitemap resource list + # @return [void] + def manipulate_resource_list(resources) + @_localization_data = {} + + new_resources = [] + + resources.each do |resource| + next unless File.fnmatch(File.join(@templates_dir, "**"), resource.path) + + page_id = File.basename(resource.path, File.extname(resource.path)) + + langs.map do |lang| + ::I18n.locale = lang + + localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id) + path = resource.path.sub(@templates_dir, "") + + # 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 + + path = ::Middleman::Util.normalize_path( + File.join(prefix, path.sub(page_id, localized_page_id)) + ) + + @_localization_data[path] = [lang, path, localized_page_id] + + p = ::Middleman::Sitemap::Resource.new( + @app.sitemap, + path + ) + p.proxy_to(resource.path) + + new_resources << p + end + end + + resources + new_resources + end end # Frontmatter class methods @@ -95,7 +125,7 @@ module Middleman::CoreExtensions::I18n # Initialize the i18n def i18n - @i18n ||= Localizer.new(self) + @_i18n ||= Localizer.new(self) end # Main i18n API