Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed i18n/en-US/components/Post.yml
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "ISC",
"devDependencies": {
"concurrently": "^7.2.0",
"nullstack": "~0.16.0",
"nullstack": "~0.17.2",
"tailwindcss": "^3.0.0"
},
"scripts": {
Expand Down
22 changes: 12 additions & 10 deletions src/Translatable.njs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { readFileSync } from 'fs';
import Nullstack from 'nullstack';
import YAML from 'yaml';
import { existsSync, readFileSync } from "fs";
import Nullstack from "nullstack";
import YAML from "yaml";

class Translatable extends Nullstack {

static async geti18nByLocale({ locale }) {
const [name] = this.name.split('_');
const file = readFileSync(`i18n/${locale}/components/${name}.yml`, 'utf-8');
return YAML.parse(file);
const [name] = this.name.split("_");
const translationPath = `i18n/${locale}/components/${name}.yml`;
if (existsSync(translationPath)) {
const file = readFileSync(translationPath, "utf-8");
return YAML.parse(file);
}
return {};
}

async initiate({ page, locale }) {
this.locale = locale;
this.i18n = await this.geti18nByLocale({ locale });
if (this.i18n.title) {
page.description = this.i18n.description;
page.locale = locale || 'en-US';
page.locale = locale || "en-US";
}
}

Expand All @@ -30,7 +33,6 @@ class Translatable extends Nullstack {
this.initiate();
}
}

}

export default Translatable;
export default Translatable;
Loading