@@ -252,6 +252,7 @@ impl Page { | |||||
context.insert("current_url", &self.permalink); | context.insert("current_url", &self.permalink); | ||||
context.insert("current_path", &self.path); | context.insert("current_path", &self.path); | ||||
context.insert("page", &self.to_serialized(library)); | context.insert("page", &self.to_serialized(library)); | ||||
context.insert("lang", &self.lang); | |||||
render_template(&tpl_name, tera, &context, &config.theme) | render_template(&tpl_name, tera, &context, &config.theme) | ||||
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) | .chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) | ||||
@@ -184,6 +184,7 @@ impl Section { | |||||
context.insert("current_url", &self.permalink); | context.insert("current_url", &self.permalink); | ||||
context.insert("current_path", &self.path); | context.insert("current_path", &self.path); | ||||
context.insert("section", &self.to_serialized(library)); | context.insert("section", &self.to_serialized(library)); | ||||
context.insert("lang", &self.lang); | |||||
render_template(tpl_name, tera, &context, &config.theme) | render_template(tpl_name, tera, &context, &config.theme) | ||||
.chain_err(|| format!("Failed to render section '{}'", self.file.path.display())) | .chain_err(|| format!("Failed to render section '{}'", self.file.path.display())) | ||||
@@ -30,6 +30,7 @@ pub struct SerializingPage<'a> { | |||||
toc: &'a [Header], | toc: &'a [Header], | ||||
assets: &'a [String], | assets: &'a [String], | ||||
draft: bool, | draft: bool, | ||||
lang: &'a Option<String>, | |||||
lighter: Option<Box<SerializingPage<'a>>>, | lighter: Option<Box<SerializingPage<'a>>>, | ||||
heavier: Option<Box<SerializingPage<'a>>>, | heavier: Option<Box<SerializingPage<'a>>>, | ||||
earlier: Option<Box<SerializingPage<'a>>>, | earlier: Option<Box<SerializingPage<'a>>>, | ||||
@@ -88,6 +89,7 @@ impl<'a> SerializingPage<'a> { | |||||
toc: &page.toc, | toc: &page.toc, | ||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
draft: page.is_draft(), | draft: page.is_draft(), | ||||
lang: &page.lang, | |||||
lighter, | lighter, | ||||
heavier, | heavier, | ||||
earlier, | earlier, | ||||
@@ -136,6 +138,7 @@ impl<'a> SerializingPage<'a> { | |||||
toc: &page.toc, | toc: &page.toc, | ||||
assets: &page.serialized_assets, | assets: &page.serialized_assets, | ||||
draft: page.is_draft(), | draft: page.is_draft(), | ||||
lang: &page.lang, | |||||
lighter: None, | lighter: None, | ||||
heavier: None, | heavier: None, | ||||
earlier: None, | earlier: None, | ||||
@@ -157,6 +160,7 @@ pub struct SerializingSection<'a> { | |||||
components: &'a [String], | components: &'a [String], | ||||
word_count: Option<usize>, | word_count: Option<usize>, | ||||
reading_time: Option<usize>, | reading_time: Option<usize>, | ||||
lang: &'a Option<String>, | |||||
toc: &'a [Header], | toc: &'a [Header], | ||||
assets: &'a [String], | assets: &'a [String], | ||||
pages: Vec<SerializingPage<'a>>, | pages: Vec<SerializingPage<'a>>, | ||||
@@ -196,6 +200,7 @@ impl<'a> SerializingSection<'a> { | |||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
toc: §ion.toc, | toc: §ion.toc, | ||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
lang: §ion.lang, | |||||
pages, | pages, | ||||
subsections, | subsections, | ||||
} | } | ||||
@@ -227,6 +232,7 @@ impl<'a> SerializingSection<'a> { | |||||
reading_time: section.reading_time, | reading_time: section.reading_time, | ||||
toc: §ion.toc, | toc: §ion.toc, | ||||
assets: §ion.serialized_assets, | assets: §ion.serialized_assets, | ||||
lang: §ion.lang, | |||||
pages: vec![], | pages: vec![], | ||||
subsections: vec![], | subsections: vec![], | ||||
} | } | ||||
@@ -0,0 +1,34 @@ | |||||
+++ | |||||
title = "Multilingual sites" | |||||
weight = 130 | |||||
+++ | |||||
Zola supports having a site in multiple languages. | |||||
## Configuration | |||||
To get started, you will need to add the languages you want to support | |||||
to your `config.toml`. For example: | |||||
```toml | |||||
languages = [ | |||||
{code = "fr", rss = true}, # there will be a RSS feed for French content | |||||
{code = "it"}, # there won't be a RSS feed for Italian content | |||||
] | |||||
``` | |||||
## Content | |||||
Once the languages are added in, you can start to translate your content. Zola | |||||
uses the filename to detect the language: | |||||
- `content/an-article.md`: this will be the default language | |||||
- `content/an-article.fr.md`: this will be in French | |||||
If the language code in the filename does not correspond to one of the languages configured, | |||||
an error will be shown. | |||||
If your default language has an `_index.md` in a directory, you will need to add a `_index.{code}.md` | |||||
file with the desired front-matter options as there is no language fallback. | |||||
## Output | |||||
Zola outputs the translated content with a base URL of `{base_url}/{code}/`. | |||||
The only exception to that is if you are setting a translated page `path` directly in the front-matter. |
@@ -21,7 +21,7 @@ base_url = "mywebsite.com" | |||||
# Used in RSS by default | # Used in RSS by default | ||||
title = "" | title = "" | ||||
description = "" | description = "" | ||||
# the default language, used in RSS and coming i18n | |||||
# The default language, used in RSS | |||||
default_language = "en" | default_language = "en" | ||||
# Theme name to use | # Theme name to use | ||||
@@ -51,6 +51,15 @@ generate_rss = false | |||||
# | # | ||||
taxonomies = [] | taxonomies = [] | ||||
# The additional languages for that site | |||||
# Example: | |||||
# languages = [ | |||||
# {code = "fr", rss = true}, # there will be a RSS feed for French content | |||||
# {code = "it"}, # there won't be a RSS feed for Italian content | |||||
# ] | |||||
# | |||||
languages = [] | |||||
# Whether to compile the Sass files found in the `sass` directory | # Whether to compile the Sass files found in the `sass` directory | ||||
compile_sass = false | compile_sass = false | ||||
@@ -18,6 +18,7 @@ A few variables are available on all templates minus RSS and sitemap: | |||||
- `config`: the [configuration](./documentation/getting-started/configuration.md) without any modifications | - `config`: the [configuration](./documentation/getting-started/configuration.md) without any modifications | ||||
- `current_path`: the path (full URL without the `base_url`) of the current page, never starting with a `/` | - `current_path`: the path (full URL without the `base_url`) of the current page, never starting with a `/` | ||||
- `current_url`: the full URL for that page | - `current_url`: the full URL for that page | ||||
- `lang`: the language for that page, `null` if the page/section doesn't have a language set | |||||
## Standard Templates | ## Standard Templates | ||||
By default, Zola will look for three templates: `index.html`, which is applied | By default, Zola will look for three templates: `index.html`, which is applied | ||||
@@ -51,6 +51,8 @@ assets: Array<String>; | |||||
ancestors: Array<String>; | ancestors: Array<String>; | ||||
// The relative path from the `content` directory to the markdown file | // The relative path from the `content` directory to the markdown file | ||||
relative_path: String; | relative_path: String; | ||||
// The language for the page if there is one | |||||
lang: String? | |||||
``` | ``` | ||||
## Section variables | ## Section variables | ||||
@@ -93,6 +95,8 @@ assets: Array<String>; | |||||
ancestors: Array<String>; | ancestors: Array<String>; | ||||
// The relative path from the `content` directory to the markdown file | // The relative path from the `content` directory to the markdown file | ||||
relative_path: String; | relative_path: String; | ||||
// The language for the section if there is one | |||||
lang: String? | |||||
``` | ``` | ||||
## Table of contents | ## Table of contents | ||||
@@ -1,3 +1,4 @@ | |||||
{% for page in section.pages %} | {% for page in section.pages %} | ||||
{{page.title}} | {{page.title}} | ||||
{% endfor %} | {% endfor %} | ||||
Language: {{lang}} |