Adding more internationalization support

This commit is contained in:
Jocelyn Badgley (Twipped) 2021-08-11 11:23:59 -07:00
parent 84133bd212
commit 59e4380906
10 changed files with 115 additions and 78 deletions

View File

@ -12,7 +12,7 @@ const slugify = require('./lib/slugify');
const { stripHtml } = require('string-strip-html');
const markdownIt = require('markdown-it');
const i18n = require('../lang');
const markdownEngines = {
@ -144,6 +144,7 @@ class Injectables {
this.prod = prod;
this.revManifest = revManifest;
this.injections = {};
this.languages = {};
}
_parsePath (tpath, local, type) {
@ -182,6 +183,7 @@ class Injectables {
icon: this.icon(),
prod: this.production(),
rev: this.rev(),
lang: this.lang(),
};
}
@ -268,4 +270,12 @@ class Injectables {
};
}
lang () {
return function (key, ...args) {
const { resolve: rval } = args.pop();
const lang = rval('@root.this.page.lang').split('-')[0];
return i18n(lang, key, ...args);
};
}
}

View File

@ -5,6 +5,7 @@ const { map, uniq } = require('lodash');
const { resolve, ROOT, TYPE } = require('./resolve');
const { siteInfo } = require(resolve('package.json'));
const { minify } = require('html-minifier-terser');
const i18n = require('../lang');
const MINIFY_CONFIG = {
conservativeCollapse: true,
@ -73,17 +74,18 @@ function siblings (posts) {
}
function pageState (page, posts) {
const lang = page.meta.lang || siteInfo.lang || 'en';
return {
...page,
meta: { ...page.meta, ...page },
page: {
domain: siteInfo.domain,
lang: page.meta.lang || siteInfo.lang || "",
date: page.meta.date || "",
lang,
date: page.meta.date || '',
title: page.meta.title
? (page.meta.title + (page.meta.subtitle ? ', ' + page.meta.subtitle : '') + ' :: ' + siteInfo.title)
: siteInfo.title,
description: page.meta.description || siteInfo.description,
? (page.meta.title + (page.meta.subtitle ? ', ' + page.meta.subtitle : '') + ' :: ' + i18n(lang, 'SITE_TITLE'))
: i18n(lang, 'SITE_TITLE'),
description: page.meta.description || i18n('SITE_DESCRIPTION'),
},
site: siteInfo,
local: {

11
lang/en.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = exports = {
SITE_TITLE: 'That\'s Gender Dysphoria, FYI',
SITE_DESCRIPTION: 'A resource for those questioning their gender, already on a gender journey, or simply wanting to learn more about what it is to be transgender.',
HEADER_TITLE: 'That\'s Gender Dysphoria, <abbr title="For Your Information">FYI</abbr>',
PATREON_FOOTER_BODY: 'This site is made possible thanks to contributions from the community. If you have found this site invaluable, please consider <a href="https://www.patreon.com/curvyandtrans">making a pledge on patreon</a> or a <a href="https://ko-fi.com/curvyandtrans">donation via Ko-fi</a>.',
PATREON_FOOTER_THANKS: 'Special thanks to the following patreon supporters:',
FOOTER_COPYRIGHT: 'Site text, website code and original graphics are <a href="https://creativecommons.org/licenses/by-nc-sa/2.0/">licensed CC BY-NC-SA.</a>',
};

8
lang/es.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = exports = {
SITE_TITLE: 'Eso es Disforia de Género, PSI',
HEADER_TITLE: 'Eso es Disforia de Género, <abbr title="Para Su Información">PSI</abbr>',
};

12
lang/index.js Normal file
View File

@ -0,0 +1,12 @@
const languages = {
en: require('./en'),
es: require('./es'),
};
module.exports = exports = function (lang, key, ...args) {
var entry = languages[lang] && languages[lang][key];
if (!entry) entry = languages.en[key];
if (typeof entry === 'function') return entry(...args);
return entry || key;
};

View File

@ -12,7 +12,7 @@
"siteInfo": {
"title": "That's Gender Dysphoria, FYI",
"domain": "genderdysphoria.fyi",
"lang": "en-US",
"lang": "en",
"siteUrl": "https://genderdysphoria.fyi",
"description": "A resource for those questioning their gender, already on a gender journey, or simply wanting to learn more about what it is to be transgender.",
"creator": "TwippingVanilla",

View File

@ -1,4 +1,5 @@
<a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" data-flip="false" aria-haspopup="true" aria-expanded="false">The Gender Dysphoria Bible</a>
<div class="dropdown-menu" aria-labelledby="nav-gdb">
<a href="/gdb/printable" class="{{#is meta.url '/gdb/printable' }}active {{/is}}dropdown-item">View All</a>
<a href="/gdb.pdf" class="dropdown-item">Download PDF {{icon 'pdf' size="1em" style="vertical-align:middle;margin-bottom:3px;"}} </a>

View File

@ -1,4 +1,5 @@
<a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" data-flip="false" aria-haspopup="true" aria-expanded="false">La Biblia de la Disforia de Género</a>
<div class="dropdown-menu" aria-labelledby="nav-gdb">
<a href="/gdb/es/imprimible" class="{{#is meta.url '/gdb/es/imprimible' }}active {{/is}}dropdown-item">Ver Todo</a>
<!-- <a href="/gdb.es.pdf" class="dropdown-item">Descargar PDF {{icon 'pdf' size="1em" style="vertical-align:middle;margin-bottom:3px;"}} </a> -->

View File

@ -1,5 +1,6 @@
{{#is page.lang "es"}}
<a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" data-flip="false" aria-haspopup="true" aria-expanded="false">La Biblia de la Disforia de Género</a>{{import '/public/_gdb-es-menu'}}
{{import '/public/_gdb-es-menu'}}
{{else}}
<a href="/gdb/" class="top-nav-item dropdown-toggle" id="nav-gdb" data-toggle="dropdown" data-flip="false" aria-haspopup="true" aria-expanded="false">The Gender Dysphoria Bible</a>{{import '/public/_gdb-en-menu'}}
{{import '/public/_gdb-en-menu'}}
{{/is}}

View File

@ -59,22 +59,16 @@
<div class="root">
<header>
<nav>
{{#is page.lang "es"}}
<a href="/gdb/es/" class="top-brand">Eso es Disforia de Género, <abbr title="Para Su Información">PSI</abbr></a>
{{else}}
<a href="/" class="top-brand">That's Gender Dysphoria, <abbr title="For Your Information">FYI</abbr></a>
{{/is}}
<a href="/" class="top-brand">{{{lang 'HEADER_TITLE'}}}</a>
<div class="top-nav">
<ul class="top-nav-inner">
<li>{{import '/public/_gdb-menu'}}</li>
<li><a href="/tweets/" class="top-nav-item" title="Trans Twitter Topics"><img src="/images/transtwitter.png" width="24" height="24" alt=""></a></li>
<li class="disposable"><a href="https://github.com/GenderDysphoria/GenderDysphoria.fyi/issues" class="top-nav-item">{{icon 'brands/github'}}</a></li>
<li><a href="/tweets/" class="top-nav-item" title="{{{lang 'Trans Twitter Topics'}}}"><img src="/images/transtwitter.png" width="24" height="24" alt=""></a></li>
<li class="disposable"><a href="https://github.com/GenderDysphoria/GenderDysphoria.fyi" class="top-nav-item">{{icon 'brands/github'}}</a></li>
<li class="disposable"><a href="https://patreon.com/curvyandtrans" class="top-nav-item" title="Patreon">{{icon 'brands/patreon'}}</a></li>
<li class="disposable"><a href="https://ko-fi.com/curvyandtrans" class="top-nav-item" title="Ko-Fi">{{icon 'brands/ko-fi'}}</a></li>
</ul>
</div>
</nav>
</header>
@ -84,11 +78,8 @@
</div>
<footer>
<div class="patreon-support">
<strong>
This site is made possible thanks to contributions from the community.
If you have found this site invaluable, please consider <a href="https://www.patreon.com/curvyandtrans">making a pledge on patreon</a> or a <a href="https://ko-fi.com/curvyandtrans">donation via Ko-fi</a>.
</strong>
<p>Special thanks to the following patreon supporters:</p>
<strong>{{{lang 'PATREON_FOOTER_BODY'}}}</strong>
<p>{{{lang 'PATREON_FOOTER_THANKS'}}}</p>
<ul>
<li>Julia Hocken</li>
<li>Amanda B</li>
@ -113,8 +104,8 @@
</ul>
<hr>
</div>
<p class="copyright">Site text, website code and original graphics are <a href="https://creativecommons.org/licenses/by-nc-sa/2.0/">licensed CC BY-NC-SA.</a><span class="cc-by-nc-sa">{{icon 'symbols/cc'}}{{icon 'symbols/cc-by'}}{{icon 'symbols/cc-nc'}}{{icon 'symbols/cc-sa'}}</span><br>&copy; {{date "yyyy"}} <a href="https://curvyandtrans.com">Jocelyn Badgley</a> and Other Contributors </p>
<p class="foot-nav"><a href="/privacy.html">Privacy Policy</a></p>
<p class="copyright">{{{lang 'FOOTER_COPYRIGHT'}}}<span class="cc-by-nc-sa">{{icon 'symbols/cc'}}{{icon 'symbols/cc-by'}}{{icon 'symbols/cc-nc'}}{{icon 'symbols/cc-sa'}}</span><br>&copy; {{date "yyyy"}} <a href="https://curvyandtrans.com">Jocelyn Badgley</a> {{lang 'and Other Contributors'}}</p>
<p class="foot-nav"><a href="/privacy.html">{{lang 'Privacy Policy'}}</a></p>
</footer>
</div>