Add internationalization support with astro-i18next integration

- Implemented astro-i18next for multi-language support, including English, Dutch, and Italian.
- Configured default locale and language fallback settings.
- Defined routes for localized content in the configuration.
- Updated package.json and package-lock.json to include new dependencies for i18next and related plugins.
This commit is contained in:
becarta
2025-05-23 15:10:00 +02:00
parent 8a3507dce0
commit 3168826fa8
581 changed files with 88691 additions and 494 deletions

4
node_modules/i18next-fs-backend/esm/extname.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export default (function (filename) {
if (filename.indexOf('.') < 0) return undefined;
return ".".concat(filename.split('.').pop());
});

1119
node_modules/i18next-fs-backend/esm/formats/json5.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1758
node_modules/i18next-fs-backend/esm/formats/jsonc.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2698
node_modules/i18next-fs-backend/esm/formats/yaml.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

5
node_modules/i18next-fs-backend/esm/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import * as index from './index.js';
export default index.default;
export type FsBackendOptions = index.FsBackendOptions;

50
node_modules/i18next-fs-backend/esm/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import { BackendModule, ReadCallback } from "i18next";
type LoadPathOption =
| string
| ((language: string, namespace: string) => string);
type AddPathOption =
| string
| ((language: string, namespace: string) => string)
export interface FsBackendOptions {
/**
* path where resources get loaded from, or a function
* returning a path:
* function(language, namespace) { return customPath; }
* the returned path will interpolate lng, ns if provided like giving a static path
*/
loadPath?: LoadPathOption;
/**
* path to post missing resources, must be `string` or a `function` returning a path:
* function(language, namespace) { return customPath; }
*/
addPath?: AddPathOption;
ident?: number | undefined;
parse?(
data: string
): { [key: string]: any };
stringify?(
data: { [key: string]: any }
): string;
expirationTime?: number;
}
export default class I18NexFsBackend
implements BackendModule<FsBackendOptions>
{
static type: "backend";
constructor(services?: any, options?: FsBackendOptions);
init(services?: any, options?: FsBackendOptions): void;
read(language: string, namespace: string, callback: ReadCallback): void;
create?(
languages: string[],
namespace: string,
key: string,
fallbackValue: string
): void;
type: "backend";
services: any;
options: FsBackendOptions;
}

193
node_modules/i18next-fs-backend/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,193 @@
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { defaults, debounce, getPath, setPath, pushPath } from './utils.js';
import { readFile, readFileSync } from './readFile.js';
import { writeFile as _writeFile, removeFile as _removeFile } from './writeFile.js';
var getDefaults = function getDefaults() {
return {
loadPath: '/locales/{{lng}}/{{ns}}.json',
addPath: '/locales/{{lng}}/{{ns}}.missing.json',
ident: 2,
parse: JSON.parse,
stringify: JSON.stringify
};
};
var Backend = function () {
function Backend(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
_classCallCheck(this, Backend);
this.services = services;
this.options = options;
this.allOptions = allOptions;
this.type = 'backend';
this.init(services, options, allOptions);
}
return _createClass(Backend, [{
key: "init",
value: function init(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
this.allOptions = allOptions;
this.queuedWrites = {};
this.debouncedWrite = debounce(this.write, 250);
}
}, {
key: "read",
value: function read(language, namespace, callback) {
var _this = this;
var loadPath = this.options.loadPath;
if (typeof this.options.loadPath === 'function') {
loadPath = this.options.loadPath(language, namespace);
}
var filename = this.services.interpolator.interpolate(loadPath, {
lng: language,
ns: namespace
});
if (this.allOptions.initAsync === false || this.allOptions.initImmediate === false) {
try {
var _readFileSync = readFileSync(filename, this.options),
data = _readFileSync.data,
stat = _readFileSync.stat;
var timestamp = stat && stat.mtime && stat.mtime.getTime();
if (this.options.expirationTime && timestamp && timestamp + this.options.expirationTime < Date.now()) {
this.removeFile(language, namespace);
return callback(new Error('File expired!'), false);
}
callback(null, data, timestamp);
} catch (err) {
callback(err, false);
}
return;
}
readFile(filename, this.options).then(function (_ref) {
var data = _ref.data,
stat = _ref.stat;
var timestamp = stat && stat.mtime && stat.mtime.getTime();
if (_this.options.expirationTime && timestamp && timestamp + _this.options.expirationTime < Date.now()) {
_this.removeFile(language, namespace);
return callback(new Error('File expired!'), false);
}
callback(null, data, timestamp);
}).catch(function (err) {
return callback(err, false);
});
}
}, {
key: "create",
value: function create(languages, namespace, key, fallbackValue, callback) {
var _this2 = this;
if (typeof callback !== 'function') callback = function callback() {};
if (typeof languages === 'string') languages = [languages];
var todo = languages.length;
var done = function done() {
if (! --todo) callback();
};
languages.forEach(function (lng) {
_this2.queue.call(_this2, lng, namespace, key, fallbackValue, done);
});
}
}, {
key: "save",
value: function save(language, namespace, data, callback) {
var _this3 = this;
if (!callback) callback = function callback() {};
var keys = Object.keys(data);
var todo = keys.length;
var done = function done() {
if (! --todo) callback();
};
keys.forEach(function (key) {
_this3.queue.call(_this3, language, namespace, key, data[key], done);
});
}
}, {
key: "removeFile",
value: function removeFile(language, namespace) {
var addPath = this.options.addPath;
if (typeof this.options.addPath === 'function') {
addPath = this.options.addPath(language, namespace);
}
var filename = this.services.interpolator.interpolate(addPath, {
lng: language,
ns: namespace
});
_removeFile(filename, this.options).then(function () {}).catch(function () {});
}
}, {
key: "write",
value: function write() {
for (var lng in this.queuedWrites) {
var namespaces = this.queuedWrites[lng];
if (lng !== 'locks') {
for (var ns in namespaces) {
this.writeFile(lng, ns);
}
}
}
}
}, {
key: "writeFile",
value: function writeFile(lng, namespace) {
var _this4 = this;
var lock = getPath(this.queuedWrites, ['locks', lng, namespace]);
if (lock) return;
var addPath = this.options.addPath;
if (typeof this.options.addPath === 'function') {
addPath = this.options.addPath(lng, namespace);
}
var filename = this.services.interpolator.interpolate(addPath, {
lng: lng,
ns: namespace
});
var missings = getPath(this.queuedWrites, [lng, namespace]);
setPath(this.queuedWrites, [lng, namespace], []);
if (missings.length) {
setPath(this.queuedWrites, ['locks', lng, namespace], true);
var proceed = function proceed(_ref2) {
var data = _ref2.data;
missings.forEach(function (missing) {
var path = _this4.allOptions.keySeparator === false ? [missing.key] : missing.key.split(_this4.allOptions.keySeparator || '.');
try {
setPath(data, path, missing.fallbackValue);
} catch (e) {
if (path.length < 2 || !e.message || e.message.indexOf('Cannot create property') < 0) throw e;
setPath(data, [missing.key], missing.fallbackValue);
}
});
var proceedWrite = function proceedWrite() {
setPath(_this4.queuedWrites, ['locks', lng, namespace], false);
missings.forEach(function (missing) {
if (missing.callback) missing.callback();
});
_this4.debouncedWrite();
};
_writeFile(filename, data, _this4.options).then(proceedWrite).catch(proceedWrite);
};
readFile(filename, this.options).then(proceed).catch(function () {
return proceed({
data: {}
});
});
}
}
}, {
key: "queue",
value: function queue(lng, namespace, key, fallbackValue, callback) {
pushPath(this.queuedWrites, [lng, namespace], {
key: key,
fallbackValue: fallbackValue || '',
callback: callback
});
this.debouncedWrite();
}
}]);
}();
Backend.type = 'backend';
export default Backend;

150
node_modules/i18next-fs-backend/esm/readFile.js generated vendored Normal file
View File

@@ -0,0 +1,150 @@
import JSON5 from './formats/json5.js';
import { parse as parseJSONC } from './formats/jsonc.js';
import jsYaml from './formats/yaml.js';
import extname from './extname.js';
var isDeno = typeof Deno !== 'undefined';
var isBun = typeof Bun !== 'undefined';
var YAML = typeof jsYaml !== 'undefined' && jsYaml.load ? jsYaml : undefined;
var fs = !isDeno ? (await import('node:fs')).default : undefined;
var evalAlias = eval;
var readFileInNodeSync = function readFileInNodeSync(filename) {
var data = fs.readFileSync(filename, 'utf8');
var stat;
try {
stat = fs.statSync(filename);
} catch (e) {}
return {
data: data,
stat: stat
};
};
var readFileInNode = function readFileInNode(filename) {
return new Promise(function (resolve, reject) {
fs.readFile(filename, 'utf8', function (err, data) {
if (err) return reject(err);
fs.stat(filename, function (err, stat) {
if (err) return resolve({
data: data
});
return resolve({
data: data,
stat: stat
});
});
});
});
};
var readFileInDenoSync = function readFileInDenoSync(filename) {
var decoder = new TextDecoder('utf-8');
var d = Deno.readFileSync(filename);
var data = decoder.decode(d);
var stat;
try {
stat = Deno.statSync(filename);
} catch (e) {}
return {
data: data,
stat: stat
};
};
var readFileInDeno = function readFileInDeno(filename) {
return new Promise(function (resolve, reject) {
var decoder = new TextDecoder('utf-8');
Deno.readFile(filename).then(function (d) {
var data = decoder.decode(d);
Deno.stat(filename).then(function (stat) {
return resolve({
data: data,
stat: stat
});
}).catch(function () {
return resolve({
data: data
});
});
}).catch(reject);
});
};
var readFileInBunSync = readFileInNodeSync;
var readFileInBun = readFileInNode;
var replaceLast = function replaceLast(str, find, replace) {
var index = str.lastIndexOf(find);
if (index > -1) {
return str.substring(0, index) + replace + str.substring(index + find.length);
}
return str.toString();
};
var parseData = function parseData(extension, data, options) {
data = data.replace(/^\uFEFF/, '');
var result = {};
switch (extension) {
case '.js':
case '.ts':
if (typeof module === 'undefined') {
if (data.indexOf('exports') > -1) {
data = "(".concat(replaceLast(data.substring(data.indexOf('=') + 1), '};', ''), ")");
} else if (data.indexOf('export default ') > -1) {
data = "(".concat(replaceLast(data.substring(data.indexOf('export default ') + 15), '};', ''), ")");
}
}
result = evalAlias(data);
break;
case '.json5':
result = JSON5.parse(data);
break;
case '.jsonc':
result = parseJSONC(data);
break;
case '.yml':
case '.yaml':
result = YAML.load(data);
break;
default:
result = options.parse(data);
}
return result;
};
export function readFileSync(filename, options) {
var ext = extname(filename);
var data, stat;
if (isBun) {
var ret = readFileInBunSync(filename);
data = ret.data;
stat = ret.stat;
} else if (isDeno) {
var _ret = readFileInDenoSync(filename);
data = _ret.data;
stat = _ret.stat;
} else {
var _ret2 = readFileInNodeSync(filename);
data = _ret2.data;
stat = _ret2.stat;
}
return {
data: parseData(ext, data, options),
stat: stat
};
}
export function readFile(filename) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
parse: JSON.parse
};
var ext = extname(filename);
var fn = isBun ? readFileInBun : isDeno ? readFileInDeno : readFileInNode;
return new Promise(function (resolve, reject) {
fn(filename).then(function (_ref) {
var data = _ref.data,
stat = _ref.stat;
try {
var ret = parseData(ext, data, options);
resolve({
data: ret,
stat: stat
});
} catch (err) {
err.message = 'error parsing ' + filename + ': ' + err.message;
reject(err);
}
}).catch(reject);
});
}

67
node_modules/i18next-fs-backend/esm/utils.js generated vendored Normal file
View File

@@ -0,0 +1,67 @@
var arr = [];
var each = arr.forEach;
var slice = arr.slice;
export function defaults(obj) {
each.call(slice.call(arguments, 1), function (source) {
if (source) {
for (var prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
export function debounce(func, wait, immediate) {
var timeout;
return function () {
var context = this;
var args = arguments;
var later = function later() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
function getLastOfPath(object, path, Empty) {
function cleanKey(key) {
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
}
var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
while (stack.length > 1) {
if (!object) return {};
var key = cleanKey(stack.shift());
if (!object[key] && Empty) object[key] = new Empty();
object = object[key];
}
if (!object) return {};
return {
obj: object,
k: cleanKey(stack.shift())
};
}
export function setPath(object, path, newValue) {
var _getLastOfPath = getLastOfPath(object, path, Object),
obj = _getLastOfPath.obj,
k = _getLastOfPath.k;
if (Array.isArray(obj) && isNaN(k)) throw new Error("Cannot create property \"".concat(k, "\" here since object is an array"));
obj[k] = newValue;
}
export function pushPath(object, path, newValue, concat) {
var _getLastOfPath2 = getLastOfPath(object, path, Object),
obj = _getLastOfPath2.obj,
k = _getLastOfPath2.k;
obj[k] = obj[k] || [];
if (concat) obj[k] = obj[k].concat(newValue);
if (!concat) obj[k].push(newValue);
}
export function getPath(object, path) {
var _getLastOfPath3 = getLastOfPath(object, path),
obj = _getLastOfPath3.obj,
k = _getLastOfPath3.k;
if (!obj) return undefined;
return obj[k];
}

161
node_modules/i18next-fs-backend/esm/writeFile.js generated vendored Normal file
View File

@@ -0,0 +1,161 @@
import JSON5 from './formats/json5.js';
import jsYaml from './formats/yaml.js';
import extname from './extname.js';
var isDeno = typeof Deno !== 'undefined';
var isBun = typeof Bun !== 'undefined';
var YAML = typeof jsYaml !== 'undefined' && jsYaml.load ? jsYaml : undefined;
var fs = !isDeno ? (await import('node:fs')).default : undefined;
function dirname(path) {
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47) {
if (!matchedSlash) {
end = i;
break;
}
} else {
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) return '//';
return path.slice(0, end);
}
var writeFileInNodeSync = function writeFileInNodeSync(filename, payload) {
try {
fs.mkdirSync(dirname(filename), {
recursive: true
});
} catch (err) {}
return fs.writeFileSync(filename, payload, 'utf8');
};
var writeFileInNode = function writeFileInNode(filename, payload) {
return new Promise(function (resolve, reject) {
fs.mkdir(dirname(filename), {
recursive: true
}, function () {
fs.writeFile(filename, payload, 'utf8', function (err, data) {
return err ? reject(err) : resolve(data);
});
});
});
};
var removeFileInNodeSync = function removeFileInNodeSync(filename) {
return fs.unlinkSync(filename);
};
var removeFileInNode = function removeFileInNode(filename) {
return new Promise(function (resolve, reject) {
return fs.unlink(filename, function (err) {
return err ? reject(err) : resolve();
});
});
};
var writeFileInDenoSync = function writeFileInDenoSync(filename, payload) {
var encoder = new TextEncoder();
var data = encoder.encode(payload);
try {
Deno.mkdirSync(dirname(filename), {
recursive: true
});
} catch (err) {}
Deno.writeFileSync(filename, data);
};
var writeFileInDeno = function writeFileInDeno(filename, payload) {
var encoder = new TextEncoder();
var data = encoder.encode(payload);
return new Promise(function (resolve, reject) {
Deno.mkdir(dirname(filename), {
recursive: true
}).then(function () {
Deno.writeFile(filename, data).then(resolve, reject);
}).catch(function () {
Deno.writeFile(filename, data).then(resolve, reject);
});
});
};
var removeFileInDenoSync = function removeFileInDenoSync(filename) {
Deno.removeSync(filename);
};
var removeFileInDeno = function removeFileInDeno(filename) {
return Deno.remove(filename);
};
var writeFileInBunSync = writeFileInNodeSync;
var writeFileInBun = writeFileInNode;
var removeFileInBunSync = removeFileInNodeSync;
var removeFileInBun = removeFileInNode;
var stringifyData = function stringifyData(extension, data, options) {
var result = '';
switch (extension) {
case '.js':
case '.ts':
if (typeof module === 'undefined') {
result = "export default ".concat(options.stringify(data, null, options.ident));
} else {
result = "module.exports = ".concat(options.stringify(data, null, options.ident));
}
break;
case '.json5':
result = JSON5.stringify(data, null, options.ident);
break;
case '.yml':
case '.yaml':
result = YAML.dump(data, {
ident: options.indent
});
break;
default:
result = options.stringify(data, null, options.ident);
}
return result;
};
export function writeFileSync(filename, payload, options) {
var ext = extname(filename);
var data;
try {
data = stringifyData(ext, payload, options);
} catch (err) {
err.message = 'error stringifying ' + filename + ': ' + err.message;
throw err;
}
if (isBun) {
return writeFileInBunSync(filename, data);
} else if (isDeno) {
return writeFileInDenoSync(filename, data);
} else {
return writeFileInNodeSync(filename, data);
}
}
export function writeFile(filename, payload) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
stringify: JSON.stringify,
ident: 2
};
var ext = extname(filename);
var data;
try {
data = stringifyData(ext, payload, options);
} catch (err) {
err.message = 'error stringifying ' + filename + ': ' + err.message;
throw err;
}
var fn = isBun ? writeFileInBun : isDeno ? writeFileInDeno : writeFileInNode;
return fn(filename, data);
}
export function removeFileSync(filename) {
if (isBun) {
return removeFileInBunSync(filename);
} else if (isDeno) {
return removeFileInDenoSync(filename);
} else {
return removeFileInNodeSync(filename);
}
}
export function removeFile(filename) {
var fn = isBun ? removeFileInBun : isDeno ? removeFileInDeno : removeFileInNode;
return fn(filename);
}