Blockly.setLocale do not translate all block
See original GitHub issueDescribe the bug
I want to change the language of blockly. Since Blockly needs to set the language before generating the Workspace, I regenerate the workspace every time I change the language using Blockly.setLocale, but not all blocks will be changed, some blocks’ dropdown menu language will not be changed and will remain the same.
To Reproduce here is online demo, i use vue2.
- Click on select button, change language English to Chinese.
- Check blocks’ language, specially dropdown menu.
- See Block do not all translate.
App.vue
<template>
<div id="app">
<div style="margin-bottom: 12px;">
<label for="language">language: </label>
<select name="language" id="language" v-model="language">
<option value="en">English</option>
<option value="zh-hans">Chinese</option>
<option value="zh-hant">Chinese(Trandition)</option>
</select>
</div>
<div class="workspace" ref="workspace" :key="workspaceId"></div>
</div>
</template>
<script>
import Blockly from "blockly";
export default {
name: "App",
components: {},
data() {
return {
workspace: null,
language: "en",
workspaceId: 0,
};
},
watch: {
async language() {
++this.workspaceId;
const lang = await import(`blockly/msg/${this.language}`);
Blockly.setLocale(lang);
this.initBlockly();
},
},
mounted() {
this.initBlockly();
},
methods: {
initBlockly() {
this.workspace = Blockly.inject(this.$refs.workspace, {
toolbox: `
<xml id="toolbox" style="display: none">
<block type="text"></block>
<block type="text_print"></block>
<block type="math_arithmetic">
<value name="A">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
<value name="B">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
</block>
<block type="math_single">
<value name="NUM">
<shadow type="math_number">
<field name="NUM">9</field>
</shadow>
</value>
</block>
<block type="math_trig">
<value name="NUM">
<shadow type="math_number">
<field name="NUM">45</field>
</shadow>
</value>
</block>
</xml>`,
});
},
},
};
</script>
<style>
.workspace {
width: 100vw;
height: 100vh;
}
</style>
Expected behavior
all blocks translate to current language.
Desktop (please complete the following information):
- OS
- Browser : Chrome
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Translations | Blockly - Google Developers
The default messages in Blockly (such as the text in the context menu) have been translated to many different languages. The en locale...
Read more >How to fix Blockly#setLocale not updating blocks arguments locales
I'm trying to add language changer to my blockly app, and when I run this method block names are updating but not their...
Read more >Blocklys Textblock input fields can not be edited when in a ...
Trying to write something in the "text"- or "math_number"-Block does not work, and when you close the modal, with an outside click, some ......
Read more >Translating:Blockly - translatewiki.net
Blocks in Blockly programs should be translated as children's building blocks. If that doesn't work in your language, "puzzle piece" is also ...
Read more >View Raw - UNPKG
Block } * @protected */ parentBlock_: Blockly. ... Do not go all the way to the root block. ... @param {number} x X...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This could be related to #4369.
thanks.