mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-17 20:10:59 +00:00
added logic to ignore missing pages in translations
This commit is contained in:
parent
a6df6d093c
commit
93649e1cfa
4 changed files with 75 additions and 23 deletions
|
|
@ -5,6 +5,7 @@ const slugify = require("slugify");
|
|||
const metagen = require("eleventy-plugin-metagen");
|
||||
const i18n = require('eleventy-plugin-i18n');
|
||||
const translations = require('./src/_data/i18n');
|
||||
const locales = require('./src/_data/locales');
|
||||
const fs = require('fs');
|
||||
const outdent = require('outdent');
|
||||
const schema = require("@quasibit/eleventy-plugin-schema");
|
||||
|
|
@ -142,9 +143,7 @@ module.exports = function(eleventyConfig) {
|
|||
return JSON.stringify(text).replace(/(?:\\n\s*){2,}/g, "\\n");
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("baseUrl", (text) => {
|
||||
return text.replace(/(?:ru)\//g, "");
|
||||
});
|
||||
|
||||
|
||||
eleventyConfig.addFilter("niceDate", (value) => {
|
||||
try{
|
||||
|
|
@ -156,6 +155,8 @@ module.exports = function(eleventyConfig) {
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
eleventyConfig.addFilter("algExcerpt", (text) => {
|
||||
return text
|
||||
.replace(/<code class="language-.*?">.*?<\/code>/gs, "")
|
||||
|
|
@ -203,6 +204,52 @@ module.exports = function(eleventyConfig) {
|
|||
}
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("baseUrl", (text) => {
|
||||
return text.replace(/(?:ru)\//g, "");
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("i18n_locale", (current_locale, locale_list) => {
|
||||
|
||||
return locale_list.filter(x => {return x.code === (current_locale ?? "en-US")})[0].label;
|
||||
})
|
||||
|
||||
eleventyConfig.addFilter("i18n_urls", (page, all) => {
|
||||
console.log(page)
|
||||
var locale_urls = locales.map((x => { if (x.url != "") return x.url })).filter(x => {return x !== undefined});
|
||||
|
||||
var split_url = page.split('/').length > 1 ? page.split('/')[1] : "";
|
||||
|
||||
// find the current locale
|
||||
var active_local = "";
|
||||
|
||||
locale_urls.every(locale => {
|
||||
if(locale === split_url){
|
||||
active_local = locale
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
||||
// get remaining locales
|
||||
var remaining_locals = locales.map((x => { return x.url })).filter(x => {return x !== active_local});
|
||||
|
||||
var i18n_pages = []
|
||||
|
||||
var valid_urls = all.map(x => {return x.url})
|
||||
|
||||
remaining_locals.forEach(x => {
|
||||
var new_url = ("/" + page.replace(active_local,x)).replace(/\/{2,}/,"/");
|
||||
console.log(new_url)
|
||||
if (valid_urls.indexOf(new_url)){
|
||||
i18n_pages.push({
|
||||
"url": new_url,
|
||||
"meta": locales.filter(y => {return y.url === x})[0]
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return i18n_pages
|
||||
});
|
||||
|
||||
return {
|
||||
dir: {
|
||||
input: "src",
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ module.exports = {
|
|||
'en-US': "HTML Template Linter and Formatter",
|
||||
ru: "Программа проверки и форматирования шаблонов HTML"
|
||||
},
|
||||
lang_name: {
|
||||
'en-US': "English",
|
||||
ru: "Русский"
|
||||
},
|
||||
lang_code: {
|
||||
'en-US': "en",
|
||||
ru: "ru"
|
||||
},
|
||||
// lang_name: {
|
||||
// 'en-US': "English",
|
||||
// ru: "Русский"
|
||||
// },
|
||||
// lang_code: {
|
||||
// 'en-US': "en",
|
||||
// ru: "ru"
|
||||
// },
|
||||
lang_code_url: {
|
||||
'en-US': "",
|
||||
ru: "/ru"
|
||||
|
|
|
|||
12
docs/src/_data/locales.js
Normal file
12
docs/src/_data/locales.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = [
|
||||
{
|
||||
label: 'English',
|
||||
code: 'en-US',
|
||||
url: ''
|
||||
},
|
||||
{
|
||||
label: 'Русский',
|
||||
code: 'ru',
|
||||
url: 'ru'
|
||||
}
|
||||
];
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
aria-label="main navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-brand">
|
||||
<a href="/">{% image "./src/static/img/icon.png", "djlint icon", "(min-width:600px) 50vw, 100vw" %}</a>
|
||||
<a href="{{ "lang_code_url" | i18n }}/">{% image "./src/static/img/icon.png", "djlint icon", "(min-width:600px) 50vw, 100vw" %}</a>
|
||||
<a role="button"
|
||||
class="navbar-burger"
|
||||
aria-label="menu"
|
||||
|
|
@ -65,19 +65,12 @@
|
|||
<span class="icon is-large">
|
||||
<i class="fas fa-lg fa-globe"></i>
|
||||
</span>
|
||||
<span>{{ "lang_code" | i18n }}
|
||||
<span>{{ locale | i18n_locale(locales) }}
|
||||
</a>
|
||||
<div class="navbar-dropdown">
|
||||
{% if "lang_code" | i18n != "en" %}
|
||||
<a class="navbar-item" href="{{ page.url | baseUrl }}">
|
||||
{{ 'lang_name' | i18n({}, 'en-US') }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if "lang_code" | i18n != "ru" %}
|
||||
<a class="navbar-item" href="/ru{{ page.url | baseUrl }}">
|
||||
{{ 'lang_name' | i18n({}, 'ru') }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% for page in page.url | i18n_urls(collections.all) %}
|
||||
<a class="navbar-item" href="{{ page.url }}">{{ page.meta.label }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue