xcratch-create 0.3.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/create.js +3 -1
- package/package.json +1 -1
- package/template/README.md +0 -9
- package/template/dot_gitignore +2 -0
- package/template/package.json +4 -4
- package/template/src/{entry → gui/lib/libraries/extensions/entry}/entry-icon.png +0 -0
- package/template/src/{entry → gui/lib/libraries/extensions/entry}/index.jsx +10 -12
- package/template/src/{entry → gui/lib/libraries/extensions/entry}/inset-icon.svg +0 -0
- package/template/src/gui/lib/libraries/extensions/entry/translations.json +14 -0
- package/template/src/{entry → vm/extensions/block}/block-icon.png +0 -0
- package/template/src/vm/extensions/block/index.js +140 -0
- package/template/src/vm/extensions/block/translations.json +14 -0
- package/template/src/.eslintrc.js +0 -22
- package/template/src/block/index.js +0 -150
package/README.md
CHANGED
|
@@ -9,10 +9,10 @@ This command supports to create a new code base of an extension for [Xcratch](ht
|
|
|
9
9
|
npx xcratch-create --repo=xcx-my-extension --account=github-account --extensionID=myExtension --extensionName='My Extension'
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
- --repo : Name of repository on GitHub
|
|
12
|
+
- --repo : Name of the repository on GitHub
|
|
13
13
|
- --account : Account on GitHub
|
|
14
|
-
- --extensionID : ID of the extension in
|
|
15
|
-
- --extensionName :
|
|
14
|
+
- --extensionID : ID of the extension in Scratch (allowed RegExp `/^[a-z0-9]+$/i`)
|
|
15
|
+
- --extensionName : Label string of the extension on the Editor in English
|
|
16
16
|
- --version : Show version of this command
|
|
17
17
|
|
|
18
18
|
## 🤝 Contributing
|
package/bin/create.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require('path');
|
|
|
5
5
|
const replace = require('replace-in-file');
|
|
6
6
|
const fs = require('fs-extra');
|
|
7
7
|
const admZip = require('adm-zip');
|
|
8
|
+
const projectJson = require('../package.json');
|
|
8
9
|
|
|
9
10
|
function getArgs() {
|
|
10
11
|
const args = {};
|
|
@@ -32,7 +33,7 @@ function getArgs() {
|
|
|
32
33
|
const args = getArgs();
|
|
33
34
|
|
|
34
35
|
if (args['version'] || args['V']) {
|
|
35
|
-
process.stdout.write(`v
|
|
36
|
+
process.stdout.write(`v${projectJson.version}\n`);
|
|
36
37
|
process.exit(0);
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -78,6 +79,7 @@ const options = {
|
|
|
78
79
|
'package.json',
|
|
79
80
|
'src/**/*.js',
|
|
80
81
|
'src/**/*.jsx',
|
|
82
|
+
'src/**/*.json',
|
|
81
83
|
'projects/example/project.json',
|
|
82
84
|
],
|
|
83
85
|
from: [
|
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -39,15 +39,6 @@ Run build script to bundle this extension into a module file which could be load
|
|
|
39
39
|
npm run build
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
### Linting
|
|
43
|
-
|
|
44
|
-
Install Scratch eslint-config to coding.
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
npm install
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
51
42
|
## 🏠 Home Page
|
|
52
43
|
|
|
53
44
|
Open this page from [https://<<account>>.github.io/<<repo>>/](https://<<account>>.github.io/<<repo>>/)
|
package/template/dot_gitignore
CHANGED
package/template/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<<repo>>",
|
|
3
3
|
"version": "0.0.0",
|
|
4
|
-
"private": "true",
|
|
5
4
|
"scripts": {
|
|
6
|
-
"register": "npx xcratch-register --link -C --id=<<extensionID>> --gui=\"../scratch-gui\"",
|
|
7
|
-
"build": "npx xcratch-build --module=<<extensionID>> --gui=\"../scratch-gui\""
|
|
5
|
+
"register": "npx xcratch-register --link -C --id=<<extensionID>> --gui=\"../scratch-gui\" --block=\"./src/vm/extensions/block\" --entry\"./src/gui/lib/libraries/extensions/entry\"",
|
|
6
|
+
"build": "npx xcratch-build --module=<<extensionID>> --gui=\"../scratch-gui\" --block=\"./src/vm/extensions/block\" --entry\"./src/gui/lib/libraries/extensions/entry\""
|
|
8
7
|
},
|
|
9
8
|
"devDependencies": {
|
|
10
|
-
"
|
|
9
|
+
"xcratch-build": "^0.3.0",
|
|
10
|
+
"xcratch-register": "^0.3.1"
|
|
11
11
|
}
|
|
12
12
|
}
|
|
File without changes
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import iconURL from './entry-icon.png';
|
|
6
6
|
import insetIconURL from './inset-icon.svg';
|
|
7
|
+
import translations from './translations.json';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Formatter to translate the messages in this extension.
|
|
@@ -13,17 +14,14 @@ import insetIconURL from './inset-icon.svg';
|
|
|
13
14
|
*/
|
|
14
15
|
let formatMessage = messageData => messageData.defaultMessage;
|
|
15
16
|
|
|
16
|
-
const translationMap = {
|
|
17
|
-
'ja': {
|
|
18
|
-
'gui.extension.<<extensionID>>.description': 'Xcratch 拡張の例'
|
|
19
|
-
},
|
|
20
|
-
'ja-Hira': {
|
|
21
|
-
'gui.extension.<<extensionID>>.description': 'Xcratch (えくすくらっち)かくちょうのれい'
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
17
|
const entry = {
|
|
26
|
-
name
|
|
18
|
+
get name () {
|
|
19
|
+
return formatMessage({
|
|
20
|
+
id: '<<extensionID>>.entry.name',
|
|
21
|
+
default: '<<extensionName>>',
|
|
22
|
+
description: 'name of the extension'
|
|
23
|
+
});
|
|
24
|
+
},
|
|
27
25
|
extensionId: '<<extensionID>>',
|
|
28
26
|
extensionURL: 'https://<<account>>.github.io/<<repo>>/dist/<<extensionID>>.mjs',
|
|
29
27
|
collaborator: '<<account>>',
|
|
@@ -33,7 +31,7 @@ const entry = {
|
|
|
33
31
|
return formatMessage({
|
|
34
32
|
defaultMessage: 'an extension for Xcratch',
|
|
35
33
|
description: 'Description for this extension',
|
|
36
|
-
id: '
|
|
34
|
+
id: '<<extensionID>>.entry.description'
|
|
37
35
|
});
|
|
38
36
|
},
|
|
39
37
|
featured: true,
|
|
@@ -44,7 +42,7 @@ const entry = {
|
|
|
44
42
|
setFormatMessage: formatter => {
|
|
45
43
|
formatMessage = formatter;
|
|
46
44
|
},
|
|
47
|
-
translationMap:
|
|
45
|
+
translationMap: translations
|
|
48
46
|
};
|
|
49
47
|
|
|
50
48
|
export {entry}; // loadable-extension needs this line.
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"en": {
|
|
3
|
+
"<<extensionID>>.entry.name": "<<extensionName>>",
|
|
4
|
+
"<<extensionID>>.entry.description": "Description of this extension"
|
|
5
|
+
},
|
|
6
|
+
"ja": {
|
|
7
|
+
"<<extensionID>>.entry.name": "<<extensionName>>",
|
|
8
|
+
"<<extensionID>>.entry.description": "拡張機能の説明"
|
|
9
|
+
},
|
|
10
|
+
"ja-Hira": {
|
|
11
|
+
"<<extensionID>>.entry.name": "<<extensionName>>",
|
|
12
|
+
"<<extensionID>>.entry.description": "かくちょうきのうのせつめい"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import BlockType from '../../extension-support/block-type';
|
|
2
|
+
import ArgumentType from '../../extension-support/argument-type';
|
|
3
|
+
import Cast from '../../util/cast';
|
|
4
|
+
import translations from './translations.json';
|
|
5
|
+
import blockIcon from './block-icon.png';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Formatter which is used for translation.
|
|
9
|
+
* This will be replaced which is used in the runtime.
|
|
10
|
+
* @param {object} messageData - format-message object
|
|
11
|
+
* @returns {string} - message for the locale
|
|
12
|
+
*/
|
|
13
|
+
let formatMessage = messageData => messageData.defaultMessage;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Setup format-message for this extension.
|
|
17
|
+
*/
|
|
18
|
+
const setupTranslations = () => {
|
|
19
|
+
const localeSetup = formatMessage.setup();
|
|
20
|
+
if (localeSetup && localeSetup.translations[localeSetup.locale]) {
|
|
21
|
+
Object.assign(
|
|
22
|
+
localeSetup.translations[localeSetup.locale],
|
|
23
|
+
translations[localeSetup.locale]
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const EXTENSION_ID = '<<extensionID>>';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* URL to get this extension as a module.
|
|
32
|
+
* When it was loaded as a module, 'extensionURL' will be replaced a URL which is retrieved from.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
let extensionURL = 'https://<<account>>.github.io/<<repo>>/dist/<<extensionID>>.mjs';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Scratch 3.0 blocks for example of Xcratch.
|
|
39
|
+
*/
|
|
40
|
+
class ExtensionBlocks {
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @return {string} - the name of this extension.
|
|
44
|
+
*/
|
|
45
|
+
static get EXTENSION_NAME () {
|
|
46
|
+
return formatMessage({
|
|
47
|
+
id: '<<extensionID>>.name',
|
|
48
|
+
default: '<<extensionName>>',
|
|
49
|
+
description: 'name of the extension'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @return {string} - the ID of this extension.
|
|
55
|
+
*/
|
|
56
|
+
static get EXTENSION_ID () {
|
|
57
|
+
return EXTENSION_ID;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* URL to get this extension.
|
|
62
|
+
* @type {string}
|
|
63
|
+
*/
|
|
64
|
+
static get extensionURL () {
|
|
65
|
+
return extensionURL;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Set URL to get this extension.
|
|
70
|
+
* The extensionURL will be changed to the URL of the loading server.
|
|
71
|
+
* @param {string} url - URL
|
|
72
|
+
*/
|
|
73
|
+
static set extensionURL (url) {
|
|
74
|
+
extensionURL = url;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Construct a set of blocks for <<extensionName>>.
|
|
79
|
+
* @param {Runtime} runtime - the Scratch 3.0 runtime.
|
|
80
|
+
*/
|
|
81
|
+
constructor (runtime) {
|
|
82
|
+
/**
|
|
83
|
+
* The Scratch 3.0 runtime.
|
|
84
|
+
* @type {Runtime}
|
|
85
|
+
*/
|
|
86
|
+
this.runtime = runtime;
|
|
87
|
+
|
|
88
|
+
if (runtime.formatMessage) {
|
|
89
|
+
// Replace 'formatMessage' to a formatter which is used in the runtime.
|
|
90
|
+
formatMessage = runtime.formatMessage;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
doIt (args) {
|
|
95
|
+
const func = new Function(`return (${Cast.toString(args.SCRIPT)})`);
|
|
96
|
+
const result = func.call(this);
|
|
97
|
+
console.log(result);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @returns {object} metadata for this extension and its blocks.
|
|
103
|
+
*/
|
|
104
|
+
getInfo () {
|
|
105
|
+
setupTranslations();
|
|
106
|
+
return {
|
|
107
|
+
id: ExtensionBlocks.EXTENSION_ID,
|
|
108
|
+
name: ExtensionBlocks.EXTENSION_NAME,
|
|
109
|
+
extensionURL: ExtensionBlocks.extensionURL,
|
|
110
|
+
blockIconURI: blockIcon,
|
|
111
|
+
showStatusButton: false,
|
|
112
|
+
blocks: [
|
|
113
|
+
{
|
|
114
|
+
opcode: 'do-it',
|
|
115
|
+
blockType: BlockType.REPORTER,
|
|
116
|
+
blockAllThreads: false,
|
|
117
|
+
text: formatMessage({
|
|
118
|
+
id: '<<extensionID>>.doIt',
|
|
119
|
+
default: 'do it [SCRIPT]',
|
|
120
|
+
description: 'execute javascript for example'
|
|
121
|
+
}),
|
|
122
|
+
func: 'doIt',
|
|
123
|
+
arguments: {
|
|
124
|
+
SCRIPT: {
|
|
125
|
+
type: ArgumentType.STRING,
|
|
126
|
+
defaultValue: '3 + 4'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
menus: {
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
ExtensionBlocks as default,
|
|
139
|
+
ExtensionBlocks as blockClass
|
|
140
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"en": {
|
|
3
|
+
"<<extensionID>>.name": "<<extensionName>>",
|
|
4
|
+
"<<extensionID>>.doIt": "do it [SCRIPT]"
|
|
5
|
+
},
|
|
6
|
+
"ja": {
|
|
7
|
+
"<<extensionID>>.name": "<<extensionName>>",
|
|
8
|
+
"<<extensionID>>.doIt": "[SCRIPT] を実行する"
|
|
9
|
+
},
|
|
10
|
+
"ja-Hira": {
|
|
11
|
+
"<<extensionID>>.name": "<<extensionName>>",
|
|
12
|
+
"<<extensionID>>.doIt": "[SCRIPT] をじっこうする"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
extends: ['scratch', 'scratch/node', 'scratch/es6', 'scratch/react'],
|
|
4
|
-
env: {
|
|
5
|
-
browser: true,
|
|
6
|
-
worker: true
|
|
7
|
-
},
|
|
8
|
-
globals: {
|
|
9
|
-
process: true,
|
|
10
|
-
Scratch: true
|
|
11
|
-
},
|
|
12
|
-
rules: {
|
|
13
|
-
'no-confusing-arrow': ['error', {
|
|
14
|
-
allowParens: true
|
|
15
|
-
}]
|
|
16
|
-
},
|
|
17
|
-
settings: {
|
|
18
|
-
react: {
|
|
19
|
-
version: '16.2' // Prevent 16.3 lifecycle method errors
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
const BlockType = require('../../extension-support/block-type');
|
|
2
|
-
const ArgumentType = require('../../extension-support/argument-type');
|
|
3
|
-
// const cast = require('../../util/cast');
|
|
4
|
-
// const log = require('../../util/log');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Formatter which is used for translation.
|
|
8
|
-
* This will be replaced which is used in the runtime.
|
|
9
|
-
* @param {*} messageData - format-message object
|
|
10
|
-
* @returns {string} - message for the locale
|
|
11
|
-
*/
|
|
12
|
-
let formatMessage = messageData => messageData.defaultMessage;
|
|
13
|
-
|
|
14
|
-
const EXTENSION_ID = '<<extensionID>>';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* URL to get this extension as a module.
|
|
18
|
-
* When it was loaded as a module, 'extensionURL' will be replaced a URL which is retrieved from.
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
let extensionURL = 'https://<<account>>.github.io/<<repo>>/dist/<<extensionID>>.mjs';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Icon png to be displayed at the left edge of each extension block, encoded as a data URI.
|
|
25
|
-
* @type {string}
|
|
26
|
-
*/
|
|
27
|
-
// eslint-disable-next-line max-len
|
|
28
|
-
const blockIconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAABgWlDQ1BzUkdCIElFQzYxOTY2LTIuMQAAKJF1kctLQkEUh7+0MHpgUESLFhLWSsMKpDZBRlggEWbQa6PXV6B2ufdGRNugrVAQtem1qL+gtkHrICiKINoFrYvalNzOVUGJPMOZ881v5hxmzoAtklGyer0PsjlDCwcDrvmFRZfjFTsObHTiiSq6OjYzE6KmfT1QZ8U7r1Wr9rl/rTme0BWoaxQeVVTNEJ4UDq0bqsW7wh1KOhoXPhf2aHJB4XtLj5X4zeJUiX8s1iLhcbC1CbtSVRyrYiWtZYXl5bizmTWlfB/rJS2J3NysxB7xbnTCBAngYooJxvEzwIjMfrwM0i8rauT7ivnTrE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rb3T9VNeuUAGsFMktVXzjG82xIi4MnuVNGrasZAcYCPwBKA3YLpmFaIiJV/J/S6b82VDQYGIn3DAAAAABJRU5ErkJggg==';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Scratch 3.0 blocks for example of Xcratch.
|
|
32
|
-
*/
|
|
33
|
-
class ExtensionBlocks {
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @return {string} - the name of this extension.
|
|
37
|
-
*/
|
|
38
|
-
static get EXTENSION_NAME () {
|
|
39
|
-
return '<<extensionName>>';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @return {string} - the ID of this extension.
|
|
44
|
-
*/
|
|
45
|
-
static get EXTENSION_ID () {
|
|
46
|
-
return EXTENSION_ID;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* URL to get this extension.
|
|
51
|
-
* @type {string}
|
|
52
|
-
*/
|
|
53
|
-
static get extensionURL () {
|
|
54
|
-
return extensionURL;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Set URL to get this extension.
|
|
59
|
-
* extensionURL will be reset when the module is loaded from the web.
|
|
60
|
-
* @param {string} url - URL
|
|
61
|
-
*/
|
|
62
|
-
static set extensionURL (url) {
|
|
63
|
-
extensionURL = url;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Construct a set of blocks for <<extensionName>>.
|
|
68
|
-
* @param {Runtime} runtime - the Scratch 3.0 runtime.
|
|
69
|
-
*/
|
|
70
|
-
constructor (runtime) {
|
|
71
|
-
/**
|
|
72
|
-
* The Scratch 3.0 runtime.
|
|
73
|
-
* @type {Runtime}
|
|
74
|
-
*/
|
|
75
|
-
this.runtime = runtime;
|
|
76
|
-
|
|
77
|
-
if (runtime.formatMessage) {
|
|
78
|
-
// Replace 'formatMessage' to a formatter which is used in the runtime.
|
|
79
|
-
formatMessage = runtime.formatMessage;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @returns {object} metadata for this extension and its blocks.
|
|
85
|
-
*/
|
|
86
|
-
getInfo () {
|
|
87
|
-
this.setupTranslations();
|
|
88
|
-
return {
|
|
89
|
-
id: ExtensionBlocks.EXTENSION_ID,
|
|
90
|
-
name: ExtensionBlocks.EXTENSION_NAME,
|
|
91
|
-
extensionURL: ExtensionBlocks.extensionURL,
|
|
92
|
-
blockIconURI: blockIconURI,
|
|
93
|
-
showStatusButton: false,
|
|
94
|
-
blocks: [
|
|
95
|
-
{
|
|
96
|
-
opcode: 'do-it',
|
|
97
|
-
blockType: BlockType.REPORTER,
|
|
98
|
-
blockAllThreads: false,
|
|
99
|
-
text: formatMessage({
|
|
100
|
-
id: '<<extensionID>>.doIt',
|
|
101
|
-
default: 'do it [SCRIPT]',
|
|
102
|
-
description: 'execute javascript for example'
|
|
103
|
-
}),
|
|
104
|
-
func: 'doIt',
|
|
105
|
-
arguments: {
|
|
106
|
-
SCRIPT: {
|
|
107
|
-
type: ArgumentType.STRING,
|
|
108
|
-
defaultValue: '3 + 4'
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
],
|
|
113
|
-
menus: {
|
|
114
|
-
},
|
|
115
|
-
// eslint-disable-next-line no-use-before-define
|
|
116
|
-
translationMap: extensionTranslations
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
doIt (args) {
|
|
121
|
-
const func = new Function(`return (${args.SCRIPT})`);
|
|
122
|
-
return func.call(this);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Setup format-message for this extension.
|
|
128
|
-
*/
|
|
129
|
-
setupTranslations () {
|
|
130
|
-
const localeSetup = formatMessage.setup();
|
|
131
|
-
if (localeSetup && localeSetup.translations[localeSetup.locale]) {
|
|
132
|
-
Object.assign(
|
|
133
|
-
localeSetup.translations[localeSetup.locale],
|
|
134
|
-
// eslint-disable-next-line no-use-before-define
|
|
135
|
-
extensionTranslations[localeSetup.locale]
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const extensionTranslations = {
|
|
142
|
-
'ja': {
|
|
143
|
-
'<<extensionID>>.doIt': '[SCRIPT] を実行する'
|
|
144
|
-
},
|
|
145
|
-
'ja-Hira': {
|
|
146
|
-
'<<extensionID>>.doIt': '[SCRIPT] をじっこうする'
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
module.exports = ExtensionBlocks;
|