Build .qm files from .ts or .csv ones at build time

This commit is contained in:
Sebastien Fourey 2022-05-24 17:56:15 +02:00
parent ba428215f0
commit 319adab966
44 changed files with 38318 additions and 167977 deletions

View File

@ -21,9 +21,6 @@
# Possible values are "on" or "off"
!defined(LTO,var) { LTO=off }
# Possible values are "on" or "off"
!defined(TEST_FILTERS_QM,var) { TEST_FILTERS_QM=off }
#
#
#
@ -410,7 +407,6 @@ SOURCES += \
src/Widgets/LanguageSelectionWidget.cpp \
src/Widgets/ProgressInfoWindow.cpp
equals(GMIC_DYNAMIC_LINKING, "on" ) {
message(Dynamic linking with libgmic)
LIBS += -Wl,-rpath,. $$GMIC_PATH/libgmic.so
@ -457,6 +453,20 @@ translations/zh_tw.ts
RESOURCES += wip_translations.qrc
# message(Build QM translation files)
# system(make -C translations)
# system(make -C translations/filters)
qm_files.commands += make -C translations
qm_filter_files.commands += make -C translations/filters
QMAKE_EXTRA_TARGETS += qm_files qm_filter_files
PRE_TARGETDEPS += qm_files qm_filter_files
QMAKE_DISTCLEAN = \
translations/*.qm \
translations/filters/*.ts \
translations/filters/*.qm
# Prevent overwriting of these files by lupdate
# TRANSLATIONS += translations/filters/fr.ts

View File

@ -10,7 +10,7 @@
<file>translations/zh.qm</file>
<file>translations/zh_tw.qm</file>
<file>translations/ru.qm</file>
<file>translations/ua.qm</file>
<file>translations/uk.qm</file>
<file>translations/pl.qm</file>
<file>translations/pt.qm</file>
<file>translations/ja.qm</file>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,27 +1,40 @@
# G'MIC-Qt: Contribute to filters translation
We describe here the steps you should follow
if you want to help with the Italian translation of the filters
if you want to help with the *Italian* translation of the filters
(names, parameters, etc.).
## Step 1: Edit the `it.ts` file
## Step 1: Edit the `it.csv` file
* The `.ts` files are located in the
* The `.csv` files are located in the
[translations/filters](https://github.com/c-koi/gmic-qt/tree/master/translations/filters)
folder.
* They contain only automatic translations for now.
* They contain only automatic translations for now (except for French and Chinese).
Therefore they really need some editing!
* Editing can be done using a simple text editor, although the
`linguist-qt5` tool may help.
* Editing can be done using a simple text editor.
* The CSV file contains up to 3 columns :
```txt
Original text , Translation [, Filter name]
```
## Step 2: Produce an `it.qm` file
* `it.qm` file is the "binary" version of `it.ts`.
* In the `translations/filters` folder, run:
Filter name may be used to disambiguate the translation by providing a context.
## Step 2: Enable the language in `translations/filters/Makefile`
* Edit the `Makefile` to add the `.qm` file to the list.
```txt
QM = fr.qm zh.qm it.qm
```
* In the `translations/filters` folder, run make:
```shell
$ lrelease-qt5 -compress fr.ts
$ make
```
* Check that this indeed produced the file `it.qm`.
@ -34,6 +47,7 @@ $ lrelease-qt5 -compress fr.ts
<RCC>
<qresource prefix="/">
<file>translations/filters/fr.qm</file>
<file>translations/filters/zh.qm</file>
<file>translations/filters/it.qm</file>
</qresource>
</RCC>
@ -42,5 +56,6 @@ $ lrelease-qt5 -compress fr.ts
As a WIP, it is disabled by default.
## Step 4: Submit a Pull Request
* Your PR should only include the `it.ts` file and the updated
* Your PR should only include the `it.csv`, the `Makefile`, and the updated
`wip_translations.qrc`.

109
translations/filters/csv2ts.sh Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/env bash
function usage()
{
cat <<EOF
Usage:
`basename $0` -o output.ts file.csv
EOF
exit 0
}
output=/dev/stdout
while getopts o: opt ; do
case $opt in
o) output=$OPTARG ;;
*) die "Command line parsing failed"
esac
done
n=$(( OPTIND - 1 ))
while [[ $n -gt 0 ]]; do
shift
n=$((n - 1))
done
function die()
{
local message="$@"
>&2 echo "$message"
exit 1
}
function requires()
{
type "$1" >& /dev/null || die "Command '$1' not found."
}
requires sed
input="$1"
[[ -z "$input" ]] && usage
[[ ! -e "$input" ]] && die "File not found: $input"
[[ ! $input =~ .*\.csv$ ]] && die "Not a csv file: $input"
if [[ $input =~ gmic_qt.*\.csv ]]; then
language=${input%%.csv}
language=${language##*_}
else
language=${input%%.csv}
language=${language%%_*}
fi
cat <<EOF > $output
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="${language}">
<context>
<name>FilterTextTranslator</name>
EOF
# @param name
# @param text
function xml_tag()
{
local name="$1"
local text="$2"
text=${text//&/&amp;}
text=${text//\"/&quot;}
text=${text//\'/&apos;}
text=${text//</&lt;}
text=${text//>/&gt;}
text=${text# }
echo " <${name}>${text}</$name>"
}
# @param source
# @param translation
# @param comment (optionnal)
function message()
{
local source="$1"
local translation="$2"
local comment="$3"
echo -e "\n <message>"
xml_tag source "$source"
[[ -n "$comment" ]] && xml_tag comment "$comment"
xml_tag translation "$translation"
echo " </message>"
}
while IFS=$'\t' read -r -a columns ; do
count=${#columns[@]}
if (( count > 2 )); then
i=2
while (( i < count )); do
message "${columns[0]}" "${columns[1]}" "${columns[$i]}" >> $output
i=$((i+1))
done
elif (( count == 2 )); then
message "${columns[0]}" "${columns[1]}" >> $output
fi
done < <(sed -e 's/ , /\t/g' "$input")
cat <<EOF >> $output
</context>
</TS>
EOF

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

84
translations/filters/ts2csv.sh Executable file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
function usage()
{
cat <<EOF
Usage:
`basename $0` -o output.csv file.ts
EOF
exit 0
}
output=/dev/stdout
while getopts o: opt ; do
case $opt in
o) output=$OPTARG ;;
*) die "Command line parsing failed"
esac
done
n=$(( OPTIND - 1 ))
while [[ $n -gt 0 ]]; do
shift
n=$((n - 1))
done
function die()
{
local message="$@"
>&2 echo "$message"
exit 1
}
function requires()
{
type "$1" >& /dev/null || die "Command '$1' not found."
}
in="$1"
[[ -z "$in" ]] && usage
[[ ! -e "$in" ]] && die "File not found: $in"
[[ ! $in =~ .*\.ts$ ]] && die "Not a ts file: $in"
# @param text
function html2ascii()
{
local text="$1"
text=${text//&amp;/&}
text=${text//&lt;/<}
text=${text//&gt;/>}
text=${text//&quot;/\"}
text=${text//&apos;/\'}
echo -n "$text"
}
echo -n > $output
while read line; do
comment=""
if [[ "$line" =~ \ *\<message\> ]]; then
read src
read translation
if [[ "$translation" =~ \<comment\>.*\</comment\> ]]; then
comment="$translation"
read translation
fi
read dummy # </message>
src=$(echo "$src")
src=${src:8}
src=${src%</source>}
src=$(html2ascii "$src")
translation=$(echo "$translation")
translation=${translation:13}
translation=${translation%</translation>}
translation=$(html2ascii "$translation")
if [[ -z "$comment" ]]; then
echo "$src , $translation" >> $output
else
comment=$(echo "$comment")
comment=${comment:9}
comment=${comment%</comment>}
echo "$src , $translation , $comment" >> $output
fi
fi
done < "$in"

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

37
translations/lrelease.sh Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
function usage()
{
cat <<EOF
Usage:
`basename $0` file.ts
Call lrelease or lrelease-qt5 on file, depending on which command exists.
EOF
exit 0
}
function die()
{
local message="$@"
>&2 echo "$message"
exit 1
}
function exists()
{
type "$1" >& /dev/null
}
in="$1"
[[ -z "$in" ]] && usage
[[ ! -e "$in" ]] && die "File not found: $in"
[[ ! $in =~ .*\.ts$ ]] && die "Not a ts file: $in"
if exists lrelease-qt5 ; then
exec lrelease-qt5 -compress "$in"
elif exists lrelease ; then
exec lrelease -compress "$in"
else
die "No lrelease(-qt5) command available."
fi

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.