Files
klz-cables.com/.pnpm-store/v10/files/31/4514072d8c86613d680d5aab7d19eca233754b53a91ca532f40342beb7b71db2d6c8a07886e8025756b45f968e8743293954c2afd5d1ad59335265223ae599
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

43 lines
1.3 KiB
Plaintext

import { getSortedMessages, setNestedProperty } from '../../utils.js';
import { defineCodec } from '../ExtractorCodec.js';
var JSONCodec = defineCodec(() => ({
decode(source) {
const json = JSON.parse(source);
const messages = [];
traverseMessages(json, (message, id) => {
messages.push({
id,
message
});
});
return messages;
},
encode(messages) {
const root = {};
for (const message of getSortedMessages(messages)) {
setNestedProperty(root, message.id, message.message);
}
return JSON.stringify(root, null, 2) + '\n';
},
toJSONString(source) {
return source;
}
}));
function traverseMessages(obj, callback, path = '') {
const NAMESPACE_SEPARATOR = '.';
for (const key of Object.keys(obj)) {
const newPath = path ? path + NAMESPACE_SEPARATOR + key : key;
const value = obj[key];
if (typeof value === 'string') {
callback(value, newPath);
} else if (Array.isArray(value)) {
throw new Error(`Message at \`${newPath}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages`);
} else if (typeof value === 'object') {
traverseMessages(value, callback, newPath);
}
}
}
export { JSONCodec as default };