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