setLocale problem in Angular app

79 views
Skip to first unread message

David

unread,
Oct 8, 2019, 9:07:16 AM10/8/19
to Blockly
Hello,

I got an error when trying to use the setLocale method as described in https://github.com/google/blockly-samples . 

I added the import to pt-br locale inside the blockly.component.ts file from the blockly-samples-master/blockly-angular:

import { ComponentOnInit } from '@angular/core';
import * as Blockly from 'blockly';
import * as PtBr from 'blockly/msg/pt-br';

and the call to the setLocale just before the Blockly.inject inside  ngOnInit() ...

  ngOnInit() {
    const blocklyDiv = document.getElementById('blocklyDiv');
    Blockly.setLocale(PtBr);
    Blockly.inject(blocklyDiv, {
...

... and the result is:

ERROR in src/app/blockly/blockly.component.ts(39,13): error TS2339: Property 'setLocale' does not exist on type 'typeof Blockly'.

Any clues to solve this problem? :-)

Node version: 10.16.3
Npm version : 6.0.9
Angular version: 8.1.2





Sam El-Husseini

unread,
Oct 8, 2019, 1:40:59 PM10/8/19
to Blockly
Hey David, 

Unfortunately there's an issue there with the Typescript typings where setLocale isn't added.
I'll fix this up in the upcoming release.

In order to unblock you, you can do: 
(Blockly as any).setLocale(PtBr);



Cheers,
Sam

David

unread,
Oct 9, 2019, 8:02:31 AM10/9/19
to Blockly
Hey, Sam.

Thanks for the solution and fast reply.

I still got the error on console: 

```
pt-br.js:8 Uncaught TypeError: Cannot set property 'Msg' of undefined
    at pt-br.js:8
    at pt-br.js:10
```

but the language changed.

I will use the same workaround for the custom blocks.

David.
Reply all
Reply to author
Forward
0 new messages