Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multi-language support (take 2) #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,33 @@ taxonomies = [
{name = "tags", feed = true},
]

[translations]
tags = "Tags"
categories = "Categories"
url = "$BASE_URL"
name = "eng"
lang_kor = "Korean"

[languages.kor]
generate_feed = true

taxonomies = [
{name = "categories", feed = true},
{name = "tags", feed = true},
]

[languages.kor.translations]
tags = "태그"
categories = "범주"
url = "$BASE_URL/kor"
name = "한국어"
trans_key = "lang_kor"

[extra]
author = "Vincent"
after_dark_menu = [
{url = "$BASE_URL", name = "Home"},
{url = "$BASE_URL/categories", name = "Categories"},
{url = "$BASE_URL/tags", name = "Tags"},
{url = "$LANG_BASE_URL", name = "Home"},
{url = "$LANG_BASE_URL/categories", trans_key = "categories"},
{url = "$LANG_BASE_URL/tags", trans_key = "tags"},
]
after_dark_title = "My blog"
3 changes: 3 additions & 0 deletions content/_index.kor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
+++
paginate_by = 5
+++
10 changes: 10 additions & 0 deletions content/some-article.kor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
+++
title = "구텐베르크는 무엇인가"
date = 2017-09-24

[taxonomies]
categories = ["세계 안녕"]
tags = ["러스트"]
+++

글이 여기서 나온다
30 changes: 26 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,38 @@
</head>

<body class="hack dark main container">
{% set lang_base_url = get_url(path="", lang=lang) %}
{% block content %}
{% block header %}
{% if config.extra.after_dark_menu %}
{% if config.extra.after_dark_menu or config.languages %}
<header>
<nav itemscope itemtype="http://schema.org/SiteNavigationElement">
{% if config.languages %}
<div style="float: right">
<!-- does not show the current language -->
{% for key, value in config.languages %}
{% set_global lang_url = value.translations.url | safe | replace(from="$BASE_URL", to=config.base_url) | replace(from="$LANG_BASE_URL", to=lang_base_url) %}
<!-- check to see if the language has a translation of the current article -->
{% if page %}
{%for ea_translation in page.translations%}
{%if ea_translation.lang == key%}
{% set_global lang_url = ea_translation.permalink %}
{%endif%}
{% endfor %}
{% elif taxonomy.slug %}
{% set_global lang_url = value.translations.url ~ `/` ~ taxonomy.slug | safe | replace(from="$BASE_URL", to=config.base_url) | replace(from="$LANG_BASE_URL", to=lang_base_url) %}
{% endif %}
<a itemprop="url"
href="{{lang_url}}">
<span itemprop="name">{% if value.translations.trans_key %}{{ trans(key=value.translations.trans_key, lang=lang) }}{% else %}{{ value.translations.name }}{% endif %}</span></a>
{% endfor %}
</div>
{% endif %}
{% for item in config.extra.after_dark_menu %}
<a itemprop="url"
class="{% if item.url | replace(from="$BASE_URL", to=config.base_url) == current_url %}active{% endif %}"
href="{{ item.url | safe | replace(from="$BASE_URL", to=config.base_url) | safe }}">
<span itemprop="name">{{ item.name }}</span></a>
class="{% if item.url | replace(from="$BASE_URL", to=config.base_url) | replace(from="$LANG_BASE_URL", to=lang_base_url) == current_url %}active{% endif %}"
href="{{ item.url | safe | replace(from="$BASE_URL", to=config.base_url) | replace(from="$LANG_BASE_URL", to=lang_base_url) | safe }}">
<span itemprop="name">{% if item.trans_key %}{{ trans(key=item.trans_key, lang=lang) }}{% else %}{{ item.name }}{% endif %}</span></a>
{% endfor %}
</nav>
</header>
Expand Down
4 changes: 2 additions & 2 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ <h1 itemprop="headline">{{ page.title }}</h1>
{% endif %}
{% if page.taxonomies.categories %}
{% set category = page.taxonomies.categories[0] %}
in <a href="{{ get_taxonomy_url(kind="categories", name=category) | safe }}">{{ category }}</a>
in <a href="{{ get_taxonomy_url(kind="categories", name=category, lang=page.lang) | safe }}">{{ category }}</a>
jaxter184 marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}
{% if page.taxonomies.tags %}
{% if page.taxonomies.categories %}and{% endif %}
tagged
{% for tag in page.taxonomies.tags %}
<a href="{{ get_taxonomy_url(kind="tags", name=tag) | safe }}">{{ tag }}</a>
<a href="{{ get_taxonomy_url(kind="tags", name=tag, lang=page.lang) | safe }}">{{ tag }}</a>
{% if page.taxonomies.tags | length > 1 %}
{% if loop.index != page.taxonomies.tags | length %}
{% if loop.index == page.taxonomies.tags | length - 1 %}
Expand Down
2 changes: 1 addition & 1 deletion templates/tags/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ super() }}
{% endblock header %}

<h1>Tags</h1>
<h1>{% if config.languages | length > 0 %}{{ trans(key="tags", lang=lang) }}{% else %}Tags{% endif %}</h1>

{% if terms %}
<ul>
Expand Down