[英]Svelte component text doesn't update
I'm using Blockly + SvelteJS, now I am trying to add language support.我正在使用 Blockly + SvelteJS,现在我正在尝试添加语言支持。 So I have Toolbox.svelte component that looks like this:
所以我有 Toolbox.svelte 组件,看起来像这样:
<xml id="toolbox" bind:this={toolbox} style="display:none">
<category name={Msg.CATEGORY_LOGIC} colour="#5b80a5">
<block type="controls_if" />
</category>
</xml>
<script>
import Blockly from "blockly";
$: Msg = Blockly.Msg;
export let toolbox = undefined;
</script>
And also I have a script that has update locale function.而且我还有一个更新语言环境 function 的脚本。 It updates Blockly.Msg
它更新 Blockly.Msg
import Blockly from "blockly";
import {categoryNames as categoryEN, blockNames as blockEN} from "./en_US.json";
import {categoryNames as categoryRU, blockNames as blockRU} from "./ru_RU.json";
export function applyBlocklyLocale(locale) {
switch (locale) {
case "en":
for (let key in categoryEN) {
Blockly.Msg["CATEGORY_" + key.toUpperCase()] = categoryEN[key];
};
for (let key in blockEN) {
Blockly.Msg["BLOCK_" + key.toUpperCase()] = categoryEN[key];
};
break;
case "ru":
for (let key in categoryRU) {
Blockly.Msg["CATEGORY_" + key.toUpperCase()] = categoryRU[key];
};
for (let key in blockRU) {
Blockly.Msg["BLOCK_" + key.toUpperCase()] = categoryRU[key];
};
break;
};
Blockly.Msg = Blockly.Msg
};
But when I run this function, Blockly.Msg updates, and toolbox xml doesn't但是当我运行这个 function,Blockly.Msg 更新和工具箱 xml 没有
This will not work:这将不起作用:
$: Msg = Blockly.Msg;
Reactivity does not cross certain boundaries;反应性不跨越某些界限; it only works within components and via props from component to component.
它仅适用于组件内以及通过组件从组件到组件的道具。
You will have to do this via events or use a store instead to preserve change notifications and reactivity.您将不得不通过事件或使用商店来保存更改通知和反应性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.