Skip to content

Commit

Permalink
Force English for metadata
Browse files Browse the repository at this point in the history
On translated pages we are largely failing to translate the metadata,
leading to messy strings where the only translated content is the month
or the word "and" amongst otherwise English sentences.

This change sets the locale to English for the dates, and reverts attempts
to translate other sections of the page, and it marks the components
as being in English. It removes classnames that aren't used from the CSS
and forces the text direction to be left-to-right for these components.

This marks the page up more semantically, and supports a better experience
for screenreader users as they can now context switch the language
appropriately.
  • Loading branch information
maxgds committed Jul 18, 2019
1 parent 7fcff34 commit 2017156
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_published-dates.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.app-c-published-dates {
@include core-16;
direction: ltr;
}

.app-c-published-dates__toggle {
Expand Down
15 changes: 1 addition & 14 deletions app/assets/stylesheets/components/_publisher-metadata.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.app-c-publisher-metadata {
@include responsive-bottom-margin;
@include core-16;
direction: ltr;
padding-top: govuk-spacing(3);
}

Expand All @@ -11,20 +12,6 @@
.app-c-publisher-metadata__term {
float: left;
padding-right: govuk-spacing(1);

.direction-rtl & {
float: none;
display: inline-block;
padding-right: 0;
padding-left: 5px;
}
}

.app-c-publisher-metadata__definition {
.direction-rtl & {
float: none;
display: inline-block;
}
}

.app-c-publisher-metadata__toggle,
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def cache_control_public?
private

def display_date(timestamp, format = "%-d %B %Y")
I18n.l(Time.zone.parse(timestamp), format: format) if timestamp
I18n.l(Time.zone.parse(timestamp), format: format, locale: 'en') if timestamp
end

def sorted_locales(translations)
Expand Down
11 changes: 5 additions & 6 deletions app/views/components/_published-dates.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
history_class = "app-c-published-dates--history" if history.any?
%>
<% if published || last_updated %>
<div class="app-c-published-dates <%= history_class %>" <% if history.any? %>id="history" data-module="toggle"<% end %>>
<div class="app-c-published-dates <%= history_class %>" <% if history.any? %>id="history" data-module="toggle"<% end %> lang="en">
<% if published %>
<%= t('components.published_dates.published', date: published) %>
Published <%= published %>
<% end %>
<% if last_updated %>
<% if published %><br /><% end %><%= t('components.published_dates.last_updated', date: last_updated) %>
<% if published %><br /><% end %>Last updated <%= last_updated %>
<% if link_to_history && history.empty? %>
&mdash; <a href="#history"><%= t('components.published_dates.see_all_updates') %></a>
&mdash; <a href="#history"><%= t('components.published_dates.see_all_updates', locale: :en) %></a>
<% elsif history.any? %>
<a href="#full-history"
class="app-c-published-dates__toggle"
data-controls="full-history"
data-expanded="false"
data-toggled-text="&#45;&nbsp;<%= t('components.published_dates.hide_all_updates') %>">&#43;&nbsp;<%= t('components.published_dates.show_all_updates')
%></a>
data-toggled-text="&#45;&nbsp;<%= t('components.published_dates.hide_all_updates', locale: :en) %>">&#43;&nbsp;<%= t('components.published_dates.show_all_updates', locale: :en) %></a>
<div class="app-c-published-dates__change-history js-hidden" id="full-history">
<ol>
<% history.each do |change| %>
Expand Down
12 changes: 5 additions & 7 deletions app/views/components/_publisher-metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
metadata = [published, last_updated]
%>
<% if metadata.any? || other_has_values %>
<div class="app-c-publisher-metadata">
<div class="app-c-publisher-metadata" lang="en">
<%= render 'components/published-dates', published: published, last_updated: last_updated, link_to_history: link_to_history %>
<% if other_has_values %>
<div class="app-c-publisher-metadata__other">
Expand All @@ -20,15 +20,13 @@
%>
<% if values.any? %>
<dt class="app-c-publisher-metadata__term">
<%= t(title.to_s.parameterize(separator: '_'),
scope: 'components.publisher_metadata',
default: title.to_s.humanize) %>:
<%= title.to_s.humanize %>:
</dt>
<dd class="app-c-publisher-metadata__definition" data-module="gem-toggle">
<% if title.to_sym == :collections %>
<% if values.size <= 2 %>
<span class="app-c-publisher-metadata__definition-sentence">
<%= values.take(2).to_sentence.html_safe %>
<%= values.take(2).to_sentence(locale: :en).html_safe %>
</span>
<% else %>
<% featured_value, *other_values = values %>
Expand All @@ -42,11 +40,11 @@
data-toggled-text="&minus; <%= t('components.publisher_metadata.hide_all') %>">
+ <%= t('components.publisher_metadata.show_all') %>
</a>
<span id="<%= toggle_id %>" class="js-hidden"><%= other_values.to_sentence.html_safe %></span>
<span id="<%= toggle_id %>" class="js-hidden"><%= other_values.to_sentence(locale: :en).html_safe %></span>
<% end %>
<% else %>
<span class="app-c-publisher-metadata__definition-sentence">
<%= values.to_sentence.html_safe %>
<%= values.to_sentence(locale: :en).html_safe %>
</span>
<% end %>
</dd>
Expand Down

0 comments on commit 2017156

Please sign in to comment.