-
Notifications
You must be signed in to change notification settings - Fork 0
/
po4a.sh
executable file
·134 lines (109 loc) · 3.73 KB
/
po4a.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
/bin/echo "[po_directory] po
[options] -M UTF-8 -L UTF-8 -A UTF-8 --master-language en --msgmerge-opt '--no-wrap' --porefs file --wrap-po no
[po4a_alias:markdown] text -o markdown -o neverwrap -o nobullets -k 90" > "./po4a.conf"
shopt -s nullglob
shopt -s globstar
rm source/titles/titles.yaml
for file in source/**/*.md; do
newfile=""
filename=${file##*/}
filename=${filename%%\.*}
filere="($filename):\s{0,1}(.*?)"
while IFS="" read -r line || [ -n "$line" ]; do
if [[ $line =~ $filere ]]; then
newfile=${BASH_REMATCH[2]}
break
fi
done < source/titles/titles.yaml
if [[ -z $newfile ]]; then
/bin/echo "$filename: $filename" >> source/titles/titles.yaml
fi
done
for file in source/**/*.md; do
filename=${file##*/}
filename=${filename%%\.*}
folder=${file#*/}
folder=/${folder#*/}
folder=${folder%/*}
repo=${file#*/}
repo=${repo%%/*}
headre="^[,]"
if [[ $(sed '3q;d' $file) =~ $headre ]]; then
sed -i '2,3d' $file
fi
/bin/echo "[type:markdown] $file \$lang:i18n/$repo/\$lang$folder/$filename.md" >> "./po4a.conf"
cp $file source/$repo$folder/en_${filename}_en.md
/bin/echo "[type:markdown] source/$repo$folder/en_${filename}_en.md en:i18n/$repo/en$folder/$filename.md opt:\"-k 0\"" >> "./po4a.conf"
done
/bin/echo "[type:yaml] source/titles/titles.yaml \$lang:i18n/titles/\$lang/titles.yaml opt:\"-k 0\"" >> "./po4a.conf"
if [ -d ./i18n ]; then
rm -R ./i18n
fi
po4a ./po4a.conf -f -v
for file in source/**/en_*_en.md; do
rm $file
done
sed -i "/en_.*_en\.md/d" ./po4a.conf
po4a ./po4a.conf -f -v --no-translations
sed -i '1d' ./i18n/**/*.yaml
sed -i "s/\(.*:.*\)'\(.*\)'/\1\2/g" ./i18n/titles/*/titles.yaml
find ./i18n -type d -empty -delete
for file in i18n/**/*.md; do
filename=${file##*/}
filename=${filename%%\.*}
postlang=${file#*/}
postlang=${postlang#*/}
postlang=/${postlang#*/}
postlang=${postlang%/*}
lang=${file#*/}
lang=${lang#*/}
lang=${lang%%/*}
repo=${file#*/}
repo=${repo%%/*}
dirre="<div[[:space:]]dir=\"([lrt]{3})\"[[:space:]]align=\"([efghilrt]{4,5})\">"
if [[ $(sed '1q;d' $file) =~ $dirre ]]; then
if [[ ${BASH_REMATCH[1]} == "ltr" ]]; then
dir=""
else
dir=""
fi
fi
sed -i "3s/^/\n/" $file
for link in i18n/$repo/*$postlang/$filename.md; do
curlang=${link#*/}
curlang=${curlang#*/}
curlang=${curlang%%/*}
linkname=${link##*/}
linkname=${linkname%%\.*}
filere="($linkname):\s{0,1}(.*?)"
newlang=$(node -e "console.log(new Intl.DisplayNames(['$curlang'], { type: 'language' }).of('$curlang'));")
while IFS="" read -r line || [ -n "$line" ]; do
if [[ $line =~ $filere ]]; then
newfile=${BASH_REMATCH[2]}
break
fi
done < i18n/titles/$curlang/titles.yaml
if [[ $curlang == $lang ]]; then
sed -i '3s@$@'"$dir**$newlang** | "'@' $file
else
sed -i '3s@$@'"$dir[$newlang](/docs/$curlang$postlang/$newfile.md) | "'@' $file
fi
done
sed -i '3s@$@'"$dir[[+]](https://weblate.librescore.org/projects/librescore/docs)\\n"'@' $file
done
shopt -u globstar
for file in i18n/titles/*/titles.yaml; do
re="(.*?):\s{0,1}(.*?)"
lang=${file%/*}
lang=${lang##*/}
while IFS="" read -r line || [ -n "$line" ]; do
if [[ $line =~ $re ]]; then
if [ "${BASH_REMATCH[1]}" != "${BASH_REMATCH[2]}" ]; then
find ./i18n/*/$lang/ -name "${BASH_REMATCH[1]}.md" -exec sh -c 'mv $0 "${0%/*}/'"${BASH_REMATCH[2]}"'.md"' {} \;
fi
fi
done < $file
done
shopt -u nullglob
exit 0