Changing all JS qsTr to qsTranslate (better compatibility moving forward)

This commit is contained in:
Adsooi 2024-09-22 19:10:23 +02:00
parent a32d480b43
commit dcc47104ef
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
21 changed files with 76 additions and 194 deletions

View file

@ -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)

View file

@ -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('<b style="font-size: 15px;">&nbsp;' + this.targetName + "&nbsp;</b>")
.arg(this.formatColor(this.previousValue)).arg(this.formatColor(this.newValue))

View file

@ -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('<b style="font-size: 15px;">' + this.targetName + "</b>")
}

View file

@ -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('<b style="font-size: 15px;">' + this.targetName + "</b>")
}

View file

@ -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>|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('<b style="font-size: 15px;">&nbsp;' + this.targetName + '&nbsp;</b>')
// Check if we need to wait for LaTeX HTML to be rendered.

View file

@ -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('<b style="font-size: 15px;">' + this.targetName + "</b>").arg('<b>'+this.newValue+'</b>')
}

View file

@ -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('<b style="font-size: 15px;">&nbsp;' + this.targetName + '&nbsp;</b>')
// Check if we need to wait for LaTeX HTML to be rendered.
if(this.prevHTML !== undefined && this.nextHTML !== undefined)

View file

@ -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('<b style="font-size: 15px;">' + this.targetName + "</b>")
}

View file

@ -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}

View file

@ -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,

View file

@ -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

View file

@ -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,

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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(),

View file

@ -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),

View file

@ -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')
)
/**

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
// 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)
}

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import * as Polyfill from "polyfill.mjs"
import * as Polyfill from "../lib/expr-eval/polyfill.mjs"
export const CONSTANTS = {
"π": Math.PI,

View file

@ -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
}