Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option localizable to separate blog articles per locale #355

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions features/localizable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
Feature: Localizable blog

Scenario: Article list is scoped to a single language
Given the Server is running at "localizable-app"

When I go to "/index.html"
Then I should see "January"
And I should not see "Январь"

When I go to "/ru/index.html"
Then I should see "Январь"
And I should not see "January"


Scenario: Paginated article list is scoped to a single language
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n
activate :blog, localizable: true, permalink: '{title}.html', paginate: true

ignore 'templates/*'
"""

Given the Server is running at "localizable-app"

When I go to "/index.html"
Then I should see "January"
And I should not see "Январь"

When I go to "/ru/index.html"
Then I should see "Январь"
And I should not see "January"


Scenario: Non-default locale article paths are prefixed when mount_at_root is used
Given the Server is running at "localizable-app"

When I go to "/january.html"
Then I should see "January"
And I should not see "Январь"

When I go to "/en/january.html"
Then the status code should be "404"

When I go to "/ru/january.html"
Then I should see "Январь"
And I should not see "January"


Scenario: All article paths are prefixed with locale when mount_at_root is not used
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n, mount_at_root: false
activate :blog, localizable: true, permalink: '{title}.html'

ignore 'templates/*'
"""

Given the Server is running at "localizable-app"

When I go to "/january.html"
Then the status code should be "404"

When I go to "/en/january.html"
Then I should see "January"
And I should not see "Январь"

When I go to "/ru/january.html"
Then I should see "Январь"
And I should not see "January"


Scenario: Paginated tags are separated by locale
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n
activate :blog, localizable: true,
paginate: true,
permalink: '{title}.html',
tag_template: 'templates/tag.html'

ignore 'templates/*'
"""

Given the Server is running at "localizable-app"

When I go to "/tags/month.html"
Then I should see "Tag 'month'"
Then I should see "January"
And I should not see "Январь"

When I go to "/tags/month/page/2.html"
Then I should see "Tag 'month'"
Then I should see "July"
And I should not see "Июль"

When I go to "/ru/tags/winter.html"
Then I should see "Тег 'winter'"
Then I should see "Январь"
And I should not see "January"

When I go to "/ru/tags/month/page/2.html"
Then I should see "Тег 'month'"
Then I should see "Июль"
And I should not see "July"


Scenario: Tags are separated by locale
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n
activate :blog, localizable: true, permalink: '{title}.html', tag_template: 'templates/tag.html'

ignore 'templates/*'
"""

Given the Server is running at "localizable-app"

When I go to "/tags/winter.html"
Then I should see "Tag 'winter'"
Then I should see "January"
And I should not see "Январь"

When I go to "/ru/tags/winter.html"
Then I should see "Тег 'winter'"
Then I should see "Январь"
And I should not see "January"

Scenario: Calendar pages are separated by locale
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n
activate :blog, localizable: true, permalink: '{title}.html', calendar_template: 'templates/calendar.html'

ignore 'templates/*'
"""

Given a successfully built app at "localizable-app"

Then the file "build/2017/01.html" should contain "January 2017"
And the file "build/ru/2017/01.html" should contain "Январь 2017"


Scenario: Tag and Calendar links are separated by locale
Given a fixture app "localizable-app"
And a file named "config.rb" with:
"""
activate :i18n
activate :blog, localizable: true, permalink: '{title}.html', tag_template: 'templates/tag.html', calendar_template: 'templates/calendar.html', layout: 'article'

ignore 'templates/*'
"""

Given the Server is running at "localizable-app"

When I go to "/january.html"
Then I should see "winter - /tags/winter.html"
Then I should see "month - /tags/month.html"
Then I should see "2017 - /2017.html"
Then I should see "1 - /2017/01.html"
Then I should see "1 - /2017/01/01.html"

When I go to "/ru/january.html"
Then I should see "winter - /ru/tags/winter.html"
Then I should see "month - /ru/tags/month.html"
Then I should see "2017 - /ru/2017.html"
Then I should see "1 - /ru/2017/01.html"
Then I should see "2 - /ru/2017/01/02.html"
4 changes: 4 additions & 0 deletions fixtures/localizable-app/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activate :i18n
activate :blog, localizable: true, permalink: '{title}.html'

ignore 'templates/*'
8 changes: 8 additions & 0 deletions fixtures/localizable-app/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
en:
title: International Blog
overview: Overview
tag: Tag
page: Page
previous: Previous
next: Next
8 changes: 8 additions & 0 deletions fixtures/localizable-app/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
ru:
title: Интернациональный Блог
overview: Обзор
tag: Тег
page: Страница
previous: Предыдущий
next: Следующий
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-03-01-march.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: March
tags: spring, month
locale: en
---
<h1>March</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-03-02-march.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Март
tags: spring, month
locale: ru
---
<h1>Март</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-04-01-april.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: April
tags: spring, month
locale: en
---
<h1>April</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-04-02-april.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Апрель
tags: spring, month
locale: ru
---
<h1>Апрель</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-05-01-may.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: May
tags: spring, month
locale: en
---
<h1>May</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-05-02-may.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Май
tags: spring, month
locale: ru
---
<h1>Май</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-06-01-june.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: June
tags: summer, month
locale: en
---
<h1>June</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-06-02-june.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Июнь
tags: summer, month
locale: ru
---
<h1>Июнь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-07-01-july.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: July
tags: summer, month
locale: en
---
<h1>July</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-07-02-july.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Июль
tags: summer, month
locale: ru
---
<h1>Июль</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-08-01-august.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: August
tags: summer, month
locale: en
---
<h1>August</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-08-02-august.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Август
tags: summer, month
locale: ru
---
<h1>Август</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-09-01-september.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: September
tags: autumn, month
locale: en
---
<h1>September</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-09-02-september.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Сентябрь
tags: autumn, month
locale: ru
---
<h1>Сентябрь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-10-01-october.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: October
tags: autumn, month
locale: en
---
<h1>October</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-10-02-october.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Октябрь
tags: autumn, month
locale: ru
---
<h1>Октябрь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-11-01-november.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: November
tags: autumn, month
locale: en
---
<h1>November</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-11-02-november.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Ноябрь
tags: autumn, month
locale: ru
---
<h1>Ноябрь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-12-01-december.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: December
tags: winter, month
locale: en
---
<h1>December</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2016-12-02-december.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Декабрь
tags: winter, month
locale: ru
---
<h1>Декабрь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2017-01-01-january.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: January
tags: winter, month
locale: en
---
<h1>January</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2017-01-02-january.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Январь
tags: winter, month
locale: ru
---
<h1>Январь</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2017-02-01-february.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: February
tags: winter, month
locale: en
---
<h1>February</h1>
6 changes: 6 additions & 0 deletions fixtures/localizable-app/source/2017-02-02-february.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Февраль
tags: winter, month
locale: ru
---
<h1>Февраль</h1>
17 changes: 17 additions & 0 deletions fixtures/localizable-app/source/_article_list.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if paginate && num_pages > 1 %>
<p><%= t(:page) %> <%= page_number %> / <%= num_pages %></p>
<% end %>

<% if paginate && prev_page %>
<p><%= link_to t(:previous), prev_page %></p>
<% end %>

<ul>
<% page_articles.each do |article| %>
<li><%= link_to article.title, article %></li>
<% end %>
</ul>

<% if paginate && next_page %>
<p><%= link_to t(:next), next_page %></p>
<% end %>
13 changes: 13 additions & 0 deletions fixtures/localizable-app/source/layouts/article.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% wrap_layout :layout do %>
<ul>
<% current_article.tags.each do |tag| %>
<li><%= tag %> - <%= tag_path(tag) %></li>
<% end %>
</ul>
<ul>
<li><%= current_article.date.year %> - <%= blog_year_path(current_article.date.year) %></li>
<li><%= current_article.date.month %> - <%= blog_month_path(current_article.date.year, current_article.date.month) %></li>
<li><%= current_article.date.day %> - <%= blog_day_path(current_article.date.year, current_article.date.month, current_article.date.day) %></li>
</ul>
<%= yield %>
<% end %>
Loading