From 9f879be71bddd5a8cde0738f5be7dca429bb78c6 Mon Sep 17 00:00:00 2001 From: Henk Kalkwater Date: Sun, 28 Jun 2020 00:11:50 +0200 Subject: [PATCH] WIP: translation (but it ain't broken) --- dub.json | 3 +- source/app.d | 101 ++++++++++++++++++++------------- source/constants.d | 2 +- source/page.d | 2 + translations/mijnblog.en_GB.po | 2 + translations/mijnblog.nl.mo | Bin 0 -> 330 bytes translations/mijnblog.nl_NL.po | 15 +++++ translations/mijnblog.pot | 2 + views/parts/page.dt | 6 +- 9 files changed, 88 insertions(+), 45 deletions(-) create mode 100644 translations/mijnblog.en_GB.po create mode 100644 translations/mijnblog.nl.mo create mode 100644 translations/mijnblog.nl_NL.po create mode 100644 translations/mijnblog.pot diff --git a/dub.json b/dub.json index 9c4a598..1bf5803 100644 --- a/dub.json +++ b/dub.json @@ -9,5 +9,6 @@ }, "description": "A blog based on Markdown and JSON", "license": "AGPLv3", - "name": "mijnblog" + "name": "mijnblog", + "stringImportPaths": ["views", "translations"] } diff --git a/source/app.d b/source/app.d index 16bb4a3..0764e39 100644 --- a/source/app.d +++ b/source/app.d @@ -102,47 +102,67 @@ void getSingle(T, string templ)(ref T[string] array, HTTPServerRequest req, HTTP } } -/** - * Generates response for /posts/:slug and /palen/:slug. - */ -void articleGetSingle(HTTPServerRequest req, HTTPServerResponse res) { - getSingle!(Article, "pages/article.dt")(articles, req, res); +struct TranslationContext { + import std.typetuple; + enum enforceExistingKeys = true; + alias languages = TypeTuple!("en_GB", "nl_NL"); + mixin translationModule!"mijnblog"; } -/** - * Generates response for /posts and /palen - */ -void articleGetOverview(HTTPServerRequest req, HTTPServerResponse res) { - addCachingHeader(res); - render!("pages/article-list.dt", articleList)(res); -} - -/** - * Generates response for /projects and /projecten - */ -void projectGetOverview(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"); +@translationContext!TranslationContext +class MijnBlog { + /** + * Generates response for /posts/:slug and /palen/:slug. + */ + @path("/posts/:slug") + void getArticleSingle(string _slug, HTTPServerRequest req, HTTPServerResponse res) { + getSingle!(Article, "pages/article.dt")(articles, req, res); } - getSingle!(Page, "pages/page.dt")(pages, req, res); -} -/** - * Generate response for a project page - */ -void projectGet(HTTPServerRequest req, HTTPServerResponse res) { - res.headers["Cache-Control"] = "public"; - getSingle!(Project, "pages/project.dt")(projects, req, res); + /** + * Generates response for /posts and /palen + */ + @path("/posts/") + void getArticleOverview(HTTPServerRequest req, HTTPServerResponse res) { + addCachingHeader(res); + render!("pages/article-list.dt", articleList)(res); + } + + /** + * Generates response for /projects and /projecten + */ + @path("/projects/") + void getProjectOverview(HTTPServerRequest req, HTTPServerResponse res) { + addCachingHeader(res); + render!("pages/project-list.dt", projectList)(res); + } + + + + /** + * Generate response for a project page + */ + @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); + } } /** @@ -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); diff --git a/source/constants.d b/source/constants.d index 44baedd..8b665d3 100644 --- a/source/constants.d +++ b/source/constants.d @@ -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"; } diff --git a/source/page.d b/source/page.d index 49e605f..c347db1 100644 --- a/source/page.d +++ b/source/page.d @@ -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; } } diff --git a/translations/mijnblog.en_GB.po b/translations/mijnblog.en_GB.po new file mode 100644 index 0000000..2d4a957 --- /dev/null +++ b/translations/mijnblog.en_GB.po @@ -0,0 +1,2 @@ +msgid "page.header-bottom-text" +msgstr "Chris's website" diff --git a/translations/mijnblog.nl.mo b/translations/mijnblog.nl.mo new file mode 100644 index 0000000000000000000000000000000000000000..184b7fca08dc5321dc5173105b04bfc173514234 GIT binary patch literal 330 zcmYL@u};H442BN`OGbpm!f+c44itn`1(-@fm8b|PAl6G_lB20Fx-(FC51xv5;92ms z68+_Gux0DO;X;VYg+1Y3_z|qIE1Yd8CH1d(zf^A;Oj|THdMF*U zn*-y5Rqov@Rt%FGp3n#DDAP%P2M_peV+U7;QAW2WFcjWU=nOl*oKW*7u27(vOFx}V z$7_#4dYp_LF_N5p_F@s^j{446I@eWed_cZ@EUsa=-i!7x^5B>%S6gZ_JuEFt_9`jU m)FsbwgM@zdMDDP*tWVO@bdab~>uu0q2c$o+42-jxMfC^bGFXTJ literal 0 HcmV?d00001 diff --git a/translations/mijnblog.nl_NL.po b/translations/mijnblog.nl_NL.po new file mode 100644 index 0000000..0591aaf --- /dev/null +++ b/translations/mijnblog.nl_NL.po @@ -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" diff --git a/translations/mijnblog.pot b/translations/mijnblog.pot new file mode 100644 index 0000000..4d4a992 --- /dev/null +++ b/translations/mijnblog.pot @@ -0,0 +1,2 @@ +msgid "page.header-bottom-text" +msgstr "" diff --git a/views/parts/page.dt b/views/parts/page.dt index df0ced5..06730e7 100644 --- a/views/parts/page.dt +++ b/views/parts/page.dt @@ -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", "/");