Skip to content

Commit 8f31897

Browse files
Matheus Rocha Vieiramlinksva
authored andcommitted
i18n
1 parent d247be9 commit 8f31897

File tree

9 files changed

+97
-15
lines changed

9 files changed

+97
-15
lines changed

_config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ relative_permalinks: false
55
markdown: kramdown
66
url: "https://choosealicense.com"
77

8+
# See: docs/translations.md
9+
locale: en-US
10+
translations:
11+
en-US:
12+
name: English (US)
13+
url: https://choosealicense.com
14+
815
collections:
916
licenses:
1017
output: true

_data/fields.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# variables from the repository. These can be used to create accurate copyright
55
# notices. The available variables are:
66

7+
- locale:
8+
type: String
9+
710
- name: fullname
811
description: The full name or username of the repository owner
912

_data/locale/en-US.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
breadcrumb:
2+
home: Home
3+
licenses: Licenses
4+
5+
sidebar:
6+
clipboard: Copy license text to clipboard
7+
how_to_apply: How to apply this license
8+
note: Note
9+
optional: Optional
10+
add: Add
11+
or: or
12+
disallow: to disallow future versions
13+
package: to your project's package description, if applicable
14+
exempli_gratia: e.g.
15+
and: and
16+
ensure: This will ensure the license is displayed in package directories.
17+
source: Source
18+
projects_with_license: Who's using this license?
19+
20+
license_overview:
21+
view_full: View full
22+
23+
footer:
24+
about: About
25+
table_of_contents: Table of Contents
26+
licenses: The content of this site is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">
27+
Creative Commons Attribution 3.0 Unported License</a>
28+
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>

_includes/breadcrumbs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<ol>
33
<li>
44
{% if page.layout == "license" %}
5-
<a href="/">Home</a> / <a href="/licenses/">Licenses</a>
5+
<a href="/">{{ site.data.locale[site.locale].breadcrumb.home }}</a> / <a href="/licenses/">{{ site.data.locale[site.locale].breadcrumb.licenses }}</a>
66
{% else %}
7-
<a href="/">Home</a>
7+
<a href="/">{{ site.data.locale[site.locale].breadcrumb.home }}</a>
88
{% endif %}
99
</li>
1010
</ol>

_includes/footer.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<footer class="site-footer clearfix">
22
<nav>
3-
<a href="/about/">About</a>
4-
<a href="/terms-of-service/">Terms of Service</a>
3+
<a href="/about/">{{ site.data.locale[site.locale].footer.about }}</a>
4+
<a href="/terms-of-service/">{{ site.data.locale[site.locale].footer.table_of_contents }}</a>
55
</nav>
66
<p>
7-
The content of this site is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">
8-
Creative Commons Attribution 3.0 Unported License</a>.
7+
{{ site.data.locale[site.locale].footer.licenses }}
98
</p>
109
<div class="with-love">
11-
Curated with &lt;3 by <a href="https://github.com">GitHub, Inc.</a> and <a href="https://github.com/github/choosealicense.com">You!</a>
10+
{{ site.data.locale[site.locale].footer.with_love }}
1211
</div>
1312
</footer>
1413

_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="{{ site.locale }}">
33
<head itemscope itemtype="http://schema.org/WebSite">
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">

_includes/license-overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3 class="license-overview-name">
4343
{% endfor %}
4444
</tr>
4545
</table>
46-
<p class="small"><a href="{{ license.url }}">View full {{ license.title }} »</a></p>
46+
<p class="small"><a href="{{ license.url }}">{{ site.data.locale[site.locale].license_overview.view_full }} {{ license.title }} »</a></p>
4747
</div>
4848
</div>
4949
{% endfor %}

_includes/sidebar.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
<div class="sidebar">
22

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

55
<div class="how-to-apply">
6-
<h3>How to apply this license</h3>
6+
<h3>{{ site.data.locale[site.locale].sidebar.how_to_apply }}</h3>
77
<p>
88
{{ page.how | markdownify | remove: '<p>' | remove: '</p>' }}
99
</p>
1010
{% if page.note %}
1111
<p class="note">
12-
<strong>Note: </strong> {{ page.note | markdownify | remove: '<p>' | remove: '</p>' }}
12+
<strong>{{ site.data.locale[site.locale].sidebar.note }}: </strong> {{ page.note | markdownify | remove: '<p>' | remove: '</p>' }}
1313
</p>
1414
{% endif %}
1515
{% assign xgpl = false %}
1616
{% if page.spdx-id contains 'GPL' %}{% assign xgpl = true %}{% endif %}
17-
<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>
17+
<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>
1818
</div>
1919

2020
{% if page.source %}
2121
<div class="source">
2222
<a href="{{ page.source }}">
2323
<span class="license-sprite"></span>
24-
Source
24+
{{ site.data.locale[site.locale].sidebar.source }}
2525
</a>
2626
</div>
2727
{% endif %}
2828

2929
{% if page.using %}
3030
<div class="projects-with-license">
31-
<h3>Who's using this license?</h3>
31+
<h3>{{ site.data.locale[site.locale].sidebar.projects_with_license }}</h3>
3232
<ul>
3333
{% for using in page.using %}
3434
{% for hash in using %}

assets/js/locale.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
$(document).ready(function() {
2+
var currentLocale = $('html').attr('lang');
3+
4+
// All available translations
5+
var translations = $('a.locale-chooser');
6+
7+
// Get the preferred locale
8+
var locale = getLocaleFromQuery()
9+
|| getLocaleFromCookie()
10+
|| getLocaleFromBrowser(translations);
11+
12+
// If preferred locale is not the same as the current locale, then set it.
13+
if (locale && locale != currentLocale) {
14+
translations.filter("[lang=" + locale + "]").click();
15+
}
16+
17+
// Set locale when clicking on locale link
18+
translations.on('click', function(event) {
19+
setLocale($(event.target).attr('lang'));
20+
});
21+
});
22+
23+
// Save the preferred locale in a cookie, which will be set on any subdomain.
24+
function setLocale(locale) {
25+
document.cookie = 'locale=' + locale;
26+
}
27+
28+
// Get locale from the `l` parameter of the query string
29+
function getLocaleFromQuery() {
30+
return window.location.search.replace(/.*[?&]l=([^&$]+).*/, '$1');
31+
}
32+
33+
function getLocaleFromCookie() {
34+
return document.cookie.replace(/(?:(?:^|.*;\s*)locale\s*\=\s*([^;]*).*$)|^.*$/, '$1');
35+
}
36+
37+
// Use locale that matches browser's preferred locales
38+
function getLocaleFromBrowser(translations) {
39+
var browserLocales = [].concat(navigator.languages || navigator.userLanguage || navigator.language);
40+
for(var i = 0; i < browserLocales.length; i++) {
41+
if (translations.filter('[lang=' + browserLocales[i] + ']').length) {
42+
return browserLocales[i];
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)