[Automated] Crowdin synchronization (#187) #255
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |