-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
99 lines (86 loc) · 4.19 KB
/
action.yml
File metadata and controls
99 lines (86 loc) · 4.19 KB
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
name: 'Translate Cura plugin'
description: 'Create and update translation of the Cura plugin'
inputs:
translation_folder: # path to the translation directory usually i18n
description: 'translation folder of the Cura plugin'
required: true
default: 'i18n'
translation_name: # name of the translation template and locale files (will be used to include translation)
description: 'translation template and locale files name'
required: true
plugin_name: # will be dispayed in the translation files header
description: 'plugin name'
required: true
outputs:
template_updated:
description: ".pot template updated"
value: ${{ steps.template_updated.outputs.updated }}
locales_updated:
description: ".mo file/files updated"
value: ${{ steps.locale_updated.outputs.updated }}
runs:
using: "composite"
steps:
- uses: ConorMacBride/install-package@v1
with:
apt: gettext
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Ensure translation folder exists"
run: mkdir -p "${{ inputs.translation_folder }}"
shell: bash
- name: "Check template file exists"
id: template_exist
run: echo "exists=$([[ -f ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot ]] && echo true)" >> $GITHUB_OUTPUT
shell: bash
- name: Hash current .pot messages
if: ${{ steps.template_exist.outputs.exists }}
id: hash_before
run: echo "i18n_hash=$(grep '^msgid' ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot | sort | sha1sum)" >> $GITHUB_OUTPUT
shell: bash
- name: Update .pot from Python files
run: xgettext --package-name='${{ inputs.plugin_name }}' -o ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot --language=python --from-code=UTF-8 -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 $(find -L . -name \*.py)
shell: bash
- name: Update .pot from QML files
run: xgettext --package-name='${{ inputs.plugin_name }}' -o ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot --join-existing --language=javascript --from-code=UTF-8 -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 $(find -L . -name \*.qml)
shell: bash
- name: Hash new .pot messages
id: hash_after
run: echo "i18n_hash=$(grep '^msgid' ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot | sort | sha1sum)" >> $GITHUB_OUTPUT
shell: bash
- if: ${{ steps.hash_after.outputs.i18n_hash != steps.hash_before.outputs.i18n_hash }}
name: Set output value
id: template_updated
run: echo "updated=1" >> $GITHUB_OUTPUT
shell: bash
- if: ${{ steps.template_updated.outputs.updated == ''}}
name: Reset .pot file/file
run: git checkout -- ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot
shell: bash
- if: ${{ steps.template_updated.outputs.updated }}
name: Update .po files
run: find ${{ inputs.translation_folder }} -name ${{ inputs.translation_name }}.po -exec msgmerge --update {} --backup=none ${{ inputs.translation_folder }}/${{ inputs.translation_name }}.pot \;
shell: bash
- if: ${{ steps.template_exist.outputs.exists }}
id: mo_update_neened
run: |
for changed_po in `git diff-tree --no-commit-id --name-only -r ${{github.sha}}`; do
if [[ ${changed_po} == *${{ inputs.translation_name }}.po ]]
then
echo ${changed_po} changed
echo "needed=1" >> $GITHUB_OUTPUT
fi
done
shell: bash
- if: ${{ steps.template_updated.outputs.updated || steps.mo_update_neened.outputs.needed }}
name: Ensure LC_MESSAGES folder exists
run: find ${{ inputs.translation_folder }} -maxdepth 1 -name '*_*' -exec mkdir -p {}/LC_MESSAGES \;
shell: bash
- if: ${{ steps.template_updated.outputs.updated || steps.mo_update_neened.outputs.needed }}
name: Update .mo files
id: locale_updated
run: |
find ${{ inputs.translation_folder }} -maxdepth 1 -name '*_*' -exec msgfmt {}/${{ inputs.translation_name }}.po -o {}/LC_MESSAGES/${{ inputs.translation_name }}.mo \;
echo "updated=1" >> $GITHUB_OUTPUT
shell: bash