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 translations for all govuk components #814

Merged
merged 4 commits into from
Jul 28, 2016
Merged
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
8 changes: 4 additions & 4 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def govuk_component_docs
end

def govuk_available_locales
locale_files = Rails.root.join('app', 'views', 'locales', '*.yml')
locale_files = Rails.root.join("config", "locales", "*.yml")
locales = Dir[locale_files].map { |file| File.basename(file, '.yml') }
render :json => locales
end

def govuk_locales
return error_404 unless params[:locale].match(/^[a-z]{2}(-[a-z0-9]{2,3})?$/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That regular expression will allow something like pt-p1p, which ISO-639 are we using and which ISO is that regex trying to accommodate?

https://en.wikipedia.org/wiki/ISO_639

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the internals of the i18n for Rails so not sure, this seems like a sanity check but maybe something like https://github.com/tigrish/iso#tags would be more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bit of a mixture of ISO-639 standards and one or two non-standard locales. I think this is reasonable as a simple check.

render_yaml_as_json("locales", "#{params[:locale]}.yml")
locale_file_path = Rails.root.join("config", "locales", "#{params[:locale]}.yml")
render_yaml_as_json(locale_file_path)
end

NON_LAYOUT_TEMPLATES = %w(
Expand All @@ -50,8 +51,7 @@ def template

private

def render_yaml_as_json(folder, file)
file_path = Rails.root.join('app', 'views', folder, file)
def render_yaml_as_json(file_path)
error_404 and return unless File.exists?(file_path)
render :json => YAML::load_file(file_path)
end
Expand Down
22 changes: 17 additions & 5 deletions app/views/govuk_component/document_footer.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
direction_class = " direction-#{direction}" if local_assigns.include?(:direction)
%>
<div class="govuk-document-footer<%= direction_class %>">
<h2 class="visuallyhidden">Document information</h2>
<h2 class="visuallyhidden">
<%= t("govuk_component.document_footer.document_information", default: "Document information") %>
</h2>
<div class="history-information" id="history">
<% if local_assigns.include?(:published) && published %>
<p>Published: <span class="published definition"><%= published %></span></p>
<p>
<%= t("govuk_component.document_footer.published", default: "Published") %>:
<span class="published definition"><%= published %></span>
</p>
<% end %>
<% if local_assigns.include?(:updated) && updated %>
<p>Updated: <span class="updated definition"><%= updated %></span></p>
<p>
<%= t("govuk_component.document_footer.updated", default: "Updated") %>:
<span class="updated definition"><%= updated %></span>
</p>
<% end %>
<% if other_dates.present? %>
<% other_dates.each do |title, date| %>
Expand All @@ -32,7 +40,9 @@
<% if history.any? %>
<div class="change-notes" data-module="toggle">
<p>
<a href="#full-history" data-controls="full-history" data-expanded="false">+ full page history</a>
<a href="#full-history" data-controls="full-history" data-expanded="false">
+ <%= t("govuk_component.document_footer.full_page_history", default: "full page history") %>
</a>
</p>
<div class="js-hidden" id="full-history"><span class="arrow"></span>
<ol>
Expand All @@ -58,7 +68,9 @@
</p>
<% end %>
<% if part_of.any? %>
<p>Part of: <span class="part-of">
<p>
<%= t("govuk_component.document_footer.part_of", default: "Part of") %>:
<span class="part-of">
<% part_of.each do |definition| %>
<span class="definition">
<%= definition.html_safe %>
Expand Down
54 changes: 45 additions & 9 deletions app/views/govuk_component/government_navigation.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,50 @@

<nav id="proposition-menu" class="no-proposition-name">
<ul id="proposition-links">
<li><a class="<%= 'active' if active == 'departments' %>" href="/government/organisations">Departments</a></li>
<li><a class="<%= 'active' if active == 'worldwide' %>" href="/government/world">Worldwide</a></li>
<li><a class="<%= 'active' if active == 'how-government-works' %>" href="/government/how-government-works">How government works</a></li>
<li><a class="<%= 'active' if active == 'get-involved' %>" href="/government/get-involved">Get involved</a></li>
<li class="clear-child"><a class="<%= 'active' if active == 'policies' %>" href="/government/policies">Policies</a></li>
<li><a class="<%= 'active' if active == 'publications' %>" href="/government/publications">Publications</a></li>
<li><a class="<%= 'active' if active == 'consultations' %>" href="/government/publications?publication_filter_option=consultations">Consultations</a></li>
<li><a class="<%= 'active' if active == 'statistics' %>" href="/government/statistics">Statistics</a></li>
<li><a class="<%= 'active' if active == 'announcements' %>" href="/government/announcements">Announcements</a></li>
<li>
<a class="<%= 'active' if active == 'departments' %>" href="/government/organisations">
<%= t("govuk_component.government_navigation.departments", default: "Departments") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'worldwide' %>" href="/government/world">
<%= t("govuk_component.government_navigation.worldwide", default: "Worldwide") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'how-government-works' %>" href="/government/how-government-works">
<%= t("govuk_component.government_navigation.how-government-works", default: "How government works") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'get-involved' %>" href="/government/get-involved">
<%= t("govuk_component.government_navigation.get-involved", default: "Get involved") %>
</a>
</li>
<li class="clear-child">
<a class="<%= 'active' if active == 'policies' %>" href="/government/policies">
<%= t("govuk_component.government_navigation.policies", default: "Policies") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'publications' %>" href="/government/publications">
<%= t("govuk_component.government_navigation.publications", default: "Publications") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'consultations' %>" href="/government/publications?publication_filter_option=consultations">
<%= t("govuk_component.government_navigation.consultations", default: "Consultations") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'statistics' %>" href="/government/statistics">
<%= t("govuk_component.government_navigation.statistics", default: "Statistics") %>
</a>
</li>
<li>
<a class="<%= 'active' if active == 'announcements' %>" href="/government/announcements">
<%= t("govuk_component.government_navigation.announcements", default: "Announcements") %>
</a>
</li>
</ul>
</nav>
14 changes: 9 additions & 5 deletions app/views/govuk_component/metadata.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@
<dd><%= from.to_sentence.html_safe %></dd>
<% end %>
<% if part_of.any? %>
<dt>Part of:</dt>
<dt><%= t("govuk_component.metadata.part_of", default: "Part of") %>:</dt>
<dd><%= part_of.to_sentence.html_safe %></dd>
<% end %>
<% if local_assigns.include?(:history) %>
<dt>History:</dt>
<dt><%= t("govuk_component.metadata.history", default: "History") %>:</dt>
<dd><%= history %></dd>
<% end %>
<% if local_assigns.include?(:first_published) && first_published %>
<dt>First published:</dt>
<dt><%= t("govuk_component.metadata.first_published", default: "First published") %>:</dt>
<dd><%= first_published %></dd>
<% end %>
<% if local_assigns.include?(:last_updated) && last_updated %>
<dt>Last updated:</dt>
<dt><%= t("govuk_component.metadata.last_updated", default: "Last updated") %>:</dt>
<dd>
<%= last_updated %><% if local_assigns.include?(:see_updates_link) %>, <a href="#history">see all updates</a><% end %>
<%= last_updated %><% if local_assigns.include?(:see_updates_link) %>,
<a href="#history">
<%= t("govuk_component.metadata.see_all_updates", default: "see all updates") %>
</a>
<% end %>
</dd>
<% end %>
<% if other.present? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% if local_assigns.include?(:next_page) || local_assigns.include?(:previous_page) %>
<nav class="govuk-previous-and-next-navigation" role="navigation" aria-label="Pagination">
<nav
class="govuk-previous-and-next-navigation"
role="navigation"
aria-label="<%= t("govuk_component.previous_and_next_navigation.pagination", default: "Pagination") %>"
>
<ul class="group">
<% if local_assigns.include?(:previous_page) %>
<li class="previous-page">
Expand Down
8 changes: 7 additions & 1 deletion app/views/govuk_component/related_items.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
<% if section[:url] %>
<li class="related-items-more">
<a href="<%= section[:url] %>">
More<% if section[:title] %> <span class="visuallyhidden">in <%= section[:title] %></span><% end %>
<%= t("govuk_component.related_items.more", default: "More") %>
<% if section[:title] %>
<span class="visuallyhidden">
<%= t("govuk_component.related_items.in", default: "in") %>
<%= section[:title] %>
</span>
<% end %>
</a>
</li>
<% end %>
Expand Down
4 changes: 0 additions & 4 deletions app/views/locales/en.yml

This file was deleted.

33 changes: 30 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
# Passed to the Frontend app via slimmer, not used by static directly.

en:
hello: "Hello world"
govuk_component:
document_footer:
document_information: "Document information"
published: "Published"
updated: "Updated"
full_page_history: "full page history"
part_of: "Part of"
government_navigation:
departments: "Departments"
worldwide: "Worldwide"
how-government-works: "How government works"
get-involved: "Get involved"
policies: "Policies"
publications: "Publications"
consultations: "Consultations"
statistics: "Statistics"
announcements: "Announcements"
metadata:
from: "From"
part_of: "Part of"
history: "History"
first_published: "First published"
last_updated: "Last updated"
see_all_updates: "see all updates"
previous_and_next_navigation:
pagination: "Pagination"
related_items:
more: "More"
in: "in"
4 changes: 2 additions & 2 deletions test/govuk_component/document_footer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def component_name
}
})

assert_select 'p', text: 'Published: 20 January 2092'
assert_select 'p', text: 'Updated: 22 January 2092'
assert_select 'p', text: /Published:\s+20 January 2092/
assert_select 'p', text: /Updated:\s+22 January 2092/
assert_select 'p', text: 'Date opened: 1 February 2092'
assert_select 'p', text: 'Date closed: 1 March 2093'
end
Expand Down
6 changes: 3 additions & 3 deletions test/govuk_component/related_items_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def component_name
})

assert_select "h2", text: "Section title"
assert_link_with_text_in("ul li:last-child", "/more-link", "More in Section title")
assert_link_with_text_in("ul li:last-child", "/more-link", /More\s+in\s+Section title/)
assert_link_with_text_in("ul li:first-child", "/item", "Item title")
assert_link_with_text_in("ul li:first-child + li", "/other-item", "Other item title")
end
Expand Down Expand Up @@ -65,11 +65,11 @@ def component_name
})

assert_select "h2", text: "Section title"
assert_link_with_text_in("ul li:last-child", "/more-link", "More in Section title")
assert_link_with_text_in("ul li:last-child", "/more-link", /More\s+in\s+Section title/)
assert_link_with_text_in("ul li:first-child", "/item", "Item title")

assert_select "h2", text: "Other section title"
assert_link_with_text_in("ul li:last-child", "/other-more-link", "More in Other section title")
assert_link_with_text_in("ul li:last-child", "/other-more-link", /More\s+in\s+Other section title/)
assert_link_with_text_in("ul li:first-child", "/other-item", "Other item title")
end

Expand Down