-
-
Notifications
You must be signed in to change notification settings - Fork 8
175 lines (144 loc) · 5.92 KB
/
generate-mo.yml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Automated compiling of translations
on:
push:
branches: main
ignore_paths:
- "**/*.mo"
- "messages.pot"
jobs:
build:
runs-on: ubuntu-latest
name: Compile to .mo
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install gettext
run: sudo apt-get update && sudo apt-get install gettext -y
- name: Generate .mo files
run: |
for po_file in $(find . -name "*.po"); do
dirname=$(dirname $po_file)
filename=$(basename $po_file .po)
msgfmt $po_file -o "$dirname/$filename.mo"
done
- name: Add .mo files to git
run: git add .
- name: (Workaround) Rename the Serbian Folder Name
run: |
if [ -d ./srp ]; then
# Ensure the correctly named folder is removed
if [ -d ./sr_RS ]; then
rm -rf ./sr_RS
fi
# Now rename the folder within git
git mv ./srp ./sr_RS
fi
- name: Commit and push .mo files
uses: actions-js/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "Automated .mo file generation"
- name: Create artifact
uses: actions/upload-artifact@v4
with:
name: translations
path: |
./**/messages.mo
./**/messages.po
locales.php
LICENSE.md
messages.pot
readme.md
release:
name: Publish to release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download the artifact
uses: actions/download-artifact@v4
- name: Calculate the Translation Tag (messages.pot hash)
working-directory: translations
run: echo "TRANSLATION_TAG=$(md5sum messages.pot | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Display structure of downloaded files
run: ls -R
- name: Install gettext
run: sudo apt-get update && sudo apt-get install gettext -y
- name: Remove translations with low completion
working-directory: translations
run: |
now=$(date)
echo "## FOSSBilling Translations" >>translations.md
echo "Dated: $now" >>translations.md
echo "Translation Tag: [$TRANSLATION_TAG](https://github.com/FOSSBilling/locale/releases/tag/$TRANSLATION_TAG)" >>translations.md
rm -f messages.pot
# Create an associative array to store completion percentages
declare -A completion_array
for po_file in $(find . -name "*.po"); do
dirname=$(dirname "$po_file")
translation=$(dirname "$dirname")
# Use msgfmt to generate temporary file with statistics
msgfmt --statistics "$po_file" >/tmp/msgfmt_stats.tmp 2>&1
# Capture the statistics output
statistics=$(cat /tmp/msgfmt_stats.tmp)
# Remove the temporary file
rm /tmp/msgfmt_stats.tmp
# Extract the number of translated and total messages
translated_messages=$(echo "$statistics" | awk -F ',' '{print $1}' | awk '{print $1}')
untranslated_messages=$(echo "$statistics" | awk -F ',' '{print $2}' | awk '{print $1}')
total_messages=$((translated_messages + untranslated_messages))
# Calculate completion percentage
if [ -n "$translated_messages" ] && [ -n "$total_messages" ]; then
completion_percentage=$((translated_messages * 100 / total_messages))
else
completion_percentage=0
fi
completeBars=$(($completion_percentage / 10))
incompleteBars=$((10 - $completeBars))
bar=""
for ((i = 0; i < completeBars; i++)); do
bar+="▰"
done
for ((i = 0; i < incompleteBars; i++)); do
bar+="▱"
done
# If the translation is less than 25% complete, delete it entirely. Otherwise, just remove the source file to make things cleaner
if [ "$completion_percentage" -lt 25 ] && [ "$dirname" != "./en_US/LC_MESSAGES" ]; then
rm -rf "$translation"
translation=${translation#./}
completion_array["$translation"]=$completion_percentage
echo " - \`$translation\`: $bar $completion_percentage% translated (excluded, too incomplete)" >>translations.md
else
if [ "$dirname" != "./en_US/LC_MESSAGES" ]; then
translation=${translation#./}
echo " - \`$translation\`: $bar $completion_percentage% translated" >>translations.md
completion_array["$translation"]=$completion_percentage
fi
rm -f "$dirname/messages.po"
fi
done
# Create a PHP file with the completion percentages
echo '<?php' > completion.php
echo '/**' >> completion.php
echo ' * FOSSBilling translations' >> completion.php
echo " * Dated: $now" >> completion.php
echo ' * License: https://github.com/FOSSBilling/locale/blob/main/LICENSE.md' >> completion.php
echo ' */' >> completion.php
echo 'return [' >> completion.php
for locale in "${!completion_array[@]}"; do
percentage=${completion_array[$locale]}
echo " '$locale' => $percentage," >> completion.php
done
echo '];' >> completion.php
rm -f messages.mo
- name: Create a zip of the translations
run: zip -r ./translations.zip .
working-directory: translations
- name: Release to GitHub
uses: ncipollo/release-action@v1
with:
name: Translations (${{ env.TRANSLATION_TAG }})
tag: ${{ env.TRANSLATION_TAG }}
commit: main
bodyFile: translations/translations.md
artifacts: translations/translations.zip
allowUpdates: true