Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 198 additions & 4 deletions extensions/vercte/dictionaries.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,167 @@
// Name: Dictionaries

Check failure on line 1 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / validate

Validation error

Error: Missing // License: -- We recommend using // License: MPL-2.0
// ID: verctedictionaries
// Description: Use the power of dictionaries in your project.
// By: Vercte <https://scratch.mit.edu/users/lolecksdeehaha/>
, LSPECTRONIZTAR <https://scratch.mit.edu/users/LSPECTRONIZTAR/>

Check warning on line 5 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

';' expected.

Check warning on line 5 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

Cannot find name 'https'.

Check warning on line 5 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

Cannot find name 'LSPECTRONIZTAR'.

Check warning on line 5 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

Declaration or statement expected.
// License: MIT

(function (Scratch) {
/* generated l10n code */ Scratch.translate.setup({
fi: {
_Dictionaries: "Sanakirjat",
"_change key [KEY] in dictionary [DICT] by [BY]":
"lisää sanakirjan [DICT] avaimeen [KEY] arvo [BY]",
"_key [KEY] from dictionary [DICT]": "sanakirjan [DICT] avain [KEY]",
"_key [KEY] in dictionary [DICT] is defined?":
"onko avain [KEY] määritelty sanakirjassa [DICT]?",
"_key [KEY] in dictionary [DICT] is null?":
"onko sanakirjan [DICT] avaimen [KEY] arvo null?",
"_list of dictionaries": "sanakirjaluettelo",
"_parse JSON [OBJ] into dictionary [DICT]":
"muunna JSON-koodi [OBJ] sanakirjaksi [DICT]",
"_remove dictionary [DICT]": "poista sanakirja [DICT]",
"_remove key [KEY] from dictionary [DICT]":
"poista avain [KEY] sanakirjasta [DICT]",
"_set key [KEY] in dictionary [DICT] to [VAL]":
"aseta sanakirjan [DICT] avain [KEY] arvoon [VAL]",
"_stringify dictionary [DICT] into JSON": "sanakirja [DICT] JSON-muodossa",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"hanki sanakirja [DICT] JSON-merkkijonona [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]":
"aseta sanakirja [DICT] JSON:ksi [OBJ]",
_stringified: "merkkijonotettu",
_parsed: "jäsennelty",
},
it: {
_Dictionaries: "Dizionari",
"_change key [KEY] in dictionary [DICT] by [BY]":
"cambia chiave [KEY] del dizionario [DICT] di [BY]",
"_key [KEY] from dictionary [DICT]": "chiave [KEY] del dizionario [DICT]",
"_key [KEY] in dictionary [DICT] is defined?":
"chiave [KEY] definita in dizionario [DICT]",
"_key [KEY] in dictionary [DICT] is null?":
"chiave [KEY] vuota in dizionario [DICT]",
"_list of dictionaries": "lista dizionari",
"_parse JSON [OBJ] into dictionary [DICT]":
"JSON [OBJ] come dizionario [DICT]",
"_remove dictionary [DICT]": "elimina dizionario [DICT]",
"_remove key [KEY] from dictionary [DICT]":
"rimuovi chiave [KEY] da dizionario [DICT]",
"_set key [KEY] in dictionary [DICT] to [VAL]":
"porta chiave [KEY] del dizionario [DICT] a [VAL]",
"_stringify dictionary [DICT] into JSON":
"contenuto dizionario [DICT] come JSON",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"ottieni dizionario [DICT] come JSON [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]":
"imposta dizionario [DICT] con JSON [OBJ]",
_stringified: "in formato JSON",
_parsed: "analizzato",
},
ja: {
_Dictionaries: "辞書",
"_list of dictionaries": "辞書のリスト",
"_parse JSON [OBJ] into dictionary [DICT]":
"JSON[OBJ]をディクショナリ[DICT]に解析して",
"_stringify dictionary [DICT] into JSON":
"ディクショナリ[DICT]をJSON文字列に変換して",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"ディクショナリ[DICT]をJSON[STRINGIFIED]として取得",
"_set dictionary [DICT] to JSON [OBJ]":
"ディクショナリ[DICT]をJSON[OBJ]に設定",
_stringified: "文字列化済み",
_parsed: "解析済み",
},
ko: {
_Dictionaries: "사전",
"_change key [KEY] in dictionary [DICT] by [BY]":
"사전 [DICT]의 키 [KEY]을(를) [BY](으)로 변경하기",
"_key [KEY] from dictionary [DICT]": "사전 [DICT]의 키 [KEY]",
"_key [KEY] in dictionary [DICT] is defined?":
"사전 [DICT]의 키 [KEY]이(가) 정의되었는가?",
"_key [KEY] in dictionary [DICT] is null?":
"사전 [DICT]의 키 [KEY]이(가) null인가?",
"_parse JSON [OBJ] into dictionary [DICT]":
"JSON [OBJ]을 사전 [DICT](으)로 변환",
"_remove dictionary [DICT]": "사전 [DICT]을(를) 제거하기",
"_remove key [KEY] from dictionary [DICT]":
"사전 [DICT]의 키 [KEY]을(를) 제거하기",
"_set key [KEY] in dictionary [DICT] to [VAL]":
"사전 [DICT]의 키 [KEY]을(를) [VAL](으)로 정하기",
"_stringify dictionary [DICT] into JSON":
"사전 [DICT]을(를) JSON으로 문자열화",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"사전 [DICT]을(를) JSON [STRINGIFIED]로 가져오기",
"_set dictionary [DICT] to JSON [OBJ]":
"사전 [DICT]을(를) JSON [OBJ]로 설정",
_stringified: "문자열화됨",
_parsed: "변환됨",
},
nb: {
_Dictionaries: "Ordbøker",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"hent ordbok [DICT] som JSON [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]": "sett ordbok [DICT] til JSON [OBJ]",
_stringified: "strenggjort",
_parsed: "parset",
},
nl: {
_Dictionaries: "JSON-woordenboeken",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"haal woordenboek [DICT] op als JSON [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]":
"stel woordenboek [DICT] in op JSON [OBJ]",
_stringified: "als JSON-string",
_parsed: "geparseerd",
},
ru: {
_Dictionaries: "Словари",
"_change key [KEY] in dictionary [DICT] by [BY]":
"изменить ключ [KEY] в словаре [DICT] на [BY]",
"_key [KEY] from dictionary [DICT]": "ключ [KEY] из словаря [DICT]",
"_key [KEY] in dictionary [DICT] is defined?":
"ключ [KEY] в словаре [DICT] найден?",
"_key [KEY] in dictionary [DICT] is null?":
"ключ [KEY] в словаре [DICT] нулевой?",
"_list of dictionaries": "список словарей",
"_parse JSON [OBJ] into dictionary [DICT]":
"преобразовать JSON [OBJ] в словарь [DICT]",
"_remove dictionary [DICT]": "удалить словарь [DICT]",
"_remove key [KEY] from dictionary [DICT]":
"удалить ключ [KEY] из словаря [DICT]",
"_set key [KEY] in dictionary [DICT] to [VAL]":
"задать ключ [KEY] в словаре [DICT] значение [VAL]",
"_stringify dictionary [DICT] into JSON":
"преобразовать словарь [DICT] в JSON",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"получить словарь [DICT] как JSON [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]":
"установить словарь [DICT] в JSON [OBJ]",
_stringified: "в виде строки",
_parsed: "разобранный",
},
"zh-cn": {
_Dictionaries: "字典",
"_change key [KEY] in dictionary [DICT] by [BY]":
"将字典[DICT]中的键[KEY]增加[BY]",
"_key [KEY] from dictionary [DICT]": "字典[DICT]的键[KEY]",
"_key [KEY] in dictionary [DICT] is defined?": "字典[DICT]定义了键[KEY]?",
"_key [KEY] in dictionary [DICT] is null?":
"字典[DICT]中的键[KEY]是null吗?",
"_list of dictionaries": "已有字典",
"_parse JSON [OBJ] into dictionary [DICT]": "解析JSON[OBJ]到字典[DICT]",
"_remove dictionary [DICT]": "删除字典[DICT]",
"_remove key [KEY] from dictionary [DICT]": "从字典[DICT]删除键[KEY]",
"_set key [KEY] in dictionary [DICT] to [VAL]":
"将字典[DICT]中的键[KEY]设为[VAL]",
"_stringify dictionary [DICT] into JSON": "将字典[DICT]转为JSON字符串",
"_get dictionary [DICT] as JSON [STRINGIFIED]":
"将字典[DICT]获取为JSON字符串 [STRINGIFIED]",
"_set dictionary [DICT] to JSON [OBJ]": "将字典[DICT]设置为JSON [OBJ]",
_stringified: "已转为字符串",
_parsed: "已解析",
},
});
/* end generated l10n code */ (function (Scratch) {
"use strict";
let dictionaries = new Map();

Expand All @@ -29,6 +186,7 @@
{
opcode: "dict_stringify",
blockType: Scratch.BlockType.REPORTER,
hideFromPalette: true,
text: Scratch.translate("stringify dictionary [DICT] into JSON"),
arguments: {
DICT: {
Expand All @@ -37,10 +195,27 @@
},
},
},
{
opcode: "dict_stringify_better",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate(
"get dictionary [DICT] as JSON [STRINGIFIED]"
),
arguments: {
DICT: {
type: Scratch.ArgumentType.STRING,
defaultValue: "foo",
},
STRINGIFIED: {
type: Scratch.ArgumentType.STRING,
menu: "stringify",
},
},
},
{
opcode: "dict_parse",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("parse JSON [OBJ] into dictionary [DICT]"),
text: Scratch.translate("set dictionary [DICT] to JSON [OBJ]"),
arguments: {
OBJ: {
type: Scratch.ArgumentType.STRING,
Expand Down Expand Up @@ -132,6 +307,12 @@
},
},
],
menus: {
stringify: {
acceptReporters: true,
items: ["stringified", "parsed"],
},
},
};
}

Expand All @@ -147,13 +328,26 @@
}, {});
};
if (!dictionaries.get(DICT)) return "{}";
return JSON.stringify(mapToObj(dictionaries.get(DICT)));
const rObj = mapToObj(dictionaries.get(DICT));
return JSON.stringify(rObj);
}

dict_stringify_better({ DICT, STRINGIFIED }) {
const mapToObj = (m) => {
return Array.from(m).reduce((obj, [key, value]) => {
obj[key] = value;
return obj;
}, {});
};
if (!dictionaries.get(DICT)) return "{}";
const rObj = mapToObj(dictionaries.get(DICT));
return STRINGIFIED == "stringified" ? JSON.stringify(rObj) : rObj;
}

dict_parse({ OBJ, DICT }) {
let dict = null;
try {
dict = JSON.parse(OBJ);
dict = typeof OBJ === "object" ? OBJ : JSON.parse(OBJ);
} catch (e) {
dict = { error: String(e) };
}
Expand Down Expand Up @@ -222,5 +416,5 @@
}
}

Scratch.extensions.register(new DictionaryExtension());

Check warning on line 419 in extensions/vercte/dictionaries.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

Argument of type 'DictionaryExtension' is not assignable to parameter of type 'Extension'. The types of 'getInfo().blocks' are incompatible between these types. Type '(string | { opcode: string; blockType: "reporter"; text: string; hideFromPalette?: undefined; arguments?: undefined; } | { opcode: string; blockType: "reporter"; hideFromPalette: boolean; text: string; arguments: { ...; }; } | ... 7 more ... | { ...; })[]' is not assignable to type '(Block | "---")[]'. Type 'string | { opcode: string; blockType: "reporter"; text: string; hideFromPalette?: undefined; arguments?: undefined; } | { opcode: string; blockType: "reporter"; hideFromPalette: boolean; text: string; arguments: { ...; }; } | ... 7 more ... | { ...; }' is not assignable to type 'Block | "---"'. Type 'string' is not assignable to type 'Block | "---"'.
})(Scratch);
Loading