title: Customize 404 page keywords: teedoc, custom 404 page, 404 page internationalization
Support custom 404 page (the page displayed when accessing the wrong URL), and support 404 page internationalization
Set the mapping between the url
of the website root directory and the path in the site_config
, such as
"route": {
"pages": {
"/": "pages/index/zh"
}
},
"translate": {
"pages": {
"/": [{
"url": "/en/",
"src": "pages/index/en"
}
]
}
}
Here the website root directory (/
) is mapped to the folder pages/index/zh
, you only need to create the file pages/index/zh/404.md
, and then add the content:
---
layout: 404.html
---
or
---
layout: 404
---
Users will return to this page when they visit the wrong path
The website root directory configuration mentioned above, if the locale
is configured as zh
in the config
file under pages/index/zh
, the content of the generated /404.html
will be Chinese
If the user's browser language is set in other languages, such as English en
, it will try to jump to /en/404.html
, so we only need to:
translate
in site_config
, as shown in the example aboveThen create a new pages/index/en/404.md
, add content
---
layout: 404.html
---
! If
locale
has a suffix, such aszh_CN
,en_US
, etc., the404
page will automatically try to jump to the page in the same language as the browser setting, such as/en_US/404.html
,/en -US/404.html
,/en-us/404.html
,/en_us/404.html
stop redirecting until the page language and browser language are the same. When all links are tried to redirect It also stops jumping after failure
If the language you need has not been translated, there are two ways:
fork
repository, and then git clone
To your warehouse locally, add a new language to the locales.cfg
file, and then execute python trans_prepare.py
, which will generate a new translation file in the locales
directory with the suffix .po
, translate This file (to translate the po
file, you can directly modify the text, or use other tools to translate), and then execute python trans_finish.py
will generate a mo
binary file, you can submit the changes without errors, and then in github
Create PR(Pull Request)
to contribute translation to teedoc
repositoryModify the template directly based on the theme, or inherit the template of the theme, such as slightly changing the body
part of the 404.html
page, just create a new my_404.html
in the layout
directory. Note that the file name cannot be the same Built-in file name conflict, if conflict, it will prompt generate html fail: maximum recursion depth exceeded in comparison
:
{% extends "404.html" %}
{% block body_404 %}
Here is body
{{ body|safe }}
{% endblock%}
Then use this template in 404.md
---
layout: my_404.html
---