-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from CloudCannon/feat/translated-urls
Ability to translate page URLs
- Loading branch information
Showing
22 changed files
with
424 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "Translated URLs" | ||
nav_title: "Translated URLs" | ||
nav_section: Workflow | ||
weight: 6 | ||
--- | ||
|
||
Rosey URL locale files can contain translated URLs for your website in a given language. | ||
|
||
## Creating translated URL locale files | ||
|
||
Creating URL locale files is not a step performed by Rosey. This part of the translation workflow is left open ended, usually integrating into an existing translation workflow for a company, or being programmatically created by transforming the input URLs. | ||
|
||
Rosey will look for URL locale files alongside the standard locale files. For a file at `rosey/locales/es.json`, Rosey will look for URLs at `rosey/locales/es.urls.json`. | ||
|
||
Locale files should be created based on the base URL file output from the [Rosey generate command](/docs/generate/). For the example base URL file: | ||
|
||
```json | ||
{ | ||
"version": 2, | ||
"keys": { | ||
"index.html": { | ||
"original": "index.html" | ||
}, | ||
"home/index.html": { | ||
"original": "home/index.html" | ||
}, | ||
"posts/hello-world.html": { | ||
"original": "posts/hello-world.html" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The `rosey/locales/ja-jp.urls.json` locale file should match the structure: | ||
|
||
```json | ||
{ | ||
"index.html": { | ||
"original": "index.html", | ||
"value": "index.html" | ||
}, | ||
"home/index.html": { | ||
"original": "home/index.html", | ||
"value": "家/index.html" | ||
}, | ||
"posts/hello-world.html": { | ||
"original": "posts/hello-world.html", | ||
"value": "投稿/こんにちは世界.html" | ||
} | ||
} | ||
``` | ||
|
||
Each of these keys is an object with `original` and `value` strings. The `value` string should contain the translated destination file, and will be used by Rosey when building your final multilingual site. | ||
|
||
The output should always include the `.html` extension. Rosey will remove any trailing `index.html` filename where able. | ||
|
||
All internal links to these files will be updated within the target locale. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
119 changes: 119 additions & 0 deletions
119
rosey/features/build/rosey-build-translated-links.feature
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,119 @@ | ||
Feature: Rosey Translated Links | ||
Background: | ||
Given I have the environment variables: | ||
| ROSEY_SOURCE | dist/site | | ||
| ROSEY_DEST | dist/translated_site | | ||
Given I have a "dist/site/index.html" file with the content: | ||
""" | ||
<html> | ||
<body> | ||
<h1><a href="/posts/hello-world">Hello World</a></h1> | ||
<h2><a href="/posts/hello-world/">Hello World Trailing Slash</a></h2> | ||
<h3><a href="/posts/hello-world/index.html">Hello World Direct Index Link</a></h3> | ||
<h4><a href="posts/hello-world/">Hello World Relative</a></h4> | ||
<h5><a href="/posts/foobar">Foobar</a></h5> | ||
<h6><a href="/posts/foobar/">Foobar Trailing Slash</a></h6> | ||
<h7><a href="/posts/foobar/index.html">Foobar Direct Index Link</a></h7> | ||
</body> | ||
</html> | ||
""" | ||
And I have a "dist/site/posts/hello-world/index.html" file with the content: | ||
""" | ||
<html> | ||
<body> | ||
<h1>Hello</h1> | ||
<h2><a href="/posts/foobar/">Foobar Trailing Slash</a></h2> | ||
</body> | ||
</html> | ||
""" | ||
And I have a "dist/site/posts/foobar/index.html" file with the content: | ||
""" | ||
<html> | ||
<body> | ||
<h1>Hello</h1> | ||
</body> | ||
</html> | ||
""" | ||
And I have a "rosey/locales/cool.json" file with the content: | ||
""" | ||
{} | ||
""" | ||
And I have a "rosey/locales/cool.urls.json" file with the content: | ||
""" | ||
{ | ||
"index.html": { | ||
"original": "index.html", | ||
"value": "index.html" | ||
}, | ||
"posts/hello-world/index.html": { | ||
"original": "posts/hello-world/index.html", | ||
"value": "radical-articles/sup-world/index.html" | ||
}, | ||
"posts/foobar/index.html": { | ||
"original": "posts/foobar/index.html", | ||
"value": "radical-articles/foobar/foobar.html" | ||
} | ||
} | ||
""" | ||
|
||
Scenario: Rosey updates internal links using translation keys | ||
When I run my program with the flags: | ||
| build | | ||
Then I should see a selector 'h1>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/sup-world/ | | ||
| innerText | Hello World | | ||
Then I should see a selector 'h2>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/sup-world/ | | ||
| innerText | Hello World Trailing Slash | | ||
Then I should see a selector 'h3>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/sup-world/ | | ||
| innerText | Hello World Direct Index Link | | ||
Then I should see a selector 'h4>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | posts/hello-world/ | | ||
| innerText | Hello World Relative | | ||
Then I should see a selector 'h5>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/foobar/foobar.html | | ||
| innerText | Foobar | | ||
Then I should see a selector 'h6>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/foobar/foobar.html | | ||
| innerText | Foobar Trailing Slash | | ||
Then I should see a selector 'h7>a' in "dist/translated_site/cool/index.html" with the attributes: | ||
| href | /cool/radical-articles/foobar/foobar.html | | ||
| innerText | Foobar Direct Index Link | | ||
Then I should see a selector 'h2>a' in "dist/translated_site/cool/radical-articles/sup-world/index.html" with the attributes: | ||
| href | /cool/radical-articles/foobar/foobar.html | | ||
| innerText | Foobar Trailing Slash | | ||
|
||
Scenario: Rosey updates meta urls using translation keys | ||
When I run my program with the flags: | ||
| build | | ||
Then I should see a selector 'link' in "dist/translated_site/posts/hello-world/index.html" with the attributes: | ||
| rel | alternate | | ||
| href | /cool/radical-articles/sup-world/ | | ||
| hreflang | cool | | ||
|
||
Then I should see a selector 'link' in "dist/translated_site/en/posts/hello-world/index.html" with the attributes: | ||
| rel | alternate | | ||
| href | /cool/radical-articles/sup-world/ | | ||
| hreflang | cool | | ||
Then I should see a selector 'link' in "dist/translated_site/cool/radical-articles/sup-world/index.html" with the attributes: | ||
| rel | alternate | | ||
| href | /en/posts/hello-world/ | | ||
| hreflang | en | | ||
|
||
Scenario: Rosey generates redirects with translation keys | ||
When I run my program with the flags: | ||
| build | | ||
| --default-language "cool" | | ||
Then I should see a selector 'a' in "dist/translated_site/posts/hello-world/index.html" with the attributes: | ||
| href | /cool/radical-articles/sup-world/ | | ||
| innerText | Click here if you are not redirected. | | ||
|
||
Scenario: Rosey generates canonicals with translation keys | ||
When I run my program with the flags: | ||
| build | | ||
| --default-language "cool" | | ||
Then I should see a selector 'link' in "dist/translated_site/posts/hello-world/index.html" with the attributes: | ||
| rel | canonical | | ||
| href | /cool/radical-articles/sup-world/ | | ||
| hreflang | cool | |
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,31 @@ | ||
Feature: Rosey Generate URLs | ||
Background: | ||
Given I have the environment variables: | ||
| ROSEY_SOURCE | dist/site | | ||
| ROSEY_DEST | dist/translated_site | | ||
|
||
Scenario: Rosey generates a URLs file | ||
Given I have a "dist/site/index.html" file with the content: | ||
""" | ||
<html> | ||
<body> | ||
<p data-rosey="seal">Kiss From A Rose</p> | ||
<p data-rosey="sting">Desert Rose</p> | ||
</body> | ||
</html> | ||
""" | ||
And I have a "dist/site/about/index.html" file with the content: | ||
""" | ||
<html> | ||
<body> | ||
<p data-rosey="seal">Kiss From A Rose</p> | ||
<p data-rosey="seal">Kiss From A Rose</p> | ||
</body> | ||
</html> | ||
""" | ||
When I run my program with the flags: | ||
| generate | | ||
Then I should see "rosey/base.urls.json" containing the values: | ||
| version | int:2 | | ||
| keys.index\.html.original | index.html | | ||
| keys.about/index\.html.original | about/index.html | |
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
Oops, something went wrong.