From eca7bfd9bcec8f7d8a4e36b992b6247dcf63c7c3 Mon Sep 17 00:00:00 2001 From: unknown <348063288@qq.com> Date: Sat, 24 Jun 2023 23:08:52 +0800 Subject: [PATCH] localization optimize, thanks @MKhichain --- i18n/zh_CN/ps-plugin.json | 174 ++++++++++++++++++ .../zh_CN/sd-official.json | 0 manifest.json | 6 +- .../{main => locale}/locale-for-old-html.ts | 9 +- typescripts/locale/locale.ts | 50 ++++- typescripts/locale/zh_CN/zh_Hans_PS.json | 9 - typescripts/main/main.tsx | 2 +- webpack.config.js | 1 + 8 files changed, 227 insertions(+), 24 deletions(-) create mode 100644 i18n/zh_CN/ps-plugin.json rename typescripts/locale/zh_CN/zh_Hans.json => i18n/zh_CN/sd-official.json (100%) rename typescripts/{main => locale}/locale-for-old-html.ts (96%) delete mode 100644 typescripts/locale/zh_CN/zh_Hans_PS.json diff --git a/i18n/zh_CN/ps-plugin.json b/i18n/zh_CN/ps-plugin.json new file mode 100644 index 0000000..4dabd9a --- /dev/null +++ b/i18n/zh_CN/ps-plugin.json @@ -0,0 +1,174 @@ +{ + "Auto-Photoshop-SD": "SD插件(明空汉化)", + "'A' for Automatic1111 server (webui-user.bat), Green is connected. Red Means there is a problem with your Automatic1111. Run 'webui-user.bat' and hit 'Refresh' button ": "", + "'P' for proxy server (start_server.bat), Green is connected. Red means you need to run 'start_server.bat' or hit Refresh button": "", + "Stable Diffusion": "稳定扩散", + "Stable Diffusion UI": "稳定扩散 UI", + "Refresh": "刷新", + "Refresh the plugin, only fixes minor issues.": "刷新插件,仅修复小问题。", + "Update": "更新", + "Update the plugin if you encounter bugs. Get the latest features": "如果遇到错误,请更新插件。 获取最新功能", + "Select Lora": "选择 Lora", + "use lora in your prompt": "在提示中使用 lora", + "Generate": "生成", + "Generate txt2img": "生成 txt2img", + "Progress...": "进度...", + "Toggle the visibility of the Preview Image on the canvas": "切换画布上预览图像的可见性", + "Move and reSize the highlighted layer to fit into the Selection Area": "移动和调整突出显示的图层以适合选择区域", + "create a snapshot of what you see on the canvas and place on a new layer": "创建画布上看到的快照并放置在新图层上", + "reset the ui settings to their default values": "将 UI 设置重置为默认值", + "Interrogate the selected area, convert Image to Prompt": "审问所选区域,将图像转换为提示", + "use this mode to generate images from text only": "使用此模式仅从文本生成图像", + "use this mode to generate variation of an image": "使用此模式生成图像的变体", + "use this mode to generate variation of a small area of an image, while keeping the rest of the image intact": "使用此模式生成图像的小区域的变体,同时保持图像的其余部分完好无损", + "use this mode to (1) fill any missing area of an image,(2) expand an image": "使用此模式来(1)填充图像的任何缺失区域,(2)扩展图像", + "Image": "图像", + "Mask": "蒙版", + "Batch Size:": "批量大小:", + "Batch Count:": "批量计数:", + "Steps:": "步数:", + "Selection Mode:": "选择模式:", + "ratio": "比率", + "precise": "精确", + "use the selection area width and height to fill the width and height sliders": "使用选择区域的宽度和高度来填充宽度和高度滑块", + "ignore": "忽略", + "fill the width and height sliders manually": "手动填充宽度和高度滑块", + "Smart Preset": "智能预设", + "auto fill the plugin with smart settings, to speed up your working process.": "自动填充智能设置的插件,以加快您的工作流程。", + "Width:": "宽度:", + "maintain the ratio between width and height slider": "保持宽度和高度滑块之间的比例", + "Height:": "高度:", + "CFG Scale:": "CFG 比例:", + "larger value will put more emphasis on the prompt": "较大的值将更加强调提示", + "Denoising Strength:": "降噪强度:", + "Image CFG Scale:": "图像 CFG 比例:", + "Pix2Pix CFG Scale (larger value will put more emphasis on the image)": "Pix2Pix CFG 比例(较大的值将更加强调图像)", + "Mask Blur:": "蒙版模糊:", + "Mask Expansion:": "蒙版扩展:", + "the larger the value the more the mask will expand, '0' means use precise masking, use in combination with the mask blur": "值越大,蒙版就会扩展得越多,“ 0”表示使用精确的蒙版,与蒙版模糊一起使用", + "Inpainting conditioning mask strength:": "修复条件蒙版强度:", + "0 will keep the composition; 1 will allow composition to change": "0将保持构图; 1将允许构图发生变化", + "Mask Content:": "蒙版内容:", + "fill": "填充", + "original": "原始", + "latent noise": "潜在噪声", + "latent nothing": "潜在无", + "Inpaint at Full Res": "在全分辨率下修复", + "Restore Faces": "面部修复", + "Hi Res Fix": "高分修复", + "Upscaler: ": "放大器:", + "Hi Res Steps:": "高分步数:", + "Hi Res Scale:": "高分比例:", + "Hi Res Denoising Strength:": "高分降噪强度:", + "Hi Res Output Width:": "高分输出宽度:", + "Hi Res Output Height:": "高分输出高度:", + "Inpaint Padding:": "修复填充:", + "Seed:": "种子:", + "Random": "随机", + "Last": "最后", + "Show Samplers": "显示采样器", + "Select A Script": "选择脚本", + "Activate": "激活", + "Viewer": "查看器", + "View your generated images on the canvas": "在画布上查看生成的图像", + "Set Mask": "设置蒙版", + "Set Init Image": "设置初始图像", + "Interrupt": "中断", + "Selection Area": "选择区域", + "Thumbnail Size:": "缩略图大小:", + "Square 1:1": "正方形 1:1", + "Prompts Library": "提示库", + "Prompt Shortcut: a single word that represent a prompt": "提示快捷方式:代表提示的单个单词", + "Key for new prompt shortcut": "新提示快捷方式的键", + "to be replaced": "要被替换的", + "Value for new prompt shortcut": "新提示快捷方式的值", + "to be replaced with": "要被替换为", + "Add to Prompt Shortcut": "添加到提示快捷方式", + "prompt shortcut": "提示快捷方式", + "Selection a prompt": "选择提示词", + "Refresh Menu": "刷新菜单", + "Load": "加载", + "Save": "保存", + "History": "历史记录", + "history of all the images you generated": "您生成的所有图像的历史记录", + "Load Previous Generations": "加载以前的生成", + "Clear Results": "清除结果", + "Lexica": "Lexica", + "Explore Lexica for prompts and inspiration": "探索提示词和灵感的词典", + "Search:": "搜索:", + "user prompt(text) to Search Lexica": "用户提示(文本)搜索词典", + "User the selected area (image) on canvas to Search Lexica": "用户在画布上选择的区域(图像)搜索词典", + "Image Search": "图像搜索", + "Image Search Engine": "图像搜索引擎", + "ControlNet": "控制网络", + "The Controlnet Extension is missing from Automatic1111.Please install it to use it through the plugin.": "Automatic1111缺少控制网络扩展。请安装它以通过插件使用它。", + "ControlNet Preset": "控制网络预设", + "auto fill the ControlNet with smart settings, to speed up your working process.": "自动填充智能设置的控制网络,以加快您的工作流程。", + "Set All CtrlNet Images": "设置所有 CtrlNet 图像", + "Disable ControlNet Tab": "禁用控制网络选项卡", + "Control Net Settings Slot 0": "控制网络设置插槽0", + "Set CtrlNet Img": "设置 CtrlNet 图像", + "Preview Annotator": "预览注释器", + "Enable": "启用", + "Low VRAM": "低显存", + "Guess Mode": "猜测模式", + "Weight:": "权重:", + "2 will keep the composition; 0 will allow composition to change": "2将保持构图; 0将允许构图发生变化", + "Guidance strength start:": "Guidance strength start:", + "Guidance strength end:": "Guidance strength end:", + "Horde": "Horde", + "Horde Key:": "Horde密钥:", + "Select Backend:": "选择后端:", + "Native Horde": "本机 Horde", + "use the horde with the plugin no need to install anything else": "使用插件的 Horde,无需安装其他任何内容", + "Auto1111 Horde Extension": "Auto1111 Horde 扩展", + "Use the horde extension from Automatic1111 Extension tab": "使用 Automatic1111 扩展选项卡中的 Horde 扩展", + "Auto1111 Only": "仅限 Auto1111", + "use Auto1111 disable the Horde": "使用 Auto1111 禁用 Horde", + "Refresh Models": "刷新模型", + "NSFW": "NSFW", + "Share with LION": "与 LION 共享", + "Extras": "额外", + "Resize": "调整大小", + "Resize scale of current selection size": "调整当前选择大小的比例", + "Generate upscale": "生成放大", + "No work in progress": "没有正在进行的工作", + "Upscaler 1:": "放大算法 1:", + "Upscaler 2:": "放大算法 2:", + "Upscaler 2 visibility:": "放大算法 2 可见性:", + "GFPGAN visibility:": "GFPGAN 可见性:", + "CodeFormer visibility:": "CodeFormer 可见性:", + "CodeFormer weight:": "CodeFormer 权重:", + "Settings": "设置", + "Custom Presets": "自定义预设", + "SD Url:": "SD Url:", + "Submit": "提交", + "use sharp mask": "使用锐化蒙版", + "Smart Object": "智能对象", + "Live Progress Image": "实时进度图像", + "Restore Original Prompt": "恢复原始提示", + "Image Cfg Scale Slider": "图像配置比例滑块", + "Use Silent Mode": "使用静默模式", + "Your PC Speed(optimization):": "电脑性能(优化):", + "Slow PC": "节能模式", + "Fast PC": "高性能模式", + "Use Colab": "使用 Colab", + "Select Extension:": "选择扩展:", + "Proxy Server": "代理服务器", + "use the proxy server, need to run 'start_server.bat' ": "使用代理服务器,需要运行“start_server.bat”", + "Auto111 Extension": "SD扩展", + "use Automatic1111 Photoshop SD Extension, need to install the extension in Auto1111": "使用Photoshop SD 扩展,需要在 Auto1111 中安装扩展", + "None": "无", + "Use the Plugin Only No Additional Component": "仅使用插件,无需其他组件", + "Folder Path (read only):": "文件夹路径(只读):", + "copy paste the address to access the folder where the images are stored": "复制粘贴地址以访问存储图像的文件夹", + "Get Path": "获取路径", + "Preset Name": "预设名称", + "New Preset": "新建预设", + "Preset Type:": "预设类型:", + "SD Preset": "SD 预设", + "Save Preset": "保存预设", + "Delete Preset": "删除预设", + "The Controlnet Extension is missing from Automatic1111.\nPlease install it to use it through the plugin.": "本地SD中缺少控制网扩展。\n请安装该插件后再使用。", + "Set CtrlImg": "设置原始图" + } \ No newline at end of file diff --git a/typescripts/locale/zh_CN/zh_Hans.json b/i18n/zh_CN/sd-official.json similarity index 100% rename from typescripts/locale/zh_CN/zh_Hans.json rename to i18n/zh_CN/sd-official.json diff --git a/manifest.json b/manifest.json index 4f60a31..995db58 100644 --- a/manifest.json +++ b/manifest.json @@ -40,7 +40,8 @@ "label": { "default": "Auto-Photoshop-SD", "en-US": "Auto-Photoshop-SD", - "es-ES": "Auto-Photoshop-SD" + "es-ES": "Auto-Photoshop-SD", + "zh-CN": "SD插件(明空汉化)" }, "minimumSize": { "width": 400, @@ -92,7 +93,8 @@ "label": { "default": "Second Auto-Photoshop-SD", "en-US": "Second Auto-Photoshop-SD", - "es-ES": "Second Auto-Photoshop-SD" + "es-ES": "Second Auto-Photoshop-SD", + "zh-CN": "SD插件(明空汉化)" }, "minimumSize": { "width": 100, diff --git a/typescripts/main/locale-for-old-html.ts b/typescripts/locale/locale-for-old-html.ts similarity index 96% rename from typescripts/main/locale-for-old-html.ts rename to typescripts/locale/locale-for-old-html.ts index e311122..95cd0dd 100644 --- a/typescripts/main/locale-for-old-html.ts +++ b/typescripts/locale/locale-for-old-html.ts @@ -1,12 +1,12 @@ import { reaction } from 'mobx' import globalStore from '../globalstore' -import Locale from '../locale/locale' +import Locale from './locale' const elemSelectorForLocale = { // tab bar - '#sp-stable-diffusion-ui-tab sp-label': 'StableDiffusion', + '#sp-stable-diffusion-ui-tab sp-label': 'Stable Diffusion', '#sp-viewer-tab sp-label': 'Viewer', - '#sp-control_net-label': 'Controlet', + '#sp-control_net-tab sp-label': 'ControlNet', '#sp-history-tab sp-label': 'History', '#sp-lexica-tab sp-label': 'Lexica', '#sp-image_search-tab sp-label': 'Image Search', @@ -84,7 +84,6 @@ const elemSelectorForLocale = { '#sdLabelSampleStep': 'Sampling Steps', } -reaction(() => globalStore.Locale, renderLocale) function renderLocale(locale: string) { Object.keys(elemSelectorForLocale).forEach((selector) => { const elem = document.querySelector(selector) @@ -94,4 +93,6 @@ function renderLocale(locale: string) { } }) } + +reaction(() => globalStore.Locale, renderLocale) renderLocale(globalStore.Locale) diff --git a/typescripts/locale/locale.ts b/typescripts/locale/locale.ts index 1a29df7..922287e 100644 --- a/typescripts/locale/locale.ts +++ b/typescripts/locale/locale.ts @@ -1,18 +1,52 @@ import globalStore from '../globalstore' -import zhHans from './zh_CN/zh_Hans.json' -import zhHansForPSPlugin from './zh_CN/zh_Hans_PS.json' +import type zhHans from '../../i18n/zh_CN/sd-official.json' +import type zhHansForPSPlugin from '../../i18n/zh_CN/ps-plugin.json' +import { lstatSync, readFileSync } from 'fs' + +const localeFileCache: any = {} + +function isExists(path: string): boolean { + try { + lstatSync(path) + console.log(path, 'exists') + return true + } catch (e) { + console.log(path, 'not exists') + return false + } +} export default function Locale( key: keyof typeof zhHans | keyof typeof zhHansForPSPlugin ): string { const locale = globalStore.Locale - let res = '' - if (locale == 'zh_CN') { - //@ts-ignore - if (key in zhHansForPSPlugin) res = zhHansForPSPlugin[key] - //@ts-ignore - if (key in zhHans) res = zhHans[key] + + const sdOfficialJSONPath = `plugin:/i18n/${locale}/sd-official.json` + let sdOfficialTranslate = localeFileCache[sdOfficialJSONPath] + if (!localeFileCache[sdOfficialJSONPath] && isExists(sdOfficialJSONPath)) { + console.log('readFile') + sdOfficialTranslate = JSON.parse( + readFileSync(sdOfficialJSONPath, 'utf-8') + ) + localeFileCache[sdOfficialJSONPath] = sdOfficialTranslate } + + const psPluginJSONPath = `plugin:/i18n/${locale}/ps-plugin.json` + let psPluginTranslate = localeFileCache[psPluginJSONPath] + if (!localeFileCache[psPluginJSONPath] && isExists(psPluginJSONPath)) { + console.log('readFile') + psPluginTranslate = JSON.parse(readFileSync(psPluginJSONPath, 'utf-8')) + localeFileCache[psPluginJSONPath] = psPluginTranslate + } + + let res = '' + //@ts-ignore + if (sdOfficialTranslate && key in sdOfficialTranslate) + res = sdOfficialTranslate[key] + //@ts-ignore + if (psPluginTranslate && key in psPluginTranslate) + res = psPluginTranslate[key] + res = res || key return res } diff --git a/typescripts/locale/zh_CN/zh_Hans_PS.json b/typescripts/locale/zh_CN/zh_Hans_PS.json deleted file mode 100644 index 8458d5f..0000000 --- a/typescripts/locale/zh_CN/zh_Hans_PS.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "The Controlnet Extension is missing from Automatic1111.\nPlease install it to use it through the plugin.": "本地SD中缺少控制网扩展。\n请安装该插件后再使用。", - "Set CtrlImg": "设置原始图", - "Preview Annotator": "查看标注图", - "Progress...": "进度...", - "Random": "随机", - "Last": "上一个", - "Show Samplers": "显示采样方法" -} diff --git a/typescripts/main/main.tsx b/typescripts/main/main.tsx index b934f1e..d0f882c 100644 --- a/typescripts/main/main.tsx +++ b/typescripts/main/main.tsx @@ -6,7 +6,7 @@ import { SpMenu } from '../util/elements' import { api, python_replacement } from '../util/oldSystem' const { getExtensionUrl } = python_replacement -import './locale-for-old-html' +import '../locale/locale-for-old-html' declare let g_sd_url: string // class SDStore extends AStore { diff --git a/webpack.config.js b/webpack.config.js index cb8db4f..3d97592 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -19,6 +19,7 @@ module.exports = { uxp: 'commonjs2 uxp', photoshop: 'commonjs2 photoshop', os: 'commonjs2 os', + fs: 'commonjs2 fs', }, resolve: { extensions: ['.tsx', '.ts', '.js', '.jsx'],