Skip to content

Commit

Permalink
feat: add multilingual mode support (#241)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:  Layout file renamed ´layouts/partials/page-footer.html → layouts/partials/menu-nextprev.html`. If you use overrides, you might need to change the filenames as well.
  • Loading branch information
xoxys authored Jan 23, 2022
1 parent 42ebf06 commit 5c22ce5
Show file tree
Hide file tree
Showing 88 changed files with 437 additions and 144 deletions.
1 change: 1 addition & 0 deletions .dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ KaTeX
katex
Theming
Favicon[s]?
UI
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
/lhci_reports/
/exampleSite/themes/
/exampleSite/public/
/exampleSite/config/development/
CHANGELOG.md

# translation envs
exampleSite/content/de

# auto-generated files
/data/
/static/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
baseURL: https://geekdocs.de/
title: Geekdocs
theme: hugo-geekdoc

pygmentsUseClasses: true
pygmentsCodeFences: true
timeout: 180000
pluralizeListTitles: false

defaultContentLanguage: en

disablePathToLower: true
enableGitInfo: true

Expand Down Expand Up @@ -34,19 +37,3 @@ outputs:
- HTML
term:
- HTML

params:
geekdocToC: 3
geekdocTagsToMenu: true

geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc
geekdocEditPath: edit/main/exampleSite/content

geekdocSearch: true
geekdocSearchShowParent: true

geekdocLegalNotice: https://thegeeklab.de/legal-notice/#contact-information
geekdocPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy

geekdocImageLazyLoading: true
geekdocDarkModeDim: true
5 changes: 5 additions & 0 deletions exampleSite/config/_default/languages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
en:
languageName: "English"
contentDir: "content/en"
weight: 10
15 changes: 15 additions & 0 deletions exampleSite/config/_default/params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
geekdocToC: 3
geekdocTagsToMenu: true

geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc
geekdocEditPath: edit/main/exampleSite/content

geekdocSearch: true
geekdocSearchShowParent: true

geekdocLegalNotice: https://thegeeklab.de/legal-notice/#contact-information
geekdocPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy

geekdocImageLazyLoading: true
geekdocDarkModeDim: true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions exampleSite/content/en/features/multilingual/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: Multilingual
resources:
- name: translation-available
src: images/translation-available.png
title: ""
---

{{< toc >}}

Hugo supports the creation of websites with multiple languages. In this post we will explain how to get configure Multilingual Mode with this theme.

## Configuration

### Languages

You need to set a default language and configure at least two different languages used by your site to your configuration file at `config.toml`:

```Toml
defaultContentLanguage = "en"

[languages.en]
languageName = "English"
contentDir = "content/en"
weight = 10

[languages.de]
languageName = "German"
contentDir = "content/de"
weight = 20
```

### Translation Strings

To customize translation strings used by the theme you can create a file `i18n/<languagecode>.toml` for every language you want to use e.g. `i18n/en.toml`. You can lookup all used strings in the [default](https://github.com/thegeeklab/hugo-geekdoc/blob/main/i18n/en.yaml) translation file.

### Menus

For the [Bundle Menu](/usage/menus/#bundle-menu) as well as for the [Extra Header Menu](/usage/menus/#extra-header-menu) you can translate the name within the data file of the menu:

```YAML
---
more:
# If `name` is a text, this text will be used as name for each language.
- name: News
ref: "/#"
icon: "gdoc_notification"
# To translate the name you can add a sub-item per language. Important: If you miss a language key
# that is configured in the languages list of your `config.toml` the name will be empty for this language!
- name:
en: Releases
de: Veröffentlichung
ref: "https://github.com/thegeeklab/hugo-geekdoc/releases"
external: true
icon: "gdoc_download"
```
## Add Content
To translate your content you need to create a directory `content/<languagecode>/` for each language you want to use e.g. `content/en/`. This language directories will hold the translated pages for the particular language.

## Switch Content

If you have configured at least two different languages, the language switcher will be enabled in the UI automatically. The switcher is as part of the header menu and displayed on all pages.

{{< columns >}}

[![Beach Color Palette](images/translation-available.png)](images/translation-available.png)

On pages for which a translation is available it will be displayed in the selection list and links to the translated page.

<--->

[![Beach Color Palette](images/translation-not-available.png)](images/translation-not-available.png)

Pages without a translation will be displayed in the selection list as well but are marked with an asterisk and link to the start page of the respective language.

{{< /columns >}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ The Columns shortcode can be used to organize content side-by-side (horizontally

```html
{{</* columns */>}} <!-- begin columns block -->
# Left Content
## Left Content
Dolor sit, sumo unique argument um no ...

<---> <!-- magic separator, between columns -->

# Mid Content
## Mid Content
Dolor sit, sumo unique argument um no ...

<---> <!-- magic separator, between columns -->

# Right Content
## Right Content
Dolor sit, sumo unique argument um no ...
{{</* /columns */>}}
```
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ This method can be used to include source code files and keep them automatically

<!-- prettier-ignore -->
```tpl
{{</* include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
{{</* include file="config/_default/config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
```

Result:

<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" >}}
{{< include file="config/_default/config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ enableRobotsTXT = true
# You can also specify this parameter per page in front matter.
geekdocBreadcrumb = false

# (Optional, default none) Set source repository location. Used for 'Edit this page' links.
# (Optional, default none) Set source repository location. Used for 'Edit page' links.
# You can also specify this parameter per page in front matter.
geekdocRepo = "https://github.com/thegeeklab/hugo"

# (Optional, default none) Enable 'Edit this page' links. Requires 'GeekdocRepo' param
# (Optional, default none) Enable 'Edit page' links. Requires 'GeekdocRepo' param
# and path must point to 'content' directory of repo.
# You can also specify this parameter per page in front matter.
geekdocEditPath = "edit/main/exampleSite/content"
Expand Down Expand Up @@ -174,11 +174,11 @@ params:
# You can also specify this parameter per page in front matter.
geekdocBreadcrumb: false

# (Optional, default none) Set source repository location. Used for 'Edit this page' links.
# (Optional, default none) Set source repository location. Used for 'Edit page' links.
# You can also specify this parameter per page in front matter.
geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc"

# (Optional, default none) Enable "Edit this page" links. Requires 'GeekdocRepo' param
# (Optional, default none) Enable "Edit page" links. Requires 'GeekdocRepo' param
# and path must point to 'content' directory of repo.
# You can also specify this parameter per page in front matter.
geekdocEditPath: edit/main/exampleSite/content
Expand Down Expand Up @@ -262,11 +262,11 @@ geekdocBreadcrumb = false
# Set source repository location.
geekdocRepo = "https://github.com/thegeeklab/hugo-geekdoc"

# Enable "Edit this page" links. Requires 'GeekdocRepo' param and path must point
# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point
# to 'content' directory of repo.
geekdocEditPath = "edit/main/exampleSite/content"

# Used for 'Edit this page' link, set to '.File.Path' by default.
# Used for 'Edit page' link, set to '.File.Path' by default.
# Can be overwritten by a path relative to 'geekdocEditPath'
geekdocFilePath =

Expand Down Expand Up @@ -322,11 +322,11 @@ geekdocBreadcrumb: false
# Set source repository location.
geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc"

# Enable "Edit this page" links. Requires 'GeekdocRepo' param and path must point
# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point
# to 'content' directory of repo.
geekdocEditPath: "edit/main/exampleSite/content"

# Used for 'Edit this page' link, set to '.File.Path' by default.
# Used for 'Edit page' link, set to '.File.Path' by default.
# Can be overwritten by a path relative to 'geekdocEditPath'
geekdocFilePath:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ content/

## Bundle menu

This type of navigation needs to be enabled first by setting `geekdocMenuBundle` to `true` in your [site configuration](/usage/configuration/#site-configuration). After you have activated the bundle menu, you start with an empty navigation. This is intentional because bundle menus have to be defined manually in a data file. While this increases the effort it also offers maximum flexibility in the design. The data file needs to be written in YAML and placed at `data/menu/main.yml`.
This type of navigation needs to be enabled first by setting `geekdocMenuBundle` to `true` in your [site configuration](/usage/configuration/#site-configuration). After you have activated the bundle menu, you start with an empty navigation. This is intentional because bundle menus have to be defined manually in a data file. While this increases the effort it also offers maximum flexibility in the design. The data file needs to be written in YAML and placed at `data/menu/main.yaml`.

**Example:**

Expand Down Expand Up @@ -73,7 +73,7 @@ As an advantage you can add [icons](/features/icon-sets/) to your menu entries e
The more menu is special type of the bundle menu and can be combined with the default file-tree menu.
{{< /hint >}}

As this is a special type of the bundle menu it is basically working in the same way. To enable it just add a data file to `data/menu/more.yml`. The more menu will also work with the file-tree menu and therefor **don't need to be enabled** by the `geekdocMenuBundle` parameter.
As this is a special type of the bundle menu it is basically working in the same way. To enable it just add a data file to `data/menu/more.yaml`. The more menu will also work with the file-tree menu and therefor **don't need to be enabled** by the `geekdocMenuBundle` parameter.

**Example:**

Expand All @@ -97,7 +97,7 @@ more:

## Extra Header Menu

If you want to customize the header menu, this can be achieved by using a data file written in YAML and placed at `data/menu/extra.yml`.
If you want to customize the header menu, this can be achieved by using a data file written in YAML and placed at `data/menu/extra.yaml`.

**Example:**

Expand Down
2 changes: 1 addition & 1 deletion exampleSite/data/menu/more.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ more:
ref: "https://github.com/thegeeklab/hugo-geekdoc/releases"
external: true
icon: "gdoc_download"
- name: "View Source"
- name: View Source
ref: "https://github.com/thegeeklab/hugo-geekdoc"
external: true
icon: "gdoc_github"
39 changes: 39 additions & 0 deletions i18n/de.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
edit_page: Seite bearbeiten

nav_navigation: Navigation
nav_tags: Tags
nav_more: Weitere
nav_top: Nach oben

form_placeholder_search: Suchen

error_page_title: Verlaufen? Keine Sorge
error_message_title: Verlaufen?
error_message_code: Fehler 404
error_message_text: >
Wir können die Seite nach der Du gesucht hast leider nicht finden. Keine Sorge,
wir bringen Dich zurück zur <a class="gdoc-error__link" href="{{ . }}">Startseite</a>.
button_toggle_dark: Wechsel zwischen Dunkel/Hell/Auto Modus
button_nav_open: Navigation öffnen
button_nav_close: Navigation schließen
button_menu_open: Menüband öffnen
button_menu_close: Menüband schließen
button_homepage: Zurück zur Startseite

title_anchor_prefix: "Link zu:"

posts_read_more: Ganzen Artikel lesen
posts_read_time:
one: "Eine Minute Lesedauer"
other: "{{ . }} Minuten Lesedauer"
posts_update_prefix: Aktualisiert am

footer_build_with: >
Entwickelt mit <a href="https://gohugo.io/" class="gdoc-footer__link">Hugo</a> und
<svg class="icon gdoc_heart"><use xlink:href="#gdoc_heart"></use></svg>
footer_legal_notice: Impressum
footer_privacy_policy: Datenschutzerklärung

language_switch_no_tranlation_prefix: "Seite nicht übersetzt:"
39 changes: 39 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
edit_page: Edit page

nav_navigation: Navigation
nav_tags: Tags
nav_more: More
nav_top: Back to top

form_placeholder_search: Search

error_page_title: Lost? Don't worry
error_message_title: Lost?
error_message_code: Error 404
error_message_text: >
Seems like what you are looking for can't be found. Don't worry, we can
bring you back to the <a class="gdoc-error__link" href="{{ . }}">homepage</a>.
button_toggle_dark: Toggle Dark/Light/Auto mode
button_nav_open: Open Navigation
button_nav_close: Close Navigation
button_menu_open: Open Menu Bar
button_menu_close: Close Menu Bar
button_homepage: Back to homepage

title_anchor_prefix: "Anchor to:"

posts_read_more: Read full post
posts_read_time:
one: "One minute to read"
other: "{{ . }} minutes to read"
posts_update_prefix: Updated on

footer_build_with: >
Built with <a href="https://gohugo.io/" class="gdoc-footer__link">Hugo</a> and
<svg class="icon gdoc_heart"><use xlink:href="#gdoc_heart"></use></svg>
footer_legal_notice: Legal Notice
footer_privacy_policy: Privacy Policy

language_switch_no_tranlation_prefix: "Page not translated:"
10 changes: 5 additions & 5 deletions layouts/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="{{ .Site.Language.Lang }}">
<head>
{{ partial "head/meta" . }}
<title>Lost? Don't worry</title>
<title>{{ i18n "error_page_title" }}</title>

{{ partial "head/favicons" . }}
{{ partial "head/others" . }}
Expand All @@ -14,6 +14,7 @@

<div class="wrapper">
<input type="checkbox" class="hidden" id="menu-header-control" />

{{ partial "site-header" (dict "Root" . "MenuEnabled" false) }}


Expand All @@ -23,11 +24,10 @@
<svg class="icon gdoc_cloud_off"><use xlink:href="#gdoc_cloud_off"></use></svg>
</div>
<div class="gdoc-error__message">
<div class="gdoc-error__line gdoc-error__title">Lost?</div>
<div class="gdoc-error__line gdoc-error__code">Error 404</div>
<div class="gdoc-error__line gdoc-error__title">{{ i18n "error_message_title" }}</div>
<div class="gdoc-error__line gdoc-error__code">{{ i18n "error_message_code" }}</div>
<div class="gdoc-error__line gdoc-error__help">
Seems like what you are looking for can't be found. Don't worry we can bring you back
to the <a class="gdoc-error__link" href="{{ .Site.BaseURL }}">homepage</a>.
{{ i18n "error_message_text" .Site.BaseURL | safeHTML }}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 5c22ce5

Please sign in to comment.