WIP: translation (but it ain't broken)
This commit is contained in:
parent
8d2feaa76b
commit
9f879be71b
3
dub.json
3
dub.json
|
@ -9,5 +9,6 @@
|
|||
},
|
||||
"description": "A blog based on Markdown and JSON",
|
||||
"license": "AGPLv3",
|
||||
"name": "mijnblog"
|
||||
"name": "mijnblog",
|
||||
"stringImportPaths": ["views", "translations"]
|
||||
}
|
||||
|
|
57
source/app.d
57
source/app.d
|
@ -102,17 +102,28 @@ void getSingle(T, string templ)(ref T[string] array, HTTPServerRequest req, HTTP
|
|||
}
|
||||
}
|
||||
|
||||
struct TranslationContext {
|
||||
import std.typetuple;
|
||||
enum enforceExistingKeys = true;
|
||||
alias languages = TypeTuple!("en_GB", "nl_NL");
|
||||
mixin translationModule!"mijnblog";
|
||||
}
|
||||
|
||||
@translationContext!TranslationContext
|
||||
class MijnBlog {
|
||||
/**
|
||||
* Generates response for /posts/:slug and /palen/:slug.
|
||||
*/
|
||||
void articleGetSingle(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
@path("/posts/:slug")
|
||||
void getArticleSingle(string _slug, HTTPServerRequest req, HTTPServerResponse res) {
|
||||
getSingle!(Article, "pages/article.dt")(articles, req, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates response for /posts and /palen
|
||||
*/
|
||||
void articleGetOverview(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
@path("/posts/")
|
||||
void getArticleOverview(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
addCachingHeader(res);
|
||||
render!("pages/article-list.dt", articleList)(res);
|
||||
}
|
||||
|
@ -120,30 +131,39 @@ void articleGetOverview(HTTPServerRequest req, HTTPServerResponse res) {
|
|||
/**
|
||||
* Generates response for /projects and /projecten
|
||||
*/
|
||||
void projectGetOverview(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
@path("/projects/")
|
||||
void getProjectOverview(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
addCachingHeader(res);
|
||||
render!("pages/project-list.dt", projectList)(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate response for a page
|
||||
*/
|
||||
void pageGet(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
addCachingHeader(res);
|
||||
// If no slug is supplied, it will be adjusted to "index"
|
||||
if (("slug" in req.params) is null) {
|
||||
req.params.addField("slug", "index");
|
||||
}
|
||||
getSingle!(Page, "pages/page.dt")(pages, req, res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate response for a project page
|
||||
*/
|
||||
void projectGet(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
@path("/projects/:slug")
|
||||
void getProject(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
res.headers["Cache-Control"] = "public";
|
||||
getSingle!(Project, "pages/project.dt")(projects, req, res);
|
||||
}
|
||||
/**
|
||||
* Generate response for a page
|
||||
*/
|
||||
@path("/:slug")
|
||||
void getPage(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
addCachingHeader(res);
|
||||
getSingle!(Page, "pages/page.dt")(pages, req, res);
|
||||
}
|
||||
|
||||
@path("/")
|
||||
void getIndexPage(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
addCachingHeader(res);
|
||||
// If no slug is supplied, it will be adjusted to "index"
|
||||
req.params.addField("slug", "index");
|
||||
getSingle!(Page, "pages/page.dt")(pages, req, res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates response whenever an error occurs.
|
||||
|
@ -167,16 +187,17 @@ void main() {
|
|||
fSettings.maxAge = days(16);
|
||||
|
||||
URLRouter router = new URLRouter;
|
||||
router.get("/posts/:slug", &articleGetSingle);
|
||||
router.get("/static/*", serveStaticFiles("./public/", fSettings));
|
||||
router.registerWebInterface(new MijnBlog);
|
||||
/*router.get("/posts/:slug", &articleGetSingle);
|
||||
router.get("/palen/:slug", &articleGetSingle);
|
||||
router.get("/posts/", &articleGetOverview);
|
||||
router.get("/palen/", &articleGetOverview);
|
||||
router.get("/projects/", &projectGetOverview);
|
||||
router.get("/projects/:slug", &projectGet);
|
||||
router.get("/projecten/:slug", &projectGet);
|
||||
router.get("/static/*", serveStaticFiles("./public/", fSettings));
|
||||
router.get("/:slug", &pageGet);
|
||||
router.get("/", &pageGet);
|
||||
router.get("/", &pageGet);*/
|
||||
|
||||
listenHTTP(settings, router);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Constants which are passed to templates while rendering.
|
||||
*/
|
||||
class Constants {
|
||||
public static immutable string SITE_NAME = "Chris Netsoj.nl";
|
||||
public static immutable string SITE_NAME = "Chris Josten's site";
|
||||
public static immutable string SITE_URL = "https://chris.netsoj.nl";
|
||||
public static immutable string COPYRIGHT = "© Chris Josten, 2020";
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class Page {
|
|||
protected string m_content;
|
||||
protected string m_contentSource;
|
||||
protected bool m_hidden;
|
||||
protected string m_language;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -130,4 +131,5 @@ class Page {
|
|||
@property string content() { return m_content; }
|
||||
@property string contentSource() { return m_contentSource; }
|
||||
@property bool isHidden() { return m_hidden; }
|
||||
@property string language() { return m_language; }
|
||||
}
|
||||
|
|
2
translations/mijnblog.en_GB.po
Normal file
2
translations/mijnblog.en_GB.po
Normal file
|
@ -0,0 +1,2 @@
|
|||
msgid "page.header-bottom-text"
|
||||
msgstr "Chris's website"
|
BIN
translations/mijnblog.nl.mo
Normal file
BIN
translations/mijnblog.nl.mo
Normal file
Binary file not shown.
15
translations/mijnblog.nl_NL.po
Normal file
15
translations/mijnblog.nl_NL.po
Normal file
|
@ -0,0 +1,15 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: \n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Language: nl\n"
|
||||
"X-Generator: Poedit 2.3.1\n"
|
||||
|
||||
msgid "Chris's website"
|
||||
msgstr "Chris z'n webstekkie"
|
2
translations/mijnblog.pot
Normal file
2
translations/mijnblog.pot
Normal file
|
@ -0,0 +1,2 @@
|
|||
msgid "page.header-bottom-text"
|
||||
msgstr ""
|
|
@ -14,10 +14,10 @@ html(prefix="og: http://ogp.me/ns#")
|
|||
block meta_data
|
||||
|
||||
- if (page_title !is null)
|
||||
title #{page_title} - Chris Netsoj.nl
|
||||
title& #{page_title} - #{Constants.SITE_NAME}
|
||||
meta(name="og:title", content=page_title)
|
||||
- else
|
||||
title Chris Netsoj.nl
|
||||
title& #{Constants.SITE_NAME}
|
||||
|
||||
meta(name="og:site_name", content=Constants.SITE_NAME)
|
||||
- if (page_image !is null)
|
||||
|
@ -45,7 +45,7 @@ html(prefix="og: http://ogp.me/ns#")
|
|||
section.header-navigation
|
||||
header
|
||||
img.logo(src="/static/img/logo.png", alt="The logo of the website: the letter C drawn in an unprofessional manner with wobbly eyes on put on top")
|
||||
p Chris's webstekkie
|
||||
p& Chris's website
|
||||
nav
|
||||
ul
|
||||
- menuItem("home", "/");
|
||||
|
|
Loading…
Reference in a new issue