2022-01-20 17:19:36 +00:00
|
|
|
#!/bin/bash
|
2024-09-20 21:44:29 +00:00
|
|
|
#
|
|
|
|
# This file automatically renames .mjs files to js, and (tries) to fix most common ECMAScript
|
|
|
|
# specificities so that lupdate doesn't cry out in pain.
|
|
|
|
# See also: https://bugreports.qt.io/browse/QTBUG-123819
|
|
|
|
#
|
2024-09-27 01:02:55 +00:00
|
|
|
|
2024-09-22 16:28:36 +00:00
|
|
|
escape() {
|
|
|
|
str="$1"
|
|
|
|
str="${str//\//\\/}" # Escape slashes
|
|
|
|
str="${str//\*/\\*}" # Escape asterixes
|
|
|
|
echo "$str"
|
|
|
|
}
|
|
|
|
|
|
|
|
replace() {
|
|
|
|
file="$1"
|
|
|
|
from="$(escape "$2")"
|
|
|
|
to="$(escape "$3")"
|
|
|
|
sed -i "s/${from}/${to}/g" "$file"
|
|
|
|
}
|
|
|
|
|
2024-09-27 01:02:55 +00:00
|
|
|
rm ../qml/eu/ad5001/LogarithmPlotter/js/index.mjs # Remove index which should not be scanned
|
|
|
|
|
2024-10-09 18:15:27 +00:00
|
|
|
files=$(find ../../common/src -name '*.mjs')
|
2024-09-20 21:44:29 +00:00
|
|
|
for file in $files; do
|
|
|
|
echo "Moving '$file' to '${file%.*}.js'..."
|
|
|
|
mv "$file" "${file%.*}.js"
|
|
|
|
# Replacements to make it valid js
|
2024-09-22 16:28:36 +00:00
|
|
|
replace "${file%.*}.js" "^import" "/*import"
|
2024-09-27 01:02:55 +00:00
|
|
|
replace "${file%.*}.js" "^export *" "/*export *"
|
2024-09-22 16:28:36 +00:00
|
|
|
replace "${file%.*}.js" '.mjs"$' '.mjs"*/'
|
|
|
|
replace "${file%.*}.js" "^export default" "/*export default*/"
|
|
|
|
replace "${file%.*}.js" "^export" "/*export*/"
|
2024-09-27 01:02:55 +00:00
|
|
|
replace "${file%.*}.js" "async " "/*async */"
|
|
|
|
replace "${file%.*}.js" "await" "/*await */"
|
2024-10-10 03:33:01 +00:00
|
|
|
replace "${file%.*}.js" " #" "// #"
|
|
|
|
replace "${file%.*}.js" "this.#" "/*this.#*/"
|
2024-09-20 21:44:29 +00:00
|
|
|
done
|
|
|
|
|
2024-09-22 16:28:36 +00:00
|
|
|
echo "----------------------------"
|
|
|
|
echo "| Updating translations... |"
|
|
|
|
echo "----------------------------"
|
2024-10-17 03:09:33 +00:00
|
|
|
pyside6-lupdate -extensions js,qs,qml,py -recursive ../../common/src -recursive ../../runtime-pyside6/LogarithmPlotter -ts lp_*.ts
|
2024-09-20 21:44:29 +00:00
|
|
|
# Updating locations in files
|
|
|
|
for lp in *.ts; do
|
|
|
|
echo "Replacing locations in $lp..."
|
|
|
|
for file in $files; do
|
2024-09-22 16:28:36 +00:00
|
|
|
replace "$lp" "${file%.*}.js" "$file"
|
2024-09-20 21:44:29 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
for file in $files; do
|
|
|
|
echo "Moving '${file%.*}.js' to '$file'..."
|
|
|
|
mv "${file%.*}.js" "$file"
|
|
|
|
# Resetting changes
|
2024-09-27 01:02:55 +00:00
|
|
|
replace "$file" "/*await */" "await"
|
|
|
|
replace "$file" "/*async */" "async "
|
|
|
|
replace "$file" "^/*export*/" "export"
|
|
|
|
replace "$file" "^/*export default*/" "export default"
|
2024-10-10 03:33:01 +00:00
|
|
|
replace "$file" '.mjs"*/' '.mjs"'
|
2024-09-22 16:28:36 +00:00
|
|
|
replace "$file" "^/*import" "import"
|
2024-09-27 01:02:55 +00:00
|
|
|
replace "$file" "^/*export" "export"
|
2024-10-10 03:33:01 +00:00
|
|
|
replace "$file" "// #" " #"
|
|
|
|
replace "$file" "/*this.#*/" "this.#"
|
2024-09-20 21:44:29 +00:00
|
|
|
done
|