From 7d7f9a20effee32d05f0e83550933f1cbcfaad5e Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 10 Mar 2012 19:40:04 -0800 Subject: [PATCH] i18n not ready for primetime yet --- .../features/i18n_builder_alt_path.feature | 37 ++++++ .../features/i18n_builder_alt_root.feature | 23 ++++ .../features/i18n_builder_default.feature | 23 ++++ .../features/i18n_builder_lang_map.feature | 23 ++++ .../features/i18n_builder_no_mount.feature | 27 +++++ .../features/i18n_builder_subset.feature | 23 ++++ .../features/i18n_preview_alt_path.feature | 38 ++++++ .../features/i18n_preview_alt_root.feature | 38 ++++++ .../features/i18n_preview_default.feature | 38 ++++++ .../features/i18n_preview_lang_map.feature | 38 ++++++ .../features/i18n_preview_no_mount.feature | 38 ++++++ .../features/i18n_preview_subset.feature | 38 ++++++ .../fixtures/alt-path-app/.mm-pid-4567 | 1 + .../fixtures/alt-path-app/config.rb | 2 + .../fixtures/alt-path-app/locales/en.yml | 4 + .../fixtures/alt-path-app/locales/es.yml | 7 ++ .../fixtures/alt-path-app/source/layout.erb | 1 + .../source/localizable/hello.html.erb | 1 + .../source/localizable/index.html.erb | 1 + .../fixtures/alt-root-app/config.rb | 2 + .../fixtures/alt-root-app/locales/en.yml | 4 + .../fixtures/alt-root-app/locales/es.yml | 7 ++ .../source/lang_data/hello.html.erb | 1 + .../source/lang_data/index.html.erb | 1 + .../fixtures/alt-root-app/source/layout.erb | 1 + .../fixtures/i18n-test-app/config.rb | 2 + .../fixtures/i18n-test-app/locales/en.yml | 4 + .../fixtures/i18n-test-app/locales/es.yml | 7 ++ .../fixtures/i18n-test-app/source/layout.erb | 1 + .../source/localizable/hello.html.erb | 1 + .../source/localizable/index.html.erb | 1 + .../fixtures/name-map-app/config.rb | 2 + .../fixtures/name-map-app/locales/en.yml | 4 + .../fixtures/name-map-app/locales/es.yml | 7 ++ .../fixtures/name-map-app/source/layout.erb | 1 + .../source/localizable/hello.html.erb | 1 + .../source/localizable/index.html.erb | 1 + .../fixtures/no-mount-app/config.rb | 2 + .../fixtures/no-mount-app/locales/en.yml | 4 + .../fixtures/no-mount-app/locales/es.yml | 7 ++ .../fixtures/no-mount-app/source/layout.erb | 1 + .../source/localizable/hello.html.erb | 1 + .../source/localizable/index.html.erb | 1 + middleman-core/fixtures/subset-app/config.rb | 2 + .../fixtures/subset-app/locales/en.yml | 4 + .../fixtures/subset-app/locales/es.yml | 7 ++ .../fixtures/subset-app/source/layout.erb | 1 + .../source/localizable/hello.html.erb | 1 + .../source/localizable/index.html.erb | 1 + .../core_extensions/default_helpers.rb | 2 +- .../core_extensions/extensions.rb | 3 + .../middleman-core/core_extensions/i18n.rb | 108 ++++++++++++++++++ 52 files changed, 593 insertions(+), 1 deletion(-) create mode 100644 middleman-core/features/i18n_builder_alt_path.feature create mode 100644 middleman-core/features/i18n_builder_alt_root.feature create mode 100644 middleman-core/features/i18n_builder_default.feature create mode 100644 middleman-core/features/i18n_builder_lang_map.feature create mode 100644 middleman-core/features/i18n_builder_no_mount.feature create mode 100644 middleman-core/features/i18n_builder_subset.feature create mode 100644 middleman-core/features/i18n_preview_alt_path.feature create mode 100644 middleman-core/features/i18n_preview_alt_root.feature create mode 100644 middleman-core/features/i18n_preview_default.feature create mode 100644 middleman-core/features/i18n_preview_lang_map.feature create mode 100644 middleman-core/features/i18n_preview_no_mount.feature create mode 100644 middleman-core/features/i18n_preview_subset.feature create mode 100644 middleman-core/fixtures/alt-path-app/.mm-pid-4567 create mode 100644 middleman-core/fixtures/alt-path-app/config.rb create mode 100644 middleman-core/fixtures/alt-path-app/locales/en.yml create mode 100644 middleman-core/fixtures/alt-path-app/locales/es.yml create mode 100644 middleman-core/fixtures/alt-path-app/source/layout.erb create mode 100644 middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb create mode 100644 middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb create mode 100644 middleman-core/fixtures/alt-root-app/config.rb create mode 100644 middleman-core/fixtures/alt-root-app/locales/en.yml create mode 100644 middleman-core/fixtures/alt-root-app/locales/es.yml create mode 100644 middleman-core/fixtures/alt-root-app/source/lang_data/hello.html.erb create mode 100644 middleman-core/fixtures/alt-root-app/source/lang_data/index.html.erb create mode 100644 middleman-core/fixtures/alt-root-app/source/layout.erb create mode 100644 middleman-core/fixtures/i18n-test-app/config.rb create mode 100644 middleman-core/fixtures/i18n-test-app/locales/en.yml create mode 100644 middleman-core/fixtures/i18n-test-app/locales/es.yml create mode 100644 middleman-core/fixtures/i18n-test-app/source/layout.erb create mode 100644 middleman-core/fixtures/i18n-test-app/source/localizable/hello.html.erb create mode 100644 middleman-core/fixtures/i18n-test-app/source/localizable/index.html.erb create mode 100644 middleman-core/fixtures/name-map-app/config.rb create mode 100644 middleman-core/fixtures/name-map-app/locales/en.yml create mode 100644 middleman-core/fixtures/name-map-app/locales/es.yml create mode 100644 middleman-core/fixtures/name-map-app/source/layout.erb create mode 100644 middleman-core/fixtures/name-map-app/source/localizable/hello.html.erb create mode 100644 middleman-core/fixtures/name-map-app/source/localizable/index.html.erb create mode 100644 middleman-core/fixtures/no-mount-app/config.rb create mode 100644 middleman-core/fixtures/no-mount-app/locales/en.yml create mode 100644 middleman-core/fixtures/no-mount-app/locales/es.yml create mode 100644 middleman-core/fixtures/no-mount-app/source/layout.erb create mode 100644 middleman-core/fixtures/no-mount-app/source/localizable/hello.html.erb create mode 100644 middleman-core/fixtures/no-mount-app/source/localizable/index.html.erb create mode 100644 middleman-core/fixtures/subset-app/config.rb create mode 100644 middleman-core/fixtures/subset-app/locales/en.yml create mode 100644 middleman-core/fixtures/subset-app/locales/es.yml create mode 100644 middleman-core/fixtures/subset-app/source/layout.erb create mode 100644 middleman-core/fixtures/subset-app/source/localizable/hello.html.erb create mode 100644 middleman-core/fixtures/subset-app/source/localizable/index.html.erb create mode 100644 middleman-core/lib/middleman-core/core_extensions/i18n.rb diff --git a/middleman-core/features/i18n_builder_alt_path.feature b/middleman-core/features/i18n_builder_alt_path.feature new file mode 100644 index 00000000..b4f1c917 --- /dev/null +++ b/middleman-core/features/i18n_builder_alt_path.feature @@ -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" diff --git a/middleman-core/features/i18n_builder_alt_root.feature b/middleman-core/features/i18n_builder_alt_root.feature new file mode 100644 index 00000000..b9cbb7bb --- /dev/null +++ b/middleman-core/features/i18n_builder_alt_root.feature @@ -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" diff --git a/middleman-core/features/i18n_builder_default.feature b/middleman-core/features/i18n_builder_default.feature new file mode 100644 index 00000000..926eb702 --- /dev/null +++ b/middleman-core/features/i18n_builder_default.feature @@ -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" diff --git a/middleman-core/features/i18n_builder_lang_map.feature b/middleman-core/features/i18n_builder_lang_map.feature new file mode 100644 index 00000000..f92af904 --- /dev/null +++ b/middleman-core/features/i18n_builder_lang_map.feature @@ -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" diff --git a/middleman-core/features/i18n_builder_no_mount.feature b/middleman-core/features/i18n_builder_no_mount.feature new file mode 100644 index 00000000..5b628184 --- /dev/null +++ b/middleman-core/features/i18n_builder_no_mount.feature @@ -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" diff --git a/middleman-core/features/i18n_builder_subset.feature b/middleman-core/features/i18n_builder_subset.feature new file mode 100644 index 00000000..444f4349 --- /dev/null +++ b/middleman-core/features/i18n_builder_subset.feature @@ -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" diff --git a/middleman-core/features/i18n_preview_alt_path.feature b/middleman-core/features/i18n_preview_alt_path.feature new file mode 100644 index 00000000..2865fff5 --- /dev/null +++ b/middleman-core/features/i18n_preview_alt_path.feature @@ -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" \ 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 new file mode 100644 index 00000000..f8002e61 --- /dev/null +++ b/middleman-core/features/i18n_preview_alt_root.feature @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_default.feature b/middleman-core/features/i18n_preview_default.feature new file mode 100644 index 00000000..d4645a6d --- /dev/null +++ b/middleman-core/features/i18n_preview_default.feature @@ -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" \ 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 new file mode 100644 index 00000000..cac80125 --- /dev/null +++ b/middleman-core/features/i18n_preview_lang_map.feature @@ -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" \ 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 new file mode 100644 index 00000000..7f03ac59 --- /dev/null +++ b/middleman-core/features/i18n_preview_no_mount.feature @@ -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" \ No newline at end of file diff --git a/middleman-core/features/i18n_preview_subset.feature b/middleman-core/features/i18n_preview_subset.feature new file mode 100644 index 00000000..ff8d91f7 --- /dev/null +++ b/middleman-core/features/i18n_preview_subset.feature @@ -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" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/.mm-pid-4567 b/middleman-core/fixtures/alt-path-app/.mm-pid-4567 new file mode 100644 index 00000000..2aa950e4 --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/.mm-pid-4567 @@ -0,0 +1 @@ +12945 \ 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 new file mode 100644 index 00000000..77d8cbe7 --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/config.rb @@ -0,0 +1,2 @@ +activate :i18n +localize :path => "/lang_:locale/" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/locales/en.yml b/middleman-core/fixtures/alt-path-app/locales/en.yml new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +en: + greetings: "Howdy" + hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/locales/es.yml b/middleman-core/fixtures/alt-path-app/locales/es.yml new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +es: + paths: + hello: "hola" + + greetings: "Como Esta?" + hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/source/layout.erb b/middleman-core/fixtures/alt-path-app/source/layout.erb new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/source/layout.erb @@ -0,0 +1 @@ +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb b/middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/source/localizable/hello.html.erb @@ -0,0 +1 @@ +<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb b/middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/alt-path-app/source/localizable/index.html.erb @@ -0,0 +1 @@ +<%= I18n.t(:greetings) %> \ 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 new file mode 100644 index 00000000..ba5d0195 --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/config.rb @@ -0,0 +1,2 @@ +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 new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +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 new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +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 new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/source/lang_data/hello.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/source/lang_data/index.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/alt-root-app/source/layout.erb @@ -0,0 +1 @@ +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/config.rb b/middleman-core/fixtures/i18n-test-app/config.rb new file mode 100644 index 00000000..d113b9d8 --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/config.rb @@ -0,0 +1,2 @@ +activate :i18n +localize \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/locales/en.yml b/middleman-core/fixtures/i18n-test-app/locales/en.yml new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +en: + greetings: "Howdy" + hi: "Hello" \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/locales/es.yml b/middleman-core/fixtures/i18n-test-app/locales/es.yml new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +es: + paths: + hello: "hola" + + greetings: "Como Esta?" + hi: "Hola" \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/source/layout.erb b/middleman-core/fixtures/i18n-test-app/source/layout.erb new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/source/layout.erb @@ -0,0 +1 @@ +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/source/localizable/hello.html.erb b/middleman-core/fixtures/i18n-test-app/source/localizable/hello.html.erb new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/source/localizable/hello.html.erb @@ -0,0 +1 @@ +<%= I18n.t(:hi) %> World \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-test-app/source/localizable/index.html.erb b/middleman-core/fixtures/i18n-test-app/source/localizable/index.html.erb new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/i18n-test-app/source/localizable/index.html.erb @@ -0,0 +1 @@ +<%= I18n.t(:greetings) %> \ 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 new file mode 100644 index 00000000..fdf8dc29 --- /dev/null +++ b/middleman-core/fixtures/name-map-app/config.rb @@ -0,0 +1,2 @@ +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 new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/name-map-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +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 new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/name-map-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +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 new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/name-map-app/source/layout.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/name-map-app/source/localizable/hello.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/name-map-app/source/localizable/index.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..7e8276ad --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/config.rb @@ -0,0 +1,2 @@ +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 new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +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 new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +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 new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/source/layout.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/source/localizable/hello.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/no-mount-app/source/localizable/index.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..5a8e071c --- /dev/null +++ b/middleman-core/fixtures/subset-app/config.rb @@ -0,0 +1,2 @@ +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 new file mode 100644 index 00000000..91519342 --- /dev/null +++ b/middleman-core/fixtures/subset-app/locales/en.yml @@ -0,0 +1,4 @@ +--- +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 new file mode 100644 index 00000000..06756f3d --- /dev/null +++ b/middleman-core/fixtures/subset-app/locales/es.yml @@ -0,0 +1,7 @@ +--- +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 new file mode 100644 index 00000000..cd9bb66d --- /dev/null +++ b/middleman-core/fixtures/subset-app/source/layout.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..a226480d --- /dev/null +++ b/middleman-core/fixtures/subset-app/source/localizable/hello.html.erb @@ -0,0 +1 @@ +<%= 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 new file mode 100644 index 00000000..c39d59f5 --- /dev/null +++ b/middleman-core/fixtures/subset-app/source/localizable/index.html.erb @@ -0,0 +1 @@ +<%= I18n.t(:greetings) %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb index caca38d9..8fe8fa82 100644 --- a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/extensions.rb b/middleman-core/lib/middleman-core/core_extensions/extensions.rb index 10affbd9..0f1afd43 100644 --- a/middleman-core/lib/middleman-core/core_extensions/extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/extensions.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb new file mode 100644 index 00000000..7253ba36 --- /dev/null +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -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 \ No newline at end of file