From dcc47104ef488cdf5c9b8d5e3c9f36bcc92ce2b6 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 22 Sep 2024 19:10:23 +0200 Subject: [PATCH] Changing all JS qsTr to qsTranslate (better compatibility moving forward) --- .../LogarithmPlotter/Popup/Preferences.qml | 12 +- .../LogarithmPlotter/js/history/color.mjs | 4 +- .../LogarithmPlotter/js/history/create.mjs | 6 +- .../LogarithmPlotter/js/history/delete.mjs | 6 +- .../js/history/editproperty.mjs | 10 +- .../LogarithmPlotter/js/history/name.mjs | 4 +- .../LogarithmPlotter/js/history/position.mjs | 4 +- .../js/history/visibility.mjs | 4 +- .../js/objs/bodemagnitude.mjs | 8 +- .../js/objs/bodemagnitudesum.mjs | 4 +- .../LogarithmPlotter/js/objs/bodephase.mjs | 6 +- .../LogarithmPlotter/js/objs/bodephasesum.mjs | 4 +- .../LogarithmPlotter/js/objs/distribution.mjs | 4 +- .../LogarithmPlotter/js/objs/function.mjs | 4 +- .../LogarithmPlotter/js/objs/sequence.mjs | 4 +- .../ad5001/LogarithmPlotter/js/objs/text.mjs | 4 +- .../LogarithmPlotter/js/objs/xcursor.mjs | 4 +- .../ad5001/LogarithmPlotter/js/parameters.mjs | 50 +++---- .../LogarithmPlotter/js/parsing/polyfill.mjs | 125 ------------------ .../LogarithmPlotter/js/parsing/reference.mjs | 2 +- .../js/preferences/common.mjs | 1 - 21 files changed, 76 insertions(+), 194 deletions(-) delete mode 100644 LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/polyfill.mjs diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Preferences.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Preferences.qml index 7d801ca..44b1c8f 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Preferences.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/Preferences.qml @@ -46,7 +46,7 @@ Popup { CheckBox { height: 20 - text: setting.displayName + text: setting.name checked: setting.value() onClicked: setting.set(this.checked) } @@ -58,7 +58,7 @@ Popup { // Setting when selecting data from an enum, or an object of a certain type. Setting.ComboBoxSetting { height: 30 - label: setting.displayName + label: setting.name icon: `settings/${setting.icon}.svg` currentIndex: setting.value() model: setting.values @@ -71,7 +71,7 @@ Popup { Setting.ComboBoxSetting { height: 30 - label: setting.displayName + label: setting.name icon: `settings/${setting.icon}.svg` editable: true currentIndex: find(setting.value()) @@ -94,7 +94,7 @@ Popup { Setting.TextSetting { height: 30 isDouble: true - label: setting.displayName + label: setting.name min: setting.min() icon: `settings/${setting.icon}.svg` value: setting.value() @@ -114,12 +114,12 @@ Popup { Setting.ExpressionEditor { height: 30 - label: setting.displayName + label: setting.name icon: `settings/${setting.icon}.svg` defValue: Utils.simplifyExpression(setting.value()) variables: setting.variables allowGraphObjects: false - property string propertyName: setting.displayName + property string propertyName: setting.name onChanged: function(newExpr) { try { setting.set(newExpr) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs index c8bb577..12a8793 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs @@ -37,7 +37,7 @@ export default class ColorChanged extends EditedProperty { color(darkVer=false){return darkVer ? 'purple' : 'plum'} getReadableString() { - return qsTr("%1 %2's color changed from %3 to %4.") + return qsTranslate("color", "%1 %2's color changed from %3 to %4.") .arg(Objects.types[this.targetType].displayType()).arg(this.targetName) .arg(this.previousValue).arg(this.newValue) } @@ -47,7 +47,7 @@ export default class ColorChanged extends EditedProperty { } getHTMLString() { - return qsTr("%1 %2's color changed from %3 to %4.") + return qsTranslate("color", "%1 %2's color changed from %3 to %4.") .arg(Objects.types[this.targetType].displayType()) .arg(' ' + this.targetName + " ") .arg(this.formatColor(this.previousValue)).arg(this.formatColor(this.newValue)) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs index e474133..b2c7f2d 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs @@ -47,11 +47,13 @@ export default class CreateNewObject extends Action { } getReadableString() { - return qsTr("New %1 %2 created.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName) + return qsTranslate("create", "New %1 %2 created.") + .arg(Objects.types[this.targetType].displayType()) + .arg(this.targetName) } getHTMLString() { - return qsTr("New %1 %2 created.") + return qsTranslate("create", "New %1 %2 created.") .arg(Objects.types[this.targetType].displayType()) .arg('' + this.targetName + "") } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs index ea1deb1..7fa855d 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs @@ -39,11 +39,13 @@ export default class DeleteObject extends CreateNewObject { } getReadableString() { - return qsTr("%1 %2 deleted.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName) + return qsTranslate("delete", "%1 %2 deleted.") + .arg(Objects.types[this.targetType].displayType()) + .arg(this.targetName) } getHTMLString() { - return qsTr("%1 %2 deleted.") + return qsTranslate("delete", "%1 %2 deleted.") .arg(Objects.types[this.targetType].displayType()) .arg('' + this.targetName + "") } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs index 3c6bcda..1280e54 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs @@ -128,15 +128,19 @@ export default class EditedProperty extends Action { } getReadableString() { - return qsTr('%1 of %2 %3 changed from "%4" to "%5".') + return qsTranslate("editproperty", '%1 of %2 %3 changed from "%4" to "%5".') .arg(this.targetPropertyReadable) .arg(Objects.types[this.targetType].displayType()) .arg(this.targetName).arg(this.prevString).arg(this.nextString) } - + + /** + * + * @return {Promise|string} + */ getHTMLString() { return new Promise(resolve => { - const translation = qsTr('%1 of %2 changed from %3 to %4.') + const translation = qsTranslate("editproperty", '%1 of %2 changed from %3 to %4.') .arg(this.targetPropertyReadable) .arg(' ' + this.targetName + ' ') // Check if we need to wait for LaTeX HTML to be rendered. diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs index 7698adf..13417da 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs @@ -45,13 +45,13 @@ export default class NameChanged extends EditedProperty { } getReadableString() { - return qsTr('%1 %2 renamed to %3.') + return qsTranslate("name", '%1 %2 renamed to %3.') .arg(Objects.types[this.targetType].displayType()) .arg(this.targetName).arg(this.newValue) } getHTMLString() { - return qsTr('%1 %2 renamed to %3.') + return qsTranslate("name", '%1 %2 renamed to %3.') .arg(Objects.types[this.targetType].displayType()) .arg('' + this.targetName + "").arg(''+this.newValue+'') } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs index a376e2f..b071cc7 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs @@ -84,14 +84,14 @@ export default class EditedPosition extends Action { } getReadableString() { - return qsTr('Position of %1 %2 set from "%3" to "%4".') + return qsTranslate("position", 'Position of %1 %2 set from "%3" to "%4".') .arg(Objects.types[this.targetType].displayType()) .arg(this.targetName).arg(this.prevString).arg(this.nextString) } getHTMLString() { return new Promise(resolve => { - const translation = qsTr('Position of %1 set from %2 to %3.') + const translation = qsTranslate("position", 'Position of %1 set from %2 to %3.') .arg(' ' + this.targetName + ' ') // Check if we need to wait for LaTeX HTML to be rendered. if(this.prevHTML !== undefined && this.nextHTML !== undefined) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs index d38b33f..ebcb4fa 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs @@ -41,13 +41,13 @@ export default class EditedVisibility extends EditedProperty { } getReadableString() { - return (this.newValue ? qsTr('%1 %2 shown.') : qsTr('%1 %2 hidden.')) + return (this.newValue ? qsTranslate('visibility', '%1 %2 shown.') : qsTranslate('visibility', '%1 %2 hidden.')) .arg(Objects.types[this.targetType].displayType()) .arg(this.targetName) } getHTMLString() { - return (this.newValue ? qsTr('%1 %2 shown.') : qsTr('%1 %2 hidden.')) + return (this.newValue ? qsTranslate('visibility', '%1 %2 shown.') : qsTranslate('visibility', '%1 %2 hidden.')) .arg(Objects.types[this.targetType].displayType()) .arg('' + this.targetName + "") } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs index 9b0085f..c01bcae 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs @@ -30,8 +30,8 @@ import { CreateNewObject } from "../historylib.mjs" export default class BodeMagnitude extends ExecutableObject { static type(){return 'Gain Bode'} - static displayType(){return qsTr('Bode Magnitude')} - static displayTypeMultiple(){return qsTr('Bode Magnitudes')} + static displayType(){return qsTranslate("bodemagnitude", 'Bode Magnitude')} + static displayTypeMultiple(){return qsTranslate("bodemagnitude", 'Bode Magnitudes')} static properties() {return { [QT_TRANSLATE_NOOP('prop','om_0')]: new P.ObjectType('Point'), [QT_TRANSLATE_NOOP('prop','pass')]: P.Enum.BodePass, @@ -69,12 +69,12 @@ export default class BodeMagnitude extends ExecutableObject { } getReadableString() { - let pass = this.pass === "low" ? qsTr("low-pass") : qsTr("high-pass"); + let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass"); return `${this.name}: ${pass}; ${this.om_0.name} = ${this.om_0.x}\n ${' '.repeat(this.name.length)}${this.gain.toString(true)} dB/dec` } getLatexString() { - let pass = this.pass === "low" ? qsTr("low-pass") : qsTr("high-pass"); + let pass = this.pass === "low" ? qsTranslate("bodemagnitude", "low-pass") : qsTranslate("bodemagnitude", "high-pass"); return `\\mathrm{${Latex.variable(this.name)}:}\\begin{array}{l} \\textsf{${pass}};${Latex.variable(this.om_0.name)} = ${this.om_0.x.latexMarkup} \\\\ ${this.gain.latexMarkup}\\textsf{ dB/dec} diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs index bc4713a..82bf6b6 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs @@ -27,8 +27,8 @@ import Function from "function.mjs" export default class BodeMagnitudeSum extends ExecutableObject { static type(){return 'Somme gains Bode'} - static displayType(){return qsTr('Bode Magnitudes Sum')} - static displayTypeMultiple(){return qsTr('Bode Magnitudes Sum')} + static displayType(){return qsTranslate("bodemagnitudesum", 'Bode Magnitudes Sum')} + static displayTypeMultiple(){return qsTranslate("bodemagnitudesum", 'Bode Magnitudes Sum')} static createable() {return false} static properties() {return { [QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position, diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs index eaf48d3..23119ef 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs @@ -28,8 +28,8 @@ import { ExecutableObject } from "common.mjs" export default class BodePhase extends ExecutableObject { static type(){return 'Phase Bode'} - static displayType(){return qsTr('Bode Phase')} - static displayTypeMultiple(){return qsTr('Bode Phases')} + static displayType(){return qsTranslate("bodephase", 'Bode Phase')} + static displayTypeMultiple(){return qsTranslate("bodephase", 'Bode Phases')} static properties() {return { [QT_TRANSLATE_NOOP('prop','om_0')]: new P.ObjectType('Point'), [QT_TRANSLATE_NOOP('prop','phase')]: new P.Expression(), @@ -41,7 +41,7 @@ export default class BodePhase extends ExecutableObject { constructor(name = null, visible = true, color = null, labelContent = 'name + value', om_0 = '', phase = 90, unit = '°', labelPosition = 'above', labelX = 1) { if(name == null) name = Objects.getNewName('φ') - if(name === 'φ') name = 'φ₀' // φ is reserved for sum of BODE phases (Somme phases Bode). + if(name === 'φ') name = 'φ₀' // φ is reserved for sum of Bode phases. super(name, visible, color, labelContent) if(typeof phase == 'number' || typeof phase == 'string') phase = new Expression(phase.toString()) this.phase = phase diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs index 8e91784..1f1a0fa 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs @@ -25,8 +25,8 @@ import { ExecutableObject } from "common.mjs" export default class BodePhaseSum extends ExecutableObject { static type(){return 'Somme phases Bode'} - static displayType(){return qsTr('Bode Phases Sum')} - static displayTypeMultiple(){return qsTr('Bode Phases Sum')} + static displayType(){return qsTranslate("bodephasesum", 'Bode Phases Sum')} + static displayTypeMultiple(){return qsTranslate("bodephasesum", 'Bode Phases Sum')} static createable() {return false} static properties() {return { [QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position, diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs index b77189f..e0fe698 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs @@ -25,8 +25,8 @@ import { ExecutableObject } from "common.mjs" export default class DistributionFunction extends ExecutableObject { static type(){return 'Repartition'} - static displayType(){return qsTr('Repartition')} - static displayTypeMultiple(){return qsTr('Repartition functions')} + static displayType(){return qsTranslate("distribution", 'Repartition')} + static displayTypeMultiple(){return qsTranslate("distribution", 'Repartition functions')} static properties() {return { 'comment1': QT_TRANSLATE_NOOP( 'comment', diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs index 2448d50..eb3f081 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs @@ -26,8 +26,8 @@ import Latex from "../math/latex.mjs" export default class Function extends ExecutableObject { static type(){return 'Function'} - static displayType(){return qsTr('Function')} - static displayTypeMultiple(){return qsTr('Functions')} + static displayType(){return qsTranslate("function", 'Function')} + static displayTypeMultiple(){return qsTranslate("function", 'Functions')} static properties() {return { [QT_TRANSLATE_NOOP('prop','expression')]: new P.Expression('x'), [QT_TRANSLATE_NOOP('prop','definitionDomain')]: 'Domain', diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs index 11f1be7..b05a66e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs @@ -27,8 +27,8 @@ import Function from "function.mjs" export default class Sequence extends ExecutableObject { static type(){return 'Sequence'} - static displayType(){return qsTr('Sequence')} - static displayTypeMultiple(){return qsTr('Sequences')} + static displayType(){return qsTranslate("sequence", 'Sequence')} + static displayTypeMultiple(){return qsTranslate("sequence", 'Sequences')} static properties() {return { [QT_TRANSLATE_NOOP('prop','drawPoints')]: 'boolean', diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs index fab2818..3ad1e82 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs @@ -26,8 +26,8 @@ import { DrawableObject } from "common.mjs" export default class Text extends DrawableObject { static type(){return 'Text'} - static displayType(){return qsTr('Text')} - static displayTypeMultiple(){return qsTr('Texts')} + static displayType(){return qsTranslate("text", 'Text')} + static displayTypeMultiple(){return qsTranslate("text", 'Texts')} static properties() {return { [QT_TRANSLATE_NOOP('prop','x')]: new P.Expression(), [QT_TRANSLATE_NOOP('prop','y')]: new P.Expression(), diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs index 20732ba..f377a74 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs @@ -26,8 +26,8 @@ import { DrawableObject } from "common.mjs" export default class XCursor extends DrawableObject { static type(){return 'X Cursor'} - static displayType(){return qsTr('X Cursor')} - static displayTypeMultiple(){return qsTr('X Cursors')} + static displayType(){return qsTranslate("xcursor", 'X Cursor')} + static displayTypeMultiple(){return qsTranslate("xcursor", 'X Cursors')} static properties() {return { [QT_TRANSLATE_NOOP('prop','x')]: new P.Expression(), [QT_TRANSLATE_NOOP('prop','targetElement')]: new P.ObjectType('ExecutableObject', true), diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs index 72f9dee..f59c322 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs @@ -88,7 +88,7 @@ export class Enum extends PropertyType { this.type = 'Enum' this.values = values this.legacyValues = {} - this.translatedValues = values.map(x => qsTr(x)) + this.translatedValues = values.map(x => qsTranslate('parameters', x)) } toString() { @@ -246,14 +246,14 @@ export class Dictionary extends PropertyType { // Common parameters for Enums Enum.Position = new Enum( - QT_TR_NOOP('above'), - QT_TR_NOOP('below'), - QT_TR_NOOP('left'), - QT_TR_NOOP('right'), - QT_TR_NOOP('above-left'), - QT_TR_NOOP('above-right'), - QT_TR_NOOP('below-left'), - QT_TR_NOOP('below-right') + QT_TRANSLATE_NOOP('parameters', 'above'), + QT_TRANSLATE_NOOP('parameters', 'below'), + QT_TRANSLATE_NOOP('parameters', 'left'), + QT_TRANSLATE_NOOP('parameters', 'right'), + QT_TRANSLATE_NOOP('parameters', 'above-left'), + QT_TRANSLATE_NOOP('parameters', 'above-right'), + QT_TRANSLATE_NOOP('parameters', 'below-left'), + QT_TRANSLATE_NOOP('parameters', 'below-right') ) Enum.Position.legacyValues = { 'top': 'above', @@ -265,32 +265,32 @@ Enum.Position.legacyValues = { } Enum.Positioning = new Enum( - QT_TR_NOOP('center'), - QT_TR_NOOP('top'), - QT_TR_NOOP('bottom'), - QT_TR_NOOP('left'), - QT_TR_NOOP('right'), - QT_TR_NOOP('top-left'), - QT_TR_NOOP('top-right'), - QT_TR_NOOP('bottom-left'), - QT_TR_NOOP('bottom-right') + QT_TRANSLATE_NOOP('parameters', 'center'), + QT_TRANSLATE_NOOP('parameters', 'top'), + QT_TRANSLATE_NOOP('parameters', 'bottom'), + QT_TRANSLATE_NOOP('parameters', 'left'), + QT_TRANSLATE_NOOP('parameters', 'right'), + QT_TRANSLATE_NOOP('parameters', 'top-left'), + QT_TRANSLATE_NOOP('parameters', 'top-right'), + QT_TRANSLATE_NOOP('parameters', 'bottom-left'), + QT_TRANSLATE_NOOP('parameters', 'bottom-right') ) Enum.FunctionDisplayType = new Enum( - QT_TR_NOOP('application'), - QT_TR_NOOP('function') + QT_TRANSLATE_NOOP('parameters', 'application'), + QT_TRANSLATE_NOOP('parameters', 'function') ) Enum.BodePass = new Enum( - QT_TR_NOOP('high'), - QT_TR_NOOP('low') + QT_TRANSLATE_NOOP('parameters', 'high'), + QT_TRANSLATE_NOOP('parameters', 'low') ) Enum.XCursorValuePosition = new Enum( - QT_TR_NOOP('Next to target'), - QT_TR_NOOP('With label'), - QT_TR_NOOP('Hidden') + QT_TRANSLATE_NOOP('parameters', 'Next to target'), + QT_TRANSLATE_NOOP('parameters', 'With label'), + QT_TRANSLATE_NOOP('parameters', 'Hidden') ) /** diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/polyfill.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/polyfill.mjs deleted file mode 100644 index ac845ce..0000000 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/polyfill.mjs +++ /dev/null @@ -1,125 +0,0 @@ -/** - * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions. - * Copyright (C) 2021-2024 Ad5001 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -// Contains polyfill math functions used for reference. -export function factorial(x) { - if (x < 0) // Integrating by less than 0 - if(isFinite(n)) - return Infinity - else - throw new EvalError("Cannot calculate the factorial of -∞.") - - return gamma(x+1) -} - -let GAMMA_G = 4.7421875 -let GAMMA_P = [ - 0.99999999999999709182, - 57.156235665862923517, -59.597960355475491248, - 14.136097974741747174, -0.49191381609762019978, - 0.33994649984811888699e-4, - 0.46523628927048575665e-4, -0.98374475304879564677e-4, - 0.15808870322491248884e-3, -0.21026444172410488319e-3, - 0.21743961811521264320e-3, -0.16431810653676389022e-3, - 0.84418223983852743293e-4, -0.26190838401581408670e-4, - 0.36899182659531622704e-5 -] - -export function gamma(n) { - if(n <= 0) // Integrating by less than 0 - if(isFinite(n)) - return Infinity - else - throw new EvalError("Cannot calculate Γ(-∞).") - - if(n >= 171.35) - return Infinity // Would return more than 2^1024 - 1 (aka Number.INT_MAX) - - if(n === Math.round(n) && isFinite(n)) { - // Calculating (n-1)! - let res = n - 1 - - for(let i = n - 2; i > 1; i++) - res *= i - - if(res === 0) - res = 1 // 0! is per definition 1 - - return res - } - - // Section below adapted function adapted from math.js - if(n < 0.5) - return Math.PI / (Math.sin(Math.PI * n) * gamma(1 - n)) - - if(n > 85.0) { // Extended Stirling Approx - let twoN = n * n - let threeN = twoN * n - let fourN = threeN * n - let fiveN = fourN * n - return Math.sqrt(2 * Math.PI / n) * Math.pow((n / Math.E), n) * - (1 + (1 / (12 * n)) + (1 / (288 * twoN)) - (139 / (51840 * threeN)) - - (571 / (2488320 * fourN)) + (163879 / (209018880 * fiveN)) + - (5246819 / (75246796800 * fiveN * n))) - } - - --n - let x = GAMMA_P[0] - for (let i = 1; i < GAMMA_P.length; ++i) { - x += GAMMA_P[i] / (n + i) - } - - let t = n + GAMMA_G + 0.5 - return Math.sqrt(2 * Math.PI) * Math.pow(t, n + 0.5) * Math.exp(-t) * x -} - -export function arrayMap(f, arr) { - if (typeof f != 'function') - throw new EvalError(qsTranslate('error', 'First argument to map is not a function.')) - if (!Array.isArray(arr)) - throw new EvalError(qsTranslate('error', 'Second argument to map is not an array.')) - return arr.map(f) -} - -export function arrayFold(f, init, arr) { - if (typeof f != 'function') - throw new EvalError(qsTranslate('error', 'First argument to fold is not a function.')) - if (!Array.isArray(arr)) - throw new EvalError(qsTranslate('error', 'Second argument to fold is not an array.')) - return arr.reduce(f, init) -} - -export function arrayFilter(f, arr) { - if (typeof f != 'function') - throw new EvalError(qsTranslate('error', 'First argument to filter is not a function.')) - if (!Array.isArray(arr)) - throw new EvalError(qsTranslate('error', 'Second argument to filter is not an array.')) - return arr.filter(f) -} - -export function arrayJoin(sep, arr) { - if (!Array.isArray(arr)) - throw new Error(qsTranslate('error', 'Second argument to join is not an array.')) - return arr.join(sep) -} - -export function indexOf(target, s) { - if (!(Array.isArray(s) || typeof s === 'string')) - throw new Error(qsTranslate('error', 'Second argument to indexOf is not a string or array.')) - return s.indexOf(target) -} diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.mjs index d6ce9dc..9c30991 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.mjs @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import * as Polyfill from "polyfill.mjs" +import * as Polyfill from "../lib/expr-eval/polyfill.mjs" export const CONSTANTS = { "π": Math.PI, diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/common.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/common.mjs index 48cd1de..4503113 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/common.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/common.mjs @@ -22,7 +22,6 @@ class Setting { constructor(type, name, nameInConfig, icon) { this.type = type this.name = name - this.displayName = qsTr(name) this.nameInConfig = nameInConfig this.icon = icon }