-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved locale routing based on filenames or special front matter (#414
) * Process filename-based locale content and multi-locale output generation * Add tests for locale features * Fix test descriptions * Fix permalink feature tests
- Loading branch information
1 parent
1cc9a21
commit 75ba507
Showing
13 changed files
with
173 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: "Multi-locale page" | ||
locale_overrides: | ||
fr: | ||
title: "Sur mesure" | ||
locale: multi | ||
--- | ||
|
||
{% if site.locale == "en" %}English:{% elsif site.locale == "fr" %}French:{% endif %} {{ resource.data.title }} |
7 changes: 7 additions & 0 deletions
7
bridgetown-core/test/resources/src/_pages/second-level-page.en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
~~~ruby | ||
{ title: "I'm a Second Level Page" } | ||
~~~ | ||
|
||
That's **nice**. | ||
|
||
Locale: {{ resource.data.locale }} |
7 changes: 7 additions & 0 deletions
7
bridgetown-core/test/resources/src/_pages/second-level-page.fr.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
~~~ruby | ||
{ title: "I'm a Second Level Page in French" } | ||
~~~ | ||
|
||
C'est **bien**. | ||
|
||
Locale: {{ resource.data.locale }} |
5 changes: 0 additions & 5 deletions
5
bridgetown-core/test/resources/src/_pages/second-level-page.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require "helper" | ||
|
||
class TestLocales < BridgetownUnitTest | ||
context "similar pages in different locales" do | ||
setup do | ||
@site = resources_site | ||
@site.process | ||
# @type [Bridgetown::Resource::Base] | ||
@english_resource = @site.collections.pages.resources.find do |page| | ||
page.relative_path.to_s == "_pages/second-level-page.en.md" | ||
end | ||
@french_resource = @site.collections.pages.resources.find do |page| | ||
page.relative_path.to_s == "_pages/second-level-page.fr.md" | ||
end | ||
end | ||
|
||
should "have the correct permalink and locale in English" do | ||
assert_equal "/second-level-page/", @english_resource.relative_url | ||
assert_includes @english_resource.output, "<p>Locale: en</p>" | ||
end | ||
|
||
should "have the correct permalink and locale in French" do | ||
assert_equal "/fr/second-level-page/", @french_resource.relative_url | ||
assert_includes @french_resource.output, "<p>C’est <strong>bien</strong>.</p>\n\n<p>Locale: fr</p>" | ||
end | ||
end | ||
|
||
context "one page which is generated into multiple locales" do | ||
setup do | ||
@site = resources_site | ||
@site.process | ||
# @type [Bridgetown::Resource::Base] | ||
@resources = @site.collections.pages.resources.select do |page| | ||
page.relative_path.to_s == "_pages/multi-page.md" | ||
end | ||
@english_resource = @resources.find { |page| page.data.locale == :en } | ||
@french_resource = @resources.find { |page| page.data.locale == :fr } | ||
end | ||
|
||
should "have the correct permalink and locale in English" do | ||
assert_equal "/multi-page/", @english_resource.relative_url | ||
assert_includes @english_resource.output, "<p>English: Multi-locale page</p>" | ||
end | ||
|
||
should "have the correct permalink and locale in French" do | ||
assert_equal "/fr/multi-page/", @french_resource.relative_url | ||
assert_includes @french_resource.output, "<p>French: Sur mesure</p>" | ||
end | ||
end | ||
end |
Oops, something went wrong.