Skip to content

Commit 89a16f5

Browse files
committed
move init_activity on frontend, for i18n
1 parent 999cab7 commit 89a16f5

File tree

6 files changed

+165
-64
lines changed

6 files changed

+165
-64
lines changed

src/assets/toolbox_adv.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"kind": "categoryToolbox",
33
"contents": [{
44
"kind": "category",
5-
"name": "Logica",
5+
"name": "message.blockly_toolbox_category_logic",
66
"colour": "210",
77
"contents": [{
88
"kind": "block",
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"kind": "category",
41-
"name": "Cicli",
41+
"name": "message.blockly_toolbox_category_cycles",
4242
"colour": "120",
4343
"contents": [{
4444
"kind": "block",
@@ -111,7 +111,7 @@
111111
},
112112
{
113113
"kind": "category",
114-
"name": "Matematica",
114+
"name": "message.blockly_toolbox_category_math",
115115
"colour": "230",
116116
"contents": [{
117117
"kind": "block",
@@ -322,7 +322,7 @@
322322
},
323323
{
324324
"kind": "category",
325-
"name": "Testo",
325+
"name": "message.blockly_toolbox_category_text",
326326
"colour": "160",
327327
"contents": [{
328328
"kind": "block",
@@ -511,7 +511,7 @@
511511
},
512512
{
513513
"kind": "category",
514-
"name": "Liste",
514+
"name": "message.blockly_toolbox_category_lists",
515515
"colour": "260",
516516
"contents": [{
517517
"kind": "block",
@@ -644,19 +644,19 @@
644644
},
645645
{
646646
"kind": "category",
647-
"name": "Variabili",
647+
"name": "message.blockly_toolbox_category_variables",
648648
"custom": "VARIABLE",
649649
"colour": "330"
650650
},
651651
{
652652
"kind": "category",
653-
"name": "Funzioni",
653+
"name": "message.blockly_toolbox_category_functions",
654654
"custom": "PROCEDURE",
655655
"colour": "290"
656656
},
657657
{
658658
"kind": "category",
659-
"name": "Eventi",
659+
"name": "message.blockly_toolbox_category_events",
660660
"colour": "15",
661661
"contents": [{
662662
"kind": "block",
@@ -749,7 +749,7 @@
749749
},
750750
{
751751
"kind": "category",
752-
"name": "Movimento",
752+
"name": "message.blockly_toolbox_category_movement",
753753
"colour": "40",
754754
"contents": [{
755755
"kind": "block",
@@ -922,7 +922,7 @@
922922
},
923923
{
924924
"kind": "category",
925-
"name": "CoderBot - Base",
925+
"name": "message.blockly_toolbox_category_base",
926926
"colour": "40",
927927
"contents": [{
928928
"kind": "block",
@@ -964,7 +964,7 @@
964964
},
965965
{
966966
"kind": "category",
967-
"name": "Camera",
967+
"name": "message.blockly_toolbox_category_camera",
968968
"colour": "120",
969969
"contents": [{
970970
"kind": "block",
@@ -982,7 +982,7 @@
982982
},
983983
{
984984
"kind": "category",
985-
"name": "Visione",
985+
"name": "message.blockly_toolbox_category_vision",
986986
"colour": "250",
987987
"contents": [{
988988
"kind": "block",
@@ -1048,7 +1048,7 @@
10481048
},
10491049
{
10501050
"kind": "category",
1051-
"name": "Sensori",
1051+
"name": "message.blockly_toolbox_category_sensors",
10521052
"colour": "240",
10531053
"contents": [{
10541054
"kind": "block",
@@ -1074,7 +1074,7 @@
10741074
},
10751075
{
10761076
"kind": "category",
1077-
"name": "Suoni",
1077+
"name": "message.blockly_toolbox_category_sound",
10781078
"colour": "220",
10791079
"contents": [{
10801080
"kind": "block",
@@ -1120,7 +1120,7 @@
11201120
},
11211121
{
11221122
"kind": "category",
1123-
"name": "Estensioni I/O",
1123+
"name": "message.blockly_toolbox_category_io_extensions",
11241124
"colour": "240",
11251125
"contents": [{
11261126
"kind": "block",
@@ -1196,7 +1196,7 @@
11961196
},
11971197
{
11981198
"kind": "category",
1199-
"name": "Music",
1199+
"name": "message.blockly_toolbox_category_music",
12001200
"colour": "345",
12011201
"contents": [{
12021202
"kind": "block",

src/common/coderbot.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import i18n from '../i18n/index';
2+
13
class CoderBot {
24
constructor(CB, APIv1, APIv2, axios, store) {
35
this.CB = CB + APIv2;
46
this.CBv1 = CB + APIv1;
57
this.$axios = axios;
68
this.$store = store;
9+
this.$i18n = i18n;
10+
this.initActivity();
711
}
812

913
load() {
@@ -13,6 +17,89 @@ class CoderBot {
1317
return Promise.all([p1, p2, p3]);
1418
}
1519

20+
initActivity() {
21+
this.loadActivity(null, true).then((activity) => {
22+
if (activity.data == '') {
23+
const toolbox_full = require('../assets/toolbox_adv.json');
24+
const defaultActivity = {
25+
stock: true,
26+
default: true,
27+
uiLang: 'browser',
28+
defaultView: null,
29+
exec: {
30+
camera: true,
31+
log: false
32+
},
33+
name: 'default',
34+
drawerEnabled: true,
35+
showName: true,
36+
description: '',
37+
fontSize: 'Medio',
38+
capsSwitch: true,
39+
bodyFont: 'Roboto',
40+
codeFont: 'ubuntumono',
41+
maxBlocks: 0,
42+
availableViews: [],
43+
viewSource: null,
44+
autoRecVideo: null,
45+
toolbox: null,
46+
buttons: [
47+
{
48+
action: 'clearProgramDlg',
49+
icon: 'clear',
50+
label: this.$i18n.t('message.activity_program_clear'),
51+
type: 'text',
52+
},
53+
{
54+
action: 'saveProgram',
55+
icon: 'save',
56+
label: this.$i18n.t('message.activity_program_save'),
57+
type: 'text',
58+
},
59+
{
60+
action: 'toggleSaveAs',
61+
icon: 'edit',
62+
label: this.$i18n.t('message.activity_program_save_as'),
63+
type: 'text',
64+
},
65+
{
66+
action: 'loadProgramList',
67+
icon: 'folder_open',
68+
label: this.$i18n.t('message.activity_program_load'),
69+
type: 'text',
70+
},
71+
{
72+
action: 'runProgram',
73+
icon: 'play_arrow',
74+
label: this.$i18n.t('message.activity_program_run'),
75+
type: 'text',
76+
},
77+
{
78+
action: 'getProgramCode',
79+
icon: 'code',
80+
label: this.$i18n.t('message.activity_program_show_code'),
81+
type: 'text',
82+
},
83+
{
84+
action: 'exportProgram',
85+
icon: 'fa-file-export',
86+
label: this.$i18n.t('message.activity_program_export'),
87+
type: 'text',
88+
},
89+
{
90+
action: 'pickFile',
91+
icon: 'fa-file-import',
92+
label: this.$i18n.t('message.activity_program_import'),
93+
type: 'text',
94+
}
95+
]
96+
};
97+
defaultActivity.toolbox = toolbox_full;
98+
this.saveActivity(defaultActivity);
99+
}
100+
});
101+
}
102+
16103
async loadMusicPackages() {
17104
const result = await this.$axios.get(`${this.CB}/listMusicPackages`);
18105
const packagesInstalled = [];

src/components/Activity.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
<template v-if="button.type == 'text'">
1818
<v-btn @click="_self[button.action]()" text>
1919
<v-icon>{{ button.icon }}</v-icon>
20-
{{ $t(button.label) }}
20+
{{ button.label }}
2121
</v-btn>
2222
</template>
2323
<template v-else>
2424
<v-btn @click="_self[button.action]()" style="height: 70%" :color="button.colorBtn"
2525
:class="button.colorText">
26-
{{ $t(button.label) }}
26+
{{ button.label }}
2727
<v-icon right dark>{{ button.icon }}</v-icon>
2828
</v-btn>
2929
</template>
@@ -375,13 +375,15 @@ export default {
375375
// Get the activity
376376
let activityName = this.$route.params.name;
377377
let activityDefault = false;
378-
if (this.$route.path == '/program') {
378+
if (this.$router.path == '/program') {
379379
activityName = this.$route.params.name;
380380
activityDefault = true;
381381
}
382382
this.$coderbot.loadActivity(activityName, activityDefault).then((activity) => {
383383
this.activity = activity.data;
384-
384+
if (this.activity.uiLang != 'browser') {
385+
this.$i18n.locale = this.activity.uiLang;
386+
}
385387
this.settings.maxBlocks = this.activity.maxBlocks;
386388
this.updateCssProps();
387389

0 commit comments

Comments
 (0)