30天通github
https://github.com/doggy8088/Learn-Git-in-30-days
java script快速入門播放清單
https://youtube.com/playlist?list=PLxNBsYH_m6ywXdOfpVgibRbJzidecajoXscratch-vm index.js結構
//require基本架構
const ArgumentType = require('../../extension-support/argument-type');
const BlockType = require('../../extension-support/block-type');
const formatMessage = require('format-message');
const msg = require('./translation');
物件
class 物件名稱 {
//物件架構
constructor(runtime) {
the_locale = this._setLocale();
this.runtime = runtime;
}
//物件資料
getInfo() {
the_locale = this._setLocale();
return {
id: 'mqtt',
color1: '#003D79', //'#0C5986',
color2: '#34B0F7',
name: 'MQTT',
blockIconURI: 'data:image/png;base64,',
blocks: [
{
}
}
function(){
}
module.exports = 物件名稱;
語系
方法1:
在index.js中有
const msg = require('./translation');
物件中要有function定義語系
_setLocale() {
let now_locale = '';
switch (formatMessage.setup().locale) {
case 'zh-tw':
now_locale = 'zh-tw';
break;
default:
now_locale = 'en';
break;
}
return now_locale;
}
物件架構是呼叫function定義語系
constructor(runtime) {
the_locale = this._setLocale();
this.runtime = runtime;
}
使用方法:
msg.disconnect[the_locale];
在資料夾下,要有translation.js
檔案內容:
export const disconnect = {
'en': 'disconnected',
'zh-tw': '未連線',
};
方法2:
在index.js中加入語系物件
const formatMessage = require('format-message');
const FormLcdShow = {
'en': 'LCD show text [VALUE] at [ROW] row',
'zh-tw': 'LCD顯示文字[VALUE]在第[ROW]列',
};
在物件中加入架構
constructor(runtime,util) {
the_locale = this._setLocale();
this.runtime = runtime;
}
需要有function _setLocale()
_setLocale () {
let now_locale = '';
switch (formatMessage.setup().locale){
case 'en':
now_locale='en';
break;
case 'zh-tw':
now_locale= 'zh-tw';
break;
default:
now_locale='en';
break;
}
return now_locale;
}
使用方法
FormLcdShow [the_locale]
積木表示
在物件中使用陣列blocks: [ ]包括所有積木。
每個積木為一物件{}。內容為
opcode: 'digital_write',
blockType: BlockType.COMMAND,
text: FormDigitalWrite[the_locale],
arguments: {
PIN: {
type: ArgumentType.NUMBER,
defaultValue: 'D2',
menu: "digital_pins"
},
}
方法3:
/src/lib/libraries/extensions/index.jsx的
翻譯檔案在/node_modules/scratch-l10n/locales/editor-msgs.js
中文語系在最後面。
格式範例:
"gui.extension.microbitMore.description":"玩轉 micro:bit 的所有功能。(v2-0.2.4)",
沒有留言:
張貼留言