question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blockly.setLocale do not translate all block

See original GitHub issue

Describe 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.

  1. Click on select button, change language English to Chinese.
  2. Check blocks’ language, specially dropdown menu.
  3. See Block do not all translate.
截圖 2021-02-03 下午4 14 33

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
moniikacommented, Feb 8, 2021

This could be related to #4369.

1reaction
YUN-RU-TSENGcommented, Feb 23, 2021

thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found