Просмотр исходного кода

Upload directly to Crowdin (#3702)

* Sync with crowdin

* Add on PR for testing

* use correct path

* Don't run on PR any more..

* Update crowdin.yml
Jaap Marcus 2 лет назад
Родитель
Сommit
9065b121c2
3 измененных файлов с 53 добавлено и 20 удалено
  1. 34 0
      .github/workflows/crowdin.yml
  2. 4 0
      crowdin.yml
  3. 15 20
      web/locale/hst_scan_i18n.sh

+ 34 - 0
.github/workflows/crowdin.yml

@@ -0,0 +1,34 @@
+name: Crowdin
+
+on:
+  schedule:
+    - cron: "20 4 * * *"
+  workflow_dispatch:
+
+jobs:
+  update-pot:
+    name: Update .pot file
+    runs-on: ubuntu-latest
+    permissions:
+      contents: write
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v3
+      - name: Build hestiacp.pot
+        run: |
+          sudo apt install gettext -y
+          cd ./web/locale
+          bash ./hst_scan_i18n.sh
+      - name: Commit new .pot file
+        uses: stefanzweifel/git-auto-commit-action@v4
+      - name: crowdin action
+        uses: crowdin/github-action@v1
+        with:
+          upload_sources: true
+          upload_translations: false
+          download_translations: false
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
+          CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

+ 4 - 0
crowdin.yml

@@ -0,0 +1,4 @@
+files:
+  - source: /web/locale/hestiacp.pot
+project_id_env: CROWDIN_PROJECT_ID
+api_token_env: CROWDIN_PERSONAL_TOKEN

+ 15 - 20
web/locale/hst_scan_i18n.sh

@@ -6,37 +6,32 @@ if [ ! -e /usr/bin/xgettext ]; then
 	exit 3
 fi
 
-delete=0
-
-echo "[ * ] Remove old hestiacp.pot and generate new one"
-rm hestiacp.pot
+echo "[ * ] Move hestiacp.pot to Move hestiacp.pot.old"
+mv hestiacp.pot hestiacp.pot.old
 echo "" > hestiacp.pot
+
+echo "[ * ] Search *.php *.html and *.sh for php based gettext functions"
 find ../.. \( -name '*.php' -o -name '*.html' -o -name '*.sh' \) | xgettext --output=hestiacp.pot --language=PHP --join-existing -f -
 OLDIFS=$IFS
 IFS=$'\n'
 # Scan the description string for list updates page
-for string in $(awk -F'DESCR=' '/data=".+ DESCR=[^"]/ {print $2}' $HESTIA/bin/v-list-sys-hestia-updates | cut -d\' -f2); do
+for string in $(awk -F'DESCR=' '/data=".+ DESCR=[^"]/ {print $2}' ../../bin/v-list-sys-hestia-updates | cut -d\' -f2); do
 	if [ -z "$(grep "\"$string\"" hestiacp.pot)" ]; then
-		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
+		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
 	fi
 done
 # Scan the description string for list server page
-for string in $(awk -F'SYSTEM=' '/data=".+ SYSTEM=[^"]/ {print $2}' $HESTIA/bin/v-list-sys-services | cut -d\' -f2); do
+for string in $(awk -F'SYSTEM=' '/data=".+ SYSTEM=[^"]/ {print $2}' ../../bin/v-list-sys-services | cut -d\' -f2); do
 	if [ -z "$(grep "\"$string\"" hestiacp.pot)" ]; then
-		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
+		echo -e "\n#: ../../bin/v-list-sys-services:"$(grep -n "$string" ../../bin/v-list-sys-services | cut -d: -f1)"\nmsgid \"$string\"\nmsgstr \"\"" >> hestiacp.pot
 	fi
 done
 IFS=$OLDIFS
 
-echo "[ * ] Scan language folders"
-languages=$(ls -d $HESTIA/web/locale/*/ | awk -F'/' '{print $(NF-1)}')
-echo "[ * ] Update hestiacp.pot with new files"
-for lang in $languages; do
-	if [ -e "$HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po" ]; then
-		echo "[ * ] Update $lang "
-		mv $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak
-		msgmerge --verbose "$HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak" "$HESTIA/web/locale/hestiacp.pot" > $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po
-		rm $HESTIA/web/locale/$lang/LC_MESSAGES/hestiacp.po.bak
-	fi
-done
-echo "[ ! ] Update complete"
+# Prevent only date change become a commit
+if [ $(diff hestiacp.pot hestiacp.pot.old | wc -l) != 2 ]; then
+	rm hestiacp.pot
+	mv hestiacp.pot.old hestiacp.pot
+else
+	rm hestiacp.pot.old
+fi