Pass down lang and start docs
This commit is contained in:
parent
1d06324a65
commit
779511ae43
|
@ -252,6 +252,7 @@ impl Page {
|
|||
context.insert("current_url", &self.permalink);
|
||||
context.insert("current_path", &self.path);
|
||||
context.insert("page", &self.to_serialized(library));
|
||||
context.insert("lang", &self.lang);
|
||||
|
||||
render_template(&tpl_name, tera, &context, &config.theme)
|
||||
.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_path", &self.path);
|
||||
context.insert("section", &self.to_serialized(library));
|
||||
context.insert("lang", &self.lang);
|
||||
|
||||
render_template(tpl_name, tera, &context, &config.theme)
|
||||
.chain_err(|| format!("Failed to render section '{}'", self.file.path.display()))
|
||||
|
|
|
@ -30,6 +30,7 @@ pub struct SerializingPage<'a> {
|
|||
toc: &'a [Header],
|
||||
assets: &'a [String],
|
||||
draft: bool,
|
||||
lang: &'a Option<String>,
|
||||
lighter: Option<Box<SerializingPage<'a>>>,
|
||||
heavier: Option<Box<SerializingPage<'a>>>,
|
||||
earlier: Option<Box<SerializingPage<'a>>>,
|
||||
|
@ -88,6 +89,7 @@ impl<'a> SerializingPage<'a> {
|
|||
toc: &page.toc,
|
||||
assets: &page.serialized_assets,
|
||||
draft: page.is_draft(),
|
||||
lang: &page.lang,
|
||||
lighter,
|
||||
heavier,
|
||||
earlier,
|
||||
|
@ -136,6 +138,7 @@ impl<'a> SerializingPage<'a> {
|
|||
toc: &page.toc,
|
||||
assets: &page.serialized_assets,
|
||||
draft: page.is_draft(),
|
||||
lang: &page.lang,
|
||||
lighter: None,
|
||||
heavier: None,
|
||||
earlier: None,
|
||||
|
@ -157,6 +160,7 @@ pub struct SerializingSection<'a> {
|
|||
components: &'a [String],
|
||||
word_count: Option<usize>,
|
||||
reading_time: Option<usize>,
|
||||
lang: &'a Option<String>,
|
||||
toc: &'a [Header],
|
||||
assets: &'a [String],
|
||||
pages: Vec<SerializingPage<'a>>,
|
||||
|
@ -196,6 +200,7 @@ impl<'a> SerializingSection<'a> {
|
|||
reading_time: section.reading_time,
|
||||
toc: §ion.toc,
|
||||
assets: §ion.serialized_assets,
|
||||
lang: §ion.lang,
|
||||
pages,
|
||||
subsections,
|
||||
}
|
||||
|
@ -227,6 +232,7 @@ impl<'a> SerializingSection<'a> {
|
|||
reading_time: section.reading_time,
|
||||
toc: §ion.toc,
|
||||
assets: §ion.serialized_assets,
|
||||
lang: §ion.lang,
|
||||
pages: vec![],
|
||||
subsections: vec![],
|
||||
}
|
||||
|
|
34
docs/content/documentation/content/multilingual.md
Normal file
34
docs/content/documentation/content/multilingual.md
Normal file
|
@ -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
|
||||
title = ""
|
||||
description = ""
|
||||
# the default language, used in RSS and coming i18n
|
||||
# The default language, used in RSS
|
||||
default_language = "en"
|
||||
|
||||
# Theme name to use
|
||||
|
@ -51,6 +51,15 @@ generate_rss = false
|
|||
#
|
||||
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
|
||||
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
|
||||
- `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
|
||||
- `lang`: the language for that page, `null` if the page/section doesn't have a language set
|
||||
|
||||
## Standard Templates
|
||||
By default, Zola will look for three templates: `index.html`, which is applied
|
||||
|
|
|
@ -51,6 +51,8 @@ assets: Array<String>;
|
|||
ancestors: Array<String>;
|
||||
// The relative path from the `content` directory to the markdown file
|
||||
relative_path: String;
|
||||
// The language for the page if there is one
|
||||
lang: String?
|
||||
```
|
||||
|
||||
## Section variables
|
||||
|
@ -93,6 +95,8 @@ assets: Array<String>;
|
|||
ancestors: Array<String>;
|
||||
// The relative path from the `content` directory to the markdown file
|
||||
relative_path: String;
|
||||
// The language for the section if there is one
|
||||
lang: String?
|
||||
```
|
||||
|
||||
## Table of contents
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{% for page in section.pages %}
|
||||
{{page.title}}
|
||||
{% endfor %}
|
||||
Language: {{lang}}
|
||||
|
|
Loading…
Reference in a new issue