Skip to content
Merged
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
23 changes: 12 additions & 11 deletions ghost/i18n/lib/i18n.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const i18next = require('i18next');
const path = require('path');
const fs = require('fs');
const errors = require('@tryghost/errors');
const debug = require('@tryghost/debug')('i18n');

// Locale data loaded from JSON (single source of truth)
Expand Down Expand Up @@ -57,21 +56,23 @@ function generateThemeResources(lng, themeLocalesPath) {

return locales.reduce((acc, locale) => {
let res;
let needsFallback = false;
// Try to load the locale file, fallback to English
try {
const localePath = path.join(themeLocalesPath, `${locale}.json`);
if (fs.existsSync(localePath)) {
const localePath = path.join(themeLocalesPath, `${locale}.json`);
if (fs.existsSync(localePath)) {
try {
// Delete from require cache to ensure fresh reads for theme files
delete require.cache[require.resolve(localePath)];
res = require(localePath);
} else {
throw new errors.IncorrectUsageError({
message: `Locale file not found: ${locale}`,
context: locale
});
} catch (err) {
debug(`Error loading theme locale file: ${locale}`);
needsFallback = true;
}
} catch (err) {
debug(`Error loading theme locale file: ${locale}`);
} else {
needsFallback = true;
}

if (needsFallback) {
// Fallback to English if it's not the locale we're already trying
if (locale !== 'en') {
try {
Expand Down