Реверснутый zcode с своими фишками и плагинами
Реверснутая ade zcode без z ai, с массовой загрузкой ключей, умным апи роутингом, плагином для командной разработки
Реверснутая ade zcode без z ai, с массовой загрузкой ключей, умным апи роутингом, плагином для командной разработки
// Выбор языка в разделе Appearance: System default / English / 中文简体 / Русский.
// Запуск: node tools/ru-locale-ui.mjs <styles-CQuzX8si.js>
import fs from 'node:fs';
const file = process.argv[2];
let s = fs.readFileSync(file, 'utf8');
if (s.includes('/*zcode-ru-locale*/')) {
console.log('already patched');
process.exit(0);
}
// 1. страница Appearance получает локаль и сеттер: {localePreference:h,setLocalePreference:g}
const pageAnchor = '/*zcode-ru-locale*/';
let page = s.indexOf('function lXn({codePreviewSettings:e,setCodePreviewSettings:t,theme:n,setTheme:r,uiFontSizePx:i,setUiFontSizePx:a})');
if (page < 0) throw new Error('Appearance page component not found');
s = s.replace(
'function lXn({codePreviewSettings:e,setCodePreviewSettings:t,theme:n,setTheme:r,uiFontSizePx:i,setUiFontSizePx:a}){let{intl:o}=q()',
`/*zcode-ru-locale*/function lXn({codePreviewSettings:e,setCodePreviewSettings:t,theme:n,setTheme:r,uiFontSizePx:i,setUiFontSizePx:a,localePreference:LP,setLocalePreference:LS}){let{intl:o}=q()`,
);
// вставить вызов компонента языков в конце блока интерфейса (после переключателя размера шрифта)
const fontAnchor = 'ariaLabel:o.formatMessage({id:`settings.uiFontSize`})},i)})]})})]})';
if (!s.includes(fontAnchor)) throw new Error('font size anchor not found');
s = s.replace(
fontAnchor,
'ariaLabel:o.formatMessage({id:`settings.uiFontSize`})},i)})]})}),__ruLocale(LP,LS)]})',
);
// 2. сам компонент + подписи
const component = `/*zcode-ru-locale*/function __ruLocale(LP,LS){
let{intl:o,locale:cur}=q();
let value=LP??"system";
return (0,$.jsx)(hL,{label:o.formatMessage({id:"settings.locale",defaultMessage:"Language"}),description:o.formatMessage({id:"settings.localeDescription",defaultMessage:"Choose the display language used by the application UI."}),control:(0,$.jsxs)(km,{value,onValueChange:e=>LS&&LS(e),children:[(0,$.jsx)(jm,{size:"lg",className:"w-[260px] min-w-0 justify-between",children:(0,$.jsx)(Am,{})}),(0,$.jsx)(Mm,{children:[["system","System default"],["en-US","English"],["ru-RU","Русский"],["zh-CN","中文简体"]].map(([e,t])=>(0,$.jsx)(Nm,{value:e,children:o.formatMessage({id:"settings.locale."+e,defaultMessage:t})},e))})]})});
}`;
s = s.replace('function lXn({', `${component}function lXn({`);
// 3. страница настроек передаёт локаль в Appearance
const call = 'C===`appearance`?(0,$.jsx)(lXn,{';
if (!s.includes(call)) throw new Error('Appearance call site not found');
s = s.replace(call, 'C===`appearance`?(0,$.jsx)(lXn,{localePreference:h,setLocalePreference:g,');
fs.writeFileSync(file, s);
console.log('patched language selector');