-
-
Notifications
You must be signed in to change notification settings - Fork 8
146 lines (119 loc) · 4.84 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
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: 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@v3
with:
name: translations
path: |
./**/messages.mo
./**/messages.po
locales.php
LICENSE.md
readme.md
release:
name: Publish to release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download the artifact
uses: actions/download-artifact@v3
- 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
# 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
# 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\` was skipped for only being $completion_percentage% translated" >>translations.md
else
if [ "$dirname" != "./en_US/LC_MESSAGES" ]; then
translation=${translation#./}
echo " - \`$translation\` is $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 ' * Licence: 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: Latest Translations
tag: latest
commit: main
bodyFile: translations/translations.md
artifacts: translations/translations.zip
allowUpdates: true