Skip to content

Commit 9065b12

Browse files
authored
Upload directly to Crowdin (hestiacp#3702)
* Sync with crowdin * Add on PR for testing * use correct path * Don't run on PR any more.. * Update crowdin.yml
1 parent 56c2a9f commit 9065b12

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

.github/workflows/crowdin.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Crowdin
2+
3+
on:
4+
schedule:
5+
- cron: "20 4 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-pot:
10+
name: Update .pot file
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
- name: Build hestiacp.pot
19+
run: |
20+
sudo apt install gettext -y
21+
cd ./web/locale
22+
bash ./hst_scan_i18n.sh
23+
- name: Commit new .pot file
24+
uses: stefanzweifel/git-auto-commit-action@v4
25+
- name: crowdin action
26+
uses: crowdin/github-action@v1
27+
with:
28+
upload_sources: true
29+
upload_translations: false
30+
download_translations: false
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
34+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

crowdin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
files:
2+
- source: /web/locale/hestiacp.pot
3+
project_id_env: CROWDIN_PROJECT_ID
4+
api_token_env: CROWDIN_PERSONAL_TOKEN

web/locale/hst_scan_i18n.sh

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,32 @@ if [ ! -e /usr/bin/xgettext ]; then
66
exit 3
77
fi
88

9-
delete=0
10-
11-
echo "[ * ] Remove old hestiacp.pot and generate new one"
12-
rm hestiacp.pot
9+
echo "[ * ] Move hestiacp.pot to Move hestiacp.pot.old"
10+
mv hestiacp.pot hestiacp.pot.old
1311
echo "" > hestiacp.pot
12+
13+
echo "[ * ] Search *.php *.html and *.sh for php based gettext functions"
1414
find ../.. \( -name '*.php' -o -name '*.html' -o -name '*.sh' \) | xgettext --output=hestiacp.pot --language=PHP --join-existing -f -
1515
OLDIFS=$IFS
1616
IFS=$'\n'
1717
# Scan the description string for list updates page
18-
for string in $(awk -F'DESCR=' '/data=".+ DESCR=[^"]/ {print $2}' $HESTIA/bin/v-list-sys-hestia-updates | cut -d\' -f2); do
18+
for string in $(awk -F'DESCR=' '/data=".+ DESCR=[^"]/ {print $2}' ../../bin/v-list-sys-hestia-updates | cut -d\' -f2); do
1919
if [ -z "$(grep "\"$string\"" hestiacp.pot)" ]; then
20-
echo -e "\n#: ../../bin/v-list-sys-hestia-updates:"$(grep -n "$string" $HESTIA/bin/v-list-sys-hestia-updates | cut -d: -f1)"\nmsgid \"$string\"\nmsgstr \"\"" >> hestiacp.pot
20+
echo -e "\n#: ../../bin/v-list-sys-hestia-updates:"$(grep -n "$string" ../../bin/v-list-sys-hestia-updates | cut -d: -f1)"\nmsgid \"$string\"\nmsgstr \"\"" >> hestiacp.pot
2121
fi
2222
done
2323
# Scan the description string for list server page
24-
for string in $(awk -F'SYSTEM=' '/data=".+ SYSTEM=[^"]/ {print $2}' $HESTIA/bin/v-list-sys-services | cut -d\' -f2); do
24+
for string in $(awk -F'SYSTEM=' '/data=".+ SYSTEM=[^"]/ {print $2}' ../../bin/v-list-sys-services | cut -d\' -f2); do
2525
if [ -z "$(grep "\"$string\"" hestiacp.pot)" ]; then
26-
echo -e "\n#: ../../bin/v-list-sys-services:"$(grep -n "$string" $HESTIA/bin/v-list-sys-services | cut -d: -f1)"\nmsgid \"$string\"\nmsgstr \"\"" >> hestiacp.pot
26+
echo -e "\n#: ../../bin/v-list-sys-services:"$(grep -n "$string" ../../bin/v-list-sys-services | cut -d: -f1)"\nmsgid \"$string\"\nmsgstr \"\"" >> hestiacp.pot
2727
fi
2828
done
2929
IFS=$OLDIFS
3030

31-
echo "[ * ] Scan language folders"
32-
languages=$(ls -d $HESTIA/web/locale/*/ | awk -F'/' '{print $(NF-1)}')
33-
echo "[ * ] Update hestiacp.pot with new files"
34-
for lang in $languages; do
35-
if [ -e "$HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po" ]; then
36-
echo "[ * ] Update $lang "
37-
mv $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak
38-
msgmerge --verbose "$HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak" "$HESTIA/web/locale/hestiacp.pot" > $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po
39-
rm $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak
40-
fi
41-
done
42-
echo "[ ! ] Update complete"
31+
# Prevent only date change become a commit
32+
if [ $(diff hestiacp.pot hestiacp.pot.old | wc -l) != 2 ]; then
33+
rm hestiacp.pot
34+
mv hestiacp.pot.old hestiacp.pot
35+
else
36+
rm hestiacp.pot.old
37+
fi

0 commit comments

Comments
 (0)