Add support for localizing UI text with a _data file

This commit is contained in:
Michael Rose 2016-03-09 16:33:27 -05:00
parent 927b3d36ff
commit ea8fb6fe33
7 changed files with 48 additions and 13 deletions

19
_data/ui-text.yml Normal file
View file

@ -0,0 +1,19 @@
# User interface text for localization
locale:
# English (default)
# -----------------
en: &DEFAULT_EN
pagination_previous: "Previous"
pagination_next: "Next"
toc_label: "Overview"
share_on: "Share on"
date_label: "Last Updated:"
related_label: "You May Also Enjoy"
follow_label: "Follow:"
feed_label: "Feed"
powered_by: "Powered by"
en_US:
<<: *DEFAULT_EN
en_UK:
<<: *DEFAULT_EN

View file

@ -16,15 +16,15 @@
<div class="follow">
<ul>
<li><strong>Follow:</strong></li>
<li><strong>{{ site.data.ui-text.locale[site.locale].follow_label }}</strong></li>
{% if site.twitter.username %}
<li><a href="https://twitter.com/{{ site.twitter.username }}"><i class="fa fa-fw fa-twitter"></i> Twitter</a></li>
{% endif %}
{% if site.facebook.username %}
<li><a href="https://facebook.com/{{ site.facebook.username }}"><i class="fa fa-fw fa-facebook"></i> Facebook</a></li>
{% endif %}
<li><a href="{{ base_path }}/feed.xml"><i class="fa fa-fw fa-rss"></i> Feed</a></li>
<li><a href="{{ base_path }}/feed.xml"><i class="fa fa-fw fa-rss"></i> {{ site.data.ui-text.locale[site.locale].feed_label }}</a></li>
</ul>
</div>
<div class="copyright">&copy; {{ site.time | date: '%Y' }} {{ site.name | default: site.title }}. Powered by <a href="http://jekyllrb.com" rel="nofollow">Jekyll</a> using the <a href="https://mademistakes.com/work/minimal-mistakes-jekyll-theme/" rel="nofollow">Minimal Mistakes</a> theme.</div>
<div class="copyright">&copy; {{ site.time | date: '%Y' }} {{ site.name | default: site.title }}. {{ site.data.ui-text.locale[site.locale].powered_by }} <a href="http://jekyllrb.com" rel="nofollow">Jekyll</a> &amp; <a href="https://mademistakes.com/work/minimal-mistakes-jekyll-theme/" rel="nofollow">Minimal Mistakes</a>.</div>

View file

@ -6,9 +6,9 @@
{% comment %} Link for previous page {% endcomment %}
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
<li><a href="{{ base_path }}/" class="btn">Previous</a></li>
<li><a href="{{ base_path }}/" class="btn">{{ site.data.ui-text.locale[site.locale].pagination_previous }}</a></li>
{% else %}
<li><a href="{{ base_path }}/page{{ paginator.previous_page }}/" class="btn">Previous</a></li>
<li><a href="{{ base_path }}/page{{ paginator.previous_page }}/" class="btn">{{ site.data.ui-text.locale[site.locale].pagination_previous }}</a></li>
{% endif %}
{% endif %}
@ -36,10 +36,10 @@
{% if index == paginator.page %}
<li><strong class="current">{{ index }}</strong></li>
{% else %}
{% comment %} Distance from current page and this link {% endcomment %}
{% comment %}Distance from current page and this link{% endcomment %}
{% assign dist = paginator.page | minus: index %}
{% if dist < 0 %}
{% comment %} Distance must be a positive value {% endcomment %}
{% comment %}Distance must be a positive value{% endcomment %}
{% assign dist = 0 | minus: dist %}
{% endif %}
<li><a href="{{ base_path }}/page{{ index }}/">{{ index }}</a></li>
@ -59,7 +59,7 @@
{% comment %}Link next page{% endcomment %}
{% if paginator.next_page %}
<li><a href="{{ base_path }}/page{{ paginator.next_page }}/" class="btn">Next</a></li>
<li><a href="{{ base_path }}/page{{ paginator.next_page }}/" class="btn">{{ site.data.ui-text.locale[site.locale].pagination_next }}</a></li>
{% endif %}
</ul>
</nav>

View file

@ -1,5 +1,5 @@
<div class="social-share">
<h4>Share on</h4>
<h4>{{ site.data.ui-text.locale[site.locale].share_on }}</h4>
<ul>
<li>
<a href="https://twitter.com/intent/tweet?text={{ base_path }}{{ page.url }}" class="twitter" title="Share on Twitter"><i class="fa fa-twitter"></i><span> Twitter</span></a>

View file

@ -1,5 +1,5 @@
<section id="table-of-contents" class="toc">
<header><h3><i class="fa fa-{{ include.icon | default: 'book' }}"></i> {{ include.title | default: "Overview" }}</h3></header>
<header><h3><i class="fa fa-{{ include.icon | default: 'book' }}"></i> {{ include.title | default: site.data.ui-text.locale[site.locale].toc_label }}</h3></header>
<div id="drawer" markdown="1">
* Auto generated table of contents
{:toc}

View file

@ -26,8 +26,10 @@ layout: default
<footer role="contentinfo">
{% if site.share and page.share %}{% include social-share %}{% endif %}
{% if page.date %}
<p class="byline"><strong>{{ page.title }}</strong> was published on <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %d, %Y" }}</time>{% if page.modified %} and last modified on <time datetime="{{ page.modified | date: "%Y-%m-%d" }}">{{ page.modified | date: "%B %d, %Y" }}</time>{% endif %}.</p>
{% if page.modified %}
<p class="byline"><strong>{{ site.data.ui-text.locale[site.locale].date_label }}</strong> <time datetime="{{ page.modified | date: "%Y-%m-%d" }}">{{ page.modified | date: "%B %d, %Y" }}</time></p>
{% elsif page.date %}
<p class="byline"><strong>{{ site.data.ui-text.locale[site.locale].date_label }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %d, %Y" }}</time></p>
{% endif %}
</footer>
</div><!-- /.article-wrap -->
@ -49,7 +51,7 @@ layout: default
{% comment %}<!-- only show related on a post page when not disabled -->{% endcomment %}
{% if page.id and page.related and site.related_posts.size > 0 %}
<div class="related-articles">
<h4>You might also enjoy <small class="pull-right">(<a href="{{ base_path }}/posts/">View all posts</a>)</small></h4>
<h4>{{ site.data.ui-text.locale[site.locale].related_label }}</h4>
<ul>
{% for post in site.related_posts limit:3 %}
<li><a href="{{ base_path }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></li>

View file

@ -0,0 +1,14 @@
---
title: "Post: Modified Date"
modified: 2016-03-09T16:20:02-05:00
categories:
- Post Formats
tags:
- Post Formats
- readability
- standard
---
This post has been updated and should show a modified date if used in a layout.
All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, "Oh, why can't you remain like this for ever!" This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.