Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate and style CodeMirror extensions #215

Merged
merged 11 commits into from
May 30, 2022
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ yarn-debug.log*
yarn-error.log*

.eslintcache

.vscode
# script outputs
translationIssues.txt

# Ignore output of local pip install when building the tar
src/workers/python/python_package/
9 changes: 9 additions & 0 deletions src/Papyros.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,12 @@ Ensure the default browser behavior of the `hidden` attribute.
/* same value as placeholder-grey in tailwind.config.js */
color: #888;
}

/* Also override CodeMirror buttons to use this style */
.papyros-button, .cm-button {
@apply _tw-m-1 _tw-px-3 _tw-py-1 _tw-rounded-lg _tw-cursor-pointer disabled:_tw-opacity-50 disabled:_tw-cursor-not-allowed !important;
}
/* Round the corners of textfields created by CodeMirror */
.cm-textfield {
@apply _tw-rounded-lg !important;
}
19 changes: 16 additions & 3 deletions src/Translations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
* I18n translations object:
*
*/
interface Translations {
interface Translation {
/**
* Phrase for given translation key
*/
[key: string]: string;
}
interface NestedTranslations {
/**
* Each key yields a translated string or a nested object
*/
[key: string]: string | Translations;
[key: string]: Translation | NestedTranslations;
}
interface CodeMirrorTranslations {
/**
* CodeMirror expects a flat object per language
*/
[key: string]: Translation
}
export declare const TRANSLATIONS: Translations;
export declare const TRANSLATIONS: NestedTranslations;
export declare const CODE_MIRROR_TRANSLATIONS: CodeMirrorTranslations;
36 changes: 36 additions & 0 deletions src/Translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,45 @@ const DUTCH_TRANSLATION = {
"used_input_with_prompt": "Deze regel werd gebruikt als invoer voor de volgende vraag: %{prompt}"
};

const DUTCH_PHRASES = {
// @codemirror/view
"Control character": "Controlekarakter",
// @codemirror/fold
"Folded lines": "Ingeklapte regels",
"Unfolded lines": "Uitgeklapte regels",
"to": "tot",
"folded code": "ingeklapte code",
"unfold": "uitklappen",
"Fold line": "Regel inklappen",
"Unfold line": "Regel uitklappen",
// @codemirror/search
"Go to line": "Spring naar regel",
"go": "OK",
"Find": "Zoeken",
"Replace": "Vervangen",
"next": "volgende",
"previous": "vorige",
"all": "alle",
"match case": "Hoofdlettergevoelig",
"replace": "vervangen",
"replace all": "alles vervangen",
"close": "sluiten",
"current match": "huidige overeenkomst",
"on line": "op regel",
// @codemirror/lint
"Diagnostics": "Problemen",
"No diagnostics": "Geen problemen",
}

const TRANSLATIONS = {
en: { "Papyros": ENGLISH_TRANSLATION },
nl: { "Papyros": DUTCH_TRANSLATION }
};

const CODE_MIRROR_TRANSLATIONS = {
en: {},
nl: DUTCH_PHRASES
};
// JS exports to allow use in TS and JS files
module.exports.TRANSLATIONS = TRANSLATIONS;
module.exports.CODE_MIRROR_TRANSLATIONS = CODE_MIRROR_TRANSLATIONS;
8 changes: 8 additions & 0 deletions src/editor/CodeMirrorEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { EditorView, placeholder, ViewUpdate } from "@codemirror/view";
import { Renderable, RenderOptions, renderWithOptions } from "../util/Rendering";
import { StyleSpec } from "style-mod";
import { oneDark } from "@codemirror/theme-one-dark";
import { CODE_MIRROR_TRANSLATIONS } from "../Translations";
import I18n from "i18n-js";

/**
* Data structure containing common elements for styling
Expand Down Expand Up @@ -67,6 +69,7 @@ export abstract class CodeMirrorEditor extends Renderable {
public static STYLE = "style";
public static PLACEHOLDER = "placeholder";
public static THEME = "theme";
public static LANGUAGE = "language";
/**
* CodeMirror EditorView representing the internal editor
*/
Expand Down Expand Up @@ -96,6 +99,7 @@ export abstract class CodeMirrorEditor extends Renderable {
compartments.add(CodeMirrorEditor.STYLE);
compartments.add(CodeMirrorEditor.PLACEHOLDER);
compartments.add(CodeMirrorEditor.THEME);
compartments.add(CodeMirrorEditor.LANGUAGE);
this.compartments = new Map();
const configurableExtensions: Array<Extension> = [];
compartments.forEach(opt => {
Expand Down Expand Up @@ -204,6 +208,10 @@ export abstract class CodeMirrorEditor extends Renderable {

protected override _render(options: RenderOptions): void {
this.setDarkMode(options.darkMode || false);
this.reconfigure([
CodeMirrorEditor.LANGUAGE,
EditorState.phrases.of(CODE_MIRROR_TRANSLATIONS[I18n.locale])
]);
const wrappingDiv = document.createElement("div");
wrappingDiv.classList.add(...this.styling.classes);
wrappingDiv.replaceChildren(this.editorView.dom);
Expand Down
2 changes: 1 addition & 1 deletion src/util/Rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface ButtonOptions {
*/
export function renderButton(options: ButtonOptions): string {
appendClasses(options,
"_tw-m-1 _tw-px-3 _tw-py-1 _tw-rounded-lg _tw-cursor-pointer disabled:_tw-opacity-50 disabled:_tw-cursor-not-allowed");
"papyros-button");
return `
<button id="${options.id}" type="button"
class="${options.classNames}">
Expand Down
120 changes: 60 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@codemirror/autocomplete@^0.20.0":
version "0.20.1"
resolved "https://registry.yarnpkg.com/@codemirror/autocomplete/-/autocomplete-0.20.1.tgz#d9aa5cfc111469f9f014e80d239916bb0c21edf9"
integrity sha512-rWDAkE1Qn9O4LsV8tAm/KlzzqdQLaIxqDOLhVYja3rKQIWebD3dixIzg9BAKpjt+0dIaDwtIp3yinD9MefgbQQ==
version "0.20.3"
resolved "https://registry.yarnpkg.com/@codemirror/autocomplete/-/autocomplete-0.20.3.tgz#affe2d7e2b2e0be42ee1ac5fb74a1c84a6f1bfd7"
integrity sha512-lYB+NPGP+LEzAudkWhLfMxhTrxtLILGl938w+RcFrGdrIc54A+UgmCoz+McE3IYRFp4xyQcL4uFJwo+93YdgHw==
dependencies:
"@codemirror/language" "^0.20.0"
"@codemirror/state" "^0.20.0"
Expand Down Expand Up @@ -429,9 +429,9 @@
style-mod "^4.0.0"

"@codemirror/lint@^0.20.0", "@codemirror/lint@^0.20.2":
version "0.20.2"
resolved "https://registry.yarnpkg.com/@codemirror/lint/-/lint-0.20.2.tgz#e47307167ff7e5bb14b717f4084a386dd7f8954e"
integrity sha512-xEH3wlzoFLEhPEeMVRNoQIhoTCMEtXhVxemGh3FYjLfl/CL3B2Wz+CU7ooP5SKhN1le7JqUNSfiTArFP+IzFuw==
version "0.20.3"
resolved "https://registry.yarnpkg.com/@codemirror/lint/-/lint-0.20.3.tgz#34c0fd45c5acd522637f68602e3a416162e03a15"
integrity sha512-06xUScbbspZ8mKoODQCEx6hz1bjaq9m8W8DxdycWARMiiX1wMtfCh/MoHpaL7ws/KUMwlsFFfp2qhm32oaCvVA==
dependencies:
"@codemirror/state" "^0.20.0"
"@codemirror/view" "^0.20.2"
Expand Down Expand Up @@ -462,9 +462,9 @@
"@lezer/highlight" "^0.16.0"

"@codemirror/view@^0.20.0", "@codemirror/view@^0.20.2", "@codemirror/view@^0.20.3":
version "0.20.6"
resolved "https://registry.yarnpkg.com/@codemirror/view/-/view-0.20.6.tgz#ccc55547ad01153a3a146a57bac8854b8cd37e79"
integrity sha512-k/Enz4HMcST5Waom2r8y8VtiJfgnU5+Y/pNVO45eIhsRH+0LYtAMgJqqqspWVv1apOuMzmlttw6keaPvkloakg==
version "0.20.7"
resolved "https://registry.yarnpkg.com/@codemirror/view/-/view-0.20.7.tgz#1d0acc740f71f92abef4b437c030d4e6c39ab6dc"
integrity sha512-pqEPCb9QFTOtHgAH5XU/oVy9UR/Anj6r+tG5CRmkNVcqSKEPmBU05WtN/jxJCFZBXf6HumzWC9ydE4qstO3TxQ==
dependencies:
"@codemirror/state" "^0.20.0"
style-mod "^4.0.0"
Expand Down Expand Up @@ -1051,13 +1051,13 @@
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^5.21.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.25.0.tgz#e8ce050990e4d36cc200f2de71ca0d3eb5e77a31"
integrity sha512-icYrFnUzvm+LhW0QeJNKkezBu6tJs9p/53dpPLFH8zoM9w1tfaKzVurkPotEpAqQ8Vf8uaFyL5jHd0Vs6Z0ZQg==
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.26.0.tgz#c1f98ccba9d345e38992975d3ca56ed6260643c2"
integrity sha512-oGCmo0PqnRZZndr+KwvvAUvD3kNE4AfyoGCwOZpoCncSh4MVD06JTE8XQa2u9u+NX5CsyZMBTEc2C72zx38eYA==
dependencies:
"@typescript-eslint/scope-manager" "5.25.0"
"@typescript-eslint/type-utils" "5.25.0"
"@typescript-eslint/utils" "5.25.0"
"@typescript-eslint/scope-manager" "5.26.0"
"@typescript-eslint/type-utils" "5.26.0"
"@typescript-eslint/utils" "5.26.0"
debug "^4.3.4"
functional-red-black-tree "^1.0.1"
ignore "^5.2.0"
Expand All @@ -1066,68 +1066,68 @@
tsutils "^3.21.0"

"@typescript-eslint/parser@^5.21.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.25.0.tgz#fb533487147b4b9efd999a4d2da0b6c263b64f7f"
integrity sha512-r3hwrOWYbNKP1nTcIw/aZoH+8bBnh/Lh1iDHoFpyG4DnCpvEdctrSl6LOo19fZbzypjQMHdajolxs6VpYoChgA==
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.26.0.tgz#a61b14205fe2ab7533deb4d35e604add9a4ceee2"
integrity sha512-n/IzU87ttzIdnAH5vQ4BBDnLPly7rC5VnjN3m0xBG82HK6rhRxnCb3w/GyWbNDghPd+NktJqB/wl6+YkzZ5T5Q==
dependencies:
"@typescript-eslint/scope-manager" "5.25.0"
"@typescript-eslint/types" "5.25.0"
"@typescript-eslint/typescript-estree" "5.25.0"
"@typescript-eslint/scope-manager" "5.26.0"
"@typescript-eslint/types" "5.26.0"
"@typescript-eslint/typescript-estree" "5.26.0"
debug "^4.3.4"

"@typescript-eslint/scope-manager@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.25.0.tgz#e78f1484bca7e484c48782075219c82c6b77a09f"
integrity sha512-p4SKTFWj+2VpreUZ5xMQsBMDdQ9XdRvODKXN4EksyBjFp2YvQdLkyHqOffakYZPuWJUDNu3jVXtHALDyTv3cww==
"@typescript-eslint/scope-manager@5.26.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.26.0.tgz#44209c7f649d1a120f0717e0e82da856e9871339"
integrity sha512-gVzTJUESuTwiju/7NiTb4c5oqod8xt5GhMbExKsCTp6adU3mya6AGJ4Pl9xC7x2DX9UYFsjImC0mA62BCY22Iw==
dependencies:
"@typescript-eslint/types" "5.25.0"
"@typescript-eslint/visitor-keys" "5.25.0"
"@typescript-eslint/types" "5.26.0"
"@typescript-eslint/visitor-keys" "5.26.0"

"@typescript-eslint/type-utils@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.25.0.tgz#5750d26a5db4c4d68d511611e0ada04e56f613bc"
integrity sha512-B6nb3GK3Gv1Rsb2pqalebe/RyQoyG/WDy9yhj8EE0Ikds4Xa8RR28nHz+wlt4tMZk5bnAr0f3oC8TuDAd5CPrw==
"@typescript-eslint/type-utils@5.26.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.26.0.tgz#937dee97702361744a3815c58991acf078230013"
integrity sha512-7ccbUVWGLmcRDSA1+ADkDBl5fP87EJt0fnijsMFTVHXKGduYMgienC/i3QwoVhDADUAPoytgjbZbCOMj4TY55A==
dependencies:
"@typescript-eslint/utils" "5.25.0"
"@typescript-eslint/utils" "5.26.0"
debug "^4.3.4"
tsutils "^3.21.0"

"@typescript-eslint/types@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.25.0.tgz#dee51b1855788b24a2eceeae54e4adb89b088dd8"
integrity sha512-7fWqfxr0KNHj75PFqlGX24gWjdV/FDBABXL5dyvBOWHpACGyveok8Uj4ipPX/1fGU63fBkzSIycEje4XsOxUFA==
"@typescript-eslint/types@5.26.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.26.0.tgz#cb204bb154d3c103d9cc4d225f311b08219469f3"
integrity sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA==

"@typescript-eslint/typescript-estree@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.25.0.tgz#a7ab40d32eb944e3fb5b4e3646e81b1bcdd63e00"
integrity sha512-MrPODKDych/oWs/71LCnuO7NyR681HuBly2uLnX3r5i4ME7q/yBqC4hW33kmxtuauLTM0OuBOhhkFaxCCOjEEw==
"@typescript-eslint/typescript-estree@5.26.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.26.0.tgz#16cbceedb0011c2ed4f607255f3ee1e6e43b88c3"
integrity sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w==
dependencies:
"@typescript-eslint/types" "5.25.0"
"@typescript-eslint/visitor-keys" "5.25.0"
"@typescript-eslint/types" "5.26.0"
"@typescript-eslint/visitor-keys" "5.26.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/utils@5.25.0", "@typescript-eslint/utils@^5.10.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.25.0.tgz#272751fd737733294b4ab95e16c7f2d4a75c2049"
integrity sha512-qNC9bhnz/n9Kba3yI6HQgQdBLuxDoMgdjzdhSInZh6NaDnFpTUlwNGxplUFWfY260Ya0TRPvkg9dd57qxrJI9g==
"@typescript-eslint/utils@5.26.0", "@typescript-eslint/utils@^5.10.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.26.0.tgz#896b8480eb124096e99c8b240460bb4298afcfb4"
integrity sha512-PJFwcTq2Pt4AMOKfe3zQOdez6InIDOjUJJD3v3LyEtxHGVVRK3Vo7Dd923t/4M9hSH2q2CLvcTdxlLPjcIk3eg==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.25.0"
"@typescript-eslint/types" "5.25.0"
"@typescript-eslint/typescript-estree" "5.25.0"
"@typescript-eslint/scope-manager" "5.26.0"
"@typescript-eslint/types" "5.26.0"
"@typescript-eslint/typescript-estree" "5.26.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

"@typescript-eslint/visitor-keys@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.25.0.tgz#33aa5fdcc5cedb9f4c8828c6a019d58548d4474b"
integrity sha512-yd26vFgMsC4h2dgX4+LR+GeicSKIfUvZREFLf3DDjZPtqgLx5AJZr6TetMNwFP9hcKreTTeztQYBTNbNoOycwA==
"@typescript-eslint/visitor-keys@5.26.0":
version "5.26.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.26.0.tgz#7195f756e367f789c0e83035297c45b417b57f57"
integrity sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q==
dependencies:
"@typescript-eslint/types" "5.25.0"
"@typescript-eslint/types" "5.26.0"
eslint-visitor-keys "^3.3.0"

"@webassemblyjs/[email protected]":
Expand Down Expand Up @@ -2197,9 +2197,9 @@ eslint-config-google@^0.14.0:
integrity sha512-WsbX4WbjuMvTdeVL6+J3rK1RGhCTqjsFjX7UMSMgZiyxxaNLkoJENbrGExzERFeoTpGw3F3FypTiWAP9ZXzkEw==

eslint-plugin-jest@^26.1.5:
version "26.2.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.2.2.tgz#74e000544259f1ef0462a609a3fc9e5da3768f6c"
integrity sha512-etSFZ8VIFX470aA6kTqDPhIq7YWe0tjBcboFNV3WeiC18PJ/AVonGhuTwlmuz2fBkH8FJHA7JQ4k7GsQIj1Gew==
version "26.4.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.4.5.tgz#c1772800bfc15c6f34d3e1536932ece0627c9f2a"
integrity sha512-jGPKXoV7v21gvt2QivCPuN1c2RePxJ9XnYQjucioAZhMTXrJ0y48QhP7UOpgNs/sj0Lns2NKRvoAjnyXDCfqbw==
dependencies:
"@typescript-eslint/utils" "^5.10.0"

Expand Down Expand Up @@ -4912,9 +4912,9 @@ typedarray-to-buffer@^3.1.5:
is-typedarray "^1.0.0"

typescript@^4.6.4:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
version "4.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4"
integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A==

universalify@^0.1.2:
version "0.1.2"
Expand Down