Skip to content

Commit 530a344

Browse files
committed
[i18n] Add i18n English / Spanish
Add _data/locales Add articles collections Add defaults to article layout Add jquey.min.js Add select for en / es Add fields.yml for front matter
1 parent 29ce46e commit 530a344

File tree

19 files changed

+212
-14
lines changed

19 files changed

+212
-14
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assets/js/index.js
2+
assets/js/jquery.min.js
3+
assets/js/bpd.js

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
assets/js/jquery.min.js
2+
assets/js/index.js

_articles/es/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
layout: index
3+
title: Comunidad de desarrolladores de Black Python.
4+
lang: es
5+
permalink: /es/
6+
---

_config.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ navigation:
1818
url: /
1919
fa: fa fa-home fa-fw
2020
- text: About Us
21-
url: /about.html
21+
url: /about/
2222
fa: fa fa-info-circle fa-fw
2323
- text: Events
24-
url: /events.html
24+
url: /events/
2525
fa: fa fa-calendar fa-fw
2626
- text: Conferences
27-
url: /conferences.html
27+
url: /conferences/
2828
fa: fa fa-microphone fa-fw
2929
- text: Community
30-
url: /community.html
30+
url: /community/
3131
fa: fa fa-users fa-fw
3232

3333
# Build settings
@@ -38,8 +38,14 @@ plugins:
3838
- github-pages
3939
- jemoji
4040
- jekyll-feed
41+
# - jekyll-seo-tag
42+
# - jekyll-sitemap
4143

4244
exclude:
45+
- bin
46+
- CNAME
47+
- CODE_OF_CONDUCT.md
48+
- CONTRIBUTING.md
4349
- README.md
4450
- Gemfile*
4551
- node_modules
@@ -55,3 +61,21 @@ exclude:
5561
- venv
5662
- .venv
5763
# timezone: America/Toronto
64+
65+
permalink: "/:path/"
66+
67+
collections:
68+
articles:
69+
output: true
70+
permalink: "/:path/"
71+
72+
defaults:
73+
# - scope:
74+
# path: ""
75+
# values:
76+
# image: /assets/images/cards/default.png
77+
- scope:
78+
path: ""
79+
type: articles
80+
values:
81+
layout: article

_data/fields.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Each piece of content has YAML front matter with these properties:
2+
3+
lang:
4+
type: String
5+
6+
layout:
7+
type: String
8+
9+
title:
10+
type: String
11+
required: true
12+
13+
contents:
14+
type: Array
15+
16+
description:
17+
type: String
18+
19+
class:
20+
type: String
21+
22+
order:
23+
type: Integer
24+
25+
image: {}
26+
27+
related:
28+
type: Array
29+
30+
untranslated:
31+
type: TrueClass
32+
33+
redirect_from:
34+
type: String

_data/locales/en.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
en:
2+
locale_name: English
3+
nav:
4+
- Home
5+
- About Us
6+
- Events
7+
- Conferences
8+
- Community
9+
index:
10+
lead: Welcome to Black Python Developers Community.
11+
article:
12+
table_of_contents: Table of Contents
13+
footer:
14+
contribute:
15+
heading: Contribute
16+
description: Want to make a suggestion? This content is open source. Help us improve it.
17+
button: Contribute
18+
subscribe:
19+
heading: Stay in touch
20+
description: Be the first to hear about BPDevs's latest open source tips and resources.
21+
label: Email Address
22+
button: Subscribe

_data/locales/es.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
es:
2+
locale_name: Español
3+
nav:
4+
- Inicio
5+
- Acerca de
6+
- Eventos
7+
- Conferencias
8+
- Comunidad
9+
index:
10+
lead: Bienvenidos a la Comunidad de desarrolladores de Black Python.
11+
article:
12+
table_of_contents: Tabla de contenidos
13+
footer:
14+
contribute:
15+
heading: Contribuir
16+
description: ¿Tienes alguna sugerencia? Este contenido es de código abierto. Ayúdanos a mejorarlo.
17+
button: Contribuir
18+
subscribe:
19+
heading: Suscribirse para novedades
20+
description: Sea el primero en enterarse de los últimos consejos y recursos de código abierto.
21+
label: Dirección de correo
22+
button: Suscribirse

_includes/header.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% assign t = site.data.locales[page.lang][page.lang] %}
12
<header class="site-header" role="banner">
23
<h1 class="site-title"><a class="logo-text" href="/index.html">BPDev</a></h1>
34
<nav class="site-navigation">
@@ -6,11 +7,27 @@ <h1 class="site-title"><a class="logo-text" href="/index.html">BPDev</a></h1>
67
{% for item in site.navigation %} {% assign current = nil %} {% if
78
page.url == item.url %} {% assign current = 'nav-current' %} {% endif %}
89
<li class="menu-item {{ current }}" role="menuitem">
9-
<a class="{{ current }}" href="{{ item.url }}"
10-
><i class="{{ item.fa }}"></i>&nbsp;{{ item.text }}</a
11-
>
10+
<a class="{{ current }}" href="{{ item.url }}">
11+
<i class="{{ item.fa }}"></i>&nbsp;{{ t.nav[forloop.index0] }}
12+
</a>
1213
</li>
13-
{% endfor %}
14+
{% endfor %} {% if page.lang and site.data.locales.size > 1 %}
15+
<li class="menu-item" role="menuitem">
16+
<div class="">
17+
<select id="language" class="form-select">
18+
{% assign locales = site.data.locales | sort %} {% for locale in
19+
locales %} {% assign lang = locale[0] %} {% assign locale_name =
20+
locale[1][lang].locale_name %} {% if page.lang == lang %}
21+
<option value="{{ lang }}" selected="selected">
22+
{{ locale_name }}
23+
</option>
24+
{% else %}
25+
<option value="{{ lang }}">{{ locale_name }}</option>
26+
{% endif %} {% endfor %}
27+
</select>
28+
</div>
29+
</li>
30+
{% endif %}
1431
</ul>
1532
<!-- .menu -->
1633
<button id="menu-close" class="menu-toggle">

_layouts/article.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
layout: default
3+
---
4+
5+
{% assign t = site.data.locales[page.lang][page.lang] %}
6+
7+
<article class="">
8+
<div class="">{{ content }}</div>
9+
</article>

_layouts/default.html

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html lang="{{ page.lang }}">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -30,16 +30,38 @@
3030
href="{{ '/feed.xml' | prepend: site.baseurl | prepend: site.url }}"
3131
/>
3232
<link
33-
rel="shortcut icon"
33+
rel="icon"
3434
href="https://github.com/BlackPythonDevs.png"
3535
type="image/png"
3636
/>
37+
{% if page.lang and page.untranslated != true and site.data.locales.size > 1
38+
%} {% assign locales = site.data.locales | sort %} {% for locale in locales
39+
%} {% assign lang = locale[0] %} {% assign page_lang_slash = page.lang |
40+
append: '/' | prepend: '/' %} {% assign default_url = page.url | replace:
41+
page_lang_slash, '/' %} {% if lang == "en" %}
42+
<link
43+
rel="alternate"
44+
hreflang="en"
45+
href="{{ site.url }}{{ default_url }}"
46+
/>
47+
<link
48+
rel="alternate"
49+
hreflang="x-default"
50+
href="{{ site.url }}{{ default_url }}"
51+
/>
52+
{% else %}
53+
<link
54+
rel="alternate"
55+
hreflang="{{ lang }}"
56+
href="{{ site.url }}/{{ lang }}{{ default_url }}"
57+
/>
58+
{% endif %} {% endfor %} {% endif %}
3759
</head>
3860

3961
<body>
4062
{% include header.html %}
4163
<main role="main">{{ content }}</main>
4264
{% include footer.html %}
43-
<script src="{{ '/assets/js/bpd.js' }}"></script>
65+
<script src="{{ '/assets/js/index.js' | relative_url }}"></script>
4466
</body>
4567
</html>

_layouts/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: default
3+
---
4+
5+
{% assign t = site.data.locales[page.lang][page.lang] %} {% if page.title %} {%
6+
assign header = page.title %} {% else %} {% assign header = site.title %} {%
7+
endif %}
8+
<h1>{{ t.index.lead }}</h1>

about.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: default
3+
lang: en
34
title: About Us
45
---
56

assets/js/bpd.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ if (menuToggle) {
1616
);
1717
}
1818
}
19+
20+
function loadLanguage(lang) {
21+
base_pathname = window.location.pathname.replace(
22+
/\/[a-z]+([_-][a-z]+)?\//,
23+
"/",
24+
);
25+
if (lang === "en") {
26+
url = base_pathname;
27+
} else {
28+
url = "/" + lang + base_pathname;
29+
}
30+
window.location.assign(url);
31+
}
32+
33+
$(document).ready(function () {
34+
$("#language").change(function () {
35+
loadLanguage($("#language option:selected").val());
36+
});
37+
});

assets/js/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
---
3+
4+
{% include_relative jquery.min.js %}
5+
{% include_relative bpd.js %}

assets/js/jquery.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

community.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: default
3+
lang: en
34
title: Community
45
---
56

conferences.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: default
3+
lang: en
34
title: Conferences
45
---
56

events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: default
3+
lang: en
34
title: Events
45
---
56

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
layout: default
2+
layout: index
3+
lang: en
34
title: Home
45
---
5-
6-
<h1>Welcome to {{ site.title }}</h1>

0 commit comments

Comments
 (0)