Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus Rocha Vieira authored and mlinksva committed Aug 4, 2018
1 parent d247be9 commit 8f31897
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 15 deletions.
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ relative_permalinks: false
markdown: kramdown
url: "https://choosealicense.com"

# See: docs/translations.md
locale: en-US
translations:
en-US:
name: English (US)
url: https://choosealicense.com

collections:
licenses:
output: true
Expand Down
3 changes: 3 additions & 0 deletions _data/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# variables from the repository. These can be used to create accurate copyright
# notices. The available variables are:

- locale:
type: String

- name: fullname
description: The full name or username of the repository owner

Expand Down
28 changes: 28 additions & 0 deletions _data/locale/en-US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
breadcrumb:
home: Home
licenses: Licenses

sidebar:
clipboard: Copy license text to clipboard
how_to_apply: How to apply this license
note: Note
optional: Optional
add: Add
or: or
disallow: to disallow future versions
package: to your project's package description, if applicable
exempli_gratia: e.g.
and: and
ensure: This will ensure the license is displayed in package directories.
source: Source
projects_with_license: Who's using this license?

license_overview:
view_full: View full

footer:
about: About
table_of_contents: Table of Contents
licenses: The content of this site is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">
Creative Commons Attribution 3.0 Unported License</a>
with_love: Curated with &lt;3 by <a href="https://github.com">GitHub, Inc.</a> and <a href="https://github.com/github/choosealicense.com">You!</a>
4 changes: 2 additions & 2 deletions _includes/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<ol>
<li>
{% if page.layout == "license" %}
<a href="/">Home</a> / <a href="/licenses/">Licenses</a>
<a href="/">{{ site.data.locale[site.locale].breadcrumb.home }}</a> / <a href="/licenses/">{{ site.data.locale[site.locale].breadcrumb.licenses }}</a>
{% else %}
<a href="/">Home</a>
<a href="/">{{ site.data.locale[site.locale].breadcrumb.home }}</a>
{% endif %}
</li>
</ol>
Expand Down
9 changes: 4 additions & 5 deletions _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<footer class="site-footer clearfix">
<nav>
<a href="/about/">About</a>
<a href="/terms-of-service/">Terms of Service</a>
<a href="/about/">{{ site.data.locale[site.locale].footer.about }}</a>
<a href="/terms-of-service/">{{ site.data.locale[site.locale].footer.table_of_contents }}</a>
</nav>
<p>
The content of this site is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">
Creative Commons Attribution 3.0 Unported License</a>.
{{ site.data.locale[site.locale].footer.licenses }}
</p>
<div class="with-love">
Curated with &lt;3 by <a href="https://github.com">GitHub, Inc.</a> and <a href="https://github.com/github/choosealicense.com">You!</a>
{{ site.data.locale[site.locale].footer.with_love }}
</div>
</footer>

Expand Down
2 changes: 1 addition & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="{{ site.locale }}">
<head itemscope itemtype="http://schema.org/WebSite">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down
2 changes: 1 addition & 1 deletion _includes/license-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3 class="license-overview-name">
{% endfor %}
</tr>
</table>
<p class="small"><a href="{{ license.url }}">View full {{ license.title }} »</a></p>
<p class="small"><a href="{{ license.url }}">{{ site.data.locale[site.locale].license_overview.view_full }} {{ license.title }} »</a></p>
</div>
</div>
{% endfor %}
12 changes: 6 additions & 6 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<div class="sidebar">

<a href="#" data-clipboard-target="#license-text" data-proofer-ignore="true" class="js-clipboard-button button">Copy license text to clipboard</a>
<a href="#" data-clipboard-target="#license-text" data-proofer-ignore="true" class="js-clipboard-button button">{{ site.data.locale[site.locale].sidebar.clipboard }}</a>

<div class="how-to-apply">
<h3>How to apply this license</h3>
<h3>{{ site.data.locale[site.locale].sidebar.how_to_apply }}</h3>
<p>
{{ page.how | markdownify | remove: '<p>' | remove: '</p>' }}
</p>
{% if page.note %}
<p class="note">
<strong>Note: </strong> {{ page.note | markdownify | remove: '<p>' | remove: '</p>' }}
<strong>{{ site.data.locale[site.locale].sidebar.note }}: </strong> {{ page.note | markdownify | remove: '<p>' | remove: '</p>' }}
</p>
{% endif %}
{% assign xgpl = false %}
{% if page.spdx-id contains 'GPL' %}{% assign xgpl = true %}{% endif %}
<p class="note"><strong>Optional: </strong> Add <strong><code>{{ page.spdx-id }}{% if xgpl %}-or-later{% endif %}</code></strong>{% if xgpl %} (or <strong><code>{{ page.spdx-id }}-only</code></strong> to disallow future versions){% endif %} to your project's package description, if applicable (e.g., <a href="https://docs.npmjs.com/files/package.json#license">Node.js</a>, <a href="http://guides.rubygems.org/specification-reference/#license=">Ruby</a>, and <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata">Rust</a>). This will ensure the license is displayed in package directories.</p>
<p class="note"><strong>{{ site.data.locale[site.locale].sidebar.optional }}: </strong> {{ site.data.locale[site.locale].sidebar.add }} <strong><code>{{ page.spdx-id }}{% if xgpl %}-or-later{% endif %}</code></strong>{% if xgpl %} ({{ site.data.locale[site.locale].sidebar.or }} <strong><code>{{ page.spdx-id }}-only</code></strong> {{ site.data.locale[site.locale].sidebar.disallow }}){% endif %} {{ site.data.locale[site.locale].sidebar.package }} ({{ site.data.locale[site.locale].sidebar.exempli_gratia }}, <a href="https://docs.npmjs.com/files/package.json#license">Node.js</a>, <a href="http://guides.rubygems.org/specification-reference/#license=">Ruby</a>, {{ site.data.locale[site.locale].sidebar.and }} <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata">Rust</a>). {{ site.data.locale[site.locale].sidebar.ensure }}</p>
</div>

{% if page.source %}
<div class="source">
<a href="{{ page.source }}">
<span class="license-sprite"></span>
Source
{{ site.data.locale[site.locale].sidebar.source }}
</a>
</div>
{% endif %}

{% if page.using %}
<div class="projects-with-license">
<h3>Who's using this license?</h3>
<h3>{{ site.data.locale[site.locale].sidebar.projects_with_license }}</h3>
<ul>
{% for using in page.using %}
{% for hash in using %}
Expand Down
45 changes: 45 additions & 0 deletions assets/js/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$(document).ready(function() {
var currentLocale = $('html').attr('lang');

// All available translations
var translations = $('a.locale-chooser');

// Get the preferred locale
var locale = getLocaleFromQuery()
|| getLocaleFromCookie()
|| getLocaleFromBrowser(translations);

// If preferred locale is not the same as the current locale, then set it.
if (locale && locale != currentLocale) {
translations.filter("[lang=" + locale + "]").click();
}

// Set locale when clicking on locale link
translations.on('click', function(event) {
setLocale($(event.target).attr('lang'));
});
});

// Save the preferred locale in a cookie, which will be set on any subdomain.
function setLocale(locale) {
document.cookie = 'locale=' + locale;
}

// Get locale from the `l` parameter of the query string
function getLocaleFromQuery() {
return window.location.search.replace(/.*[?&]l=([^&$]+).*/, '$1');
}

function getLocaleFromCookie() {
return document.cookie.replace(/(?:(?:^|.*;\s*)locale\s*\=\s*([^;]*).*$)|^.*$/, '$1');
}

// Use locale that matches browser's preferred locales
function getLocaleFromBrowser(translations) {
var browserLocales = [].concat(navigator.languages || navigator.userLanguage || navigator.language);
for(var i = 0; i < browserLocales.length; i++) {
if (translations.filter('[lang=' + browserLocales[i] + ']').length) {
return browserLocales[i];
}
}
}

0 comments on commit 8f31897

Please sign in to comment.