-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #830 from mollie/task/PIWOO-186-pot-generation-action
Add actions to update pot and diff the translation files
- Loading branch information
Showing
25 changed files
with
24,155 additions
and
6,432 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Housekeeping | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches-ignore: | ||
# We expect PRs to be merged when they are "clean". After merge, we don't need to re-trigger on develop | ||
- 'develop' | ||
|
||
jobs: | ||
housekeeping: | ||
permissions: | ||
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: "actions/checkout@v2" | ||
- name: Store branch and latest SHA | ||
id: git | ||
run: | | ||
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | ||
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" | ||
- uses: "shivammathur/setup-php@v2" | ||
with: | ||
php-version: "7.2" | ||
- uses: "ramsey/composer-install@v2" | ||
with: | ||
composer-options: "--prefer-dist" | ||
- name: "Run PHPCBF" | ||
run: "composer fix-coding-standards || true" | ||
|
||
- name: "Install node modules" | ||
run: "npm install" | ||
|
||
- name: "Install WP-CLI" | ||
run: | | ||
mkdir ~/wp-cli && cd ~/wp-cli | ||
curl -L https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar --output wp | ||
chmod +x wp | ||
sudo ln -s ~/wp-cli/wp /usr/local/bin/wp | ||
- name: "Create updated .pot file" | ||
run: | | ||
wp i18n make-pot . ./languages/en_GB.pot --skip-audit --allow-root | ||
# For now, any workflow run would result in a commit due to the updated timestamp even if there are no changes in translations | ||
# We should figure out a way to only set the timestamp when there are new translations, but for now, | ||
# let's just remove that timestamp entirely | ||
- name: "Remove POT-Creation-Date" | ||
run: sed -i '/POT-Creation-Date/d' ./languages/en_GB.pot | ||
|
||
- uses: "stefanzweifel/git-auto-commit-action@v4" | ||
with: | ||
push_options: --force | ||
# This task should never update dependencies | ||
file_pattern: :!*.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
me: Languages-diff | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
PACKAGE_VERSION: | ||
description: 'Package Version' | ||
required: true | ||
jobs: | ||
languages-diff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: "Create CSV of diff translations" | ||
run: | | ||
chmod +x ./convert_csv.sh | ||
./convert_csv.sh | ||
- name: Set artifact name | ||
id: set-artifact-name | ||
run: echo "artifact=mollie-payments-for-woocommerce-languages-${{ inputs.PACKAGE_VERSION }}" >> $GITHUB_OUTPUT | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ steps.set-artifact-name.outputs.artifact }} | ||
path: languages/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
/tools/ | ||
/build/ | ||
/tests/e2e/Shared/default.json | ||
|
||
package-lock.json | ||
.env | ||
cypress.json | ||
test-results/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
cd languages || exit | ||
|
||
POT_FILE="en_GB.pot" | ||
CSV_DIR="untranslated_csv" | ||
|
||
LANG_EXT=("-de_DE" "-de_DE_formal" "-es_ES" "-fr_FR" "-it_IT" "-nl_NL" "-nl_NL_formal" "-nl_BE" "-nl_BE_formal") | ||
|
||
if [[ ! -e $POT_FILE ]]; then | ||
echo "File $POT_FILE not found." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p $CSV_DIR # Create the directory if it does not exist | ||
|
||
# Loop through each language extension | ||
for lang in "${LANG_EXT[@]}"; do | ||
PO_FILE="mollie-payments-for-woocommerce${lang}.po" | ||
CSV_FILE="$CSV_DIR/mollie-payments-for-woocommerce${lang}.csv" | ||
UNTRANSLATED_FILE="$CSV_DIR/mollie-payments-for-woocommerce${lang}_untranslated.csv" | ||
|
||
if [[ -e $PO_FILE ]]; then | ||
msgmerge --update --no-wrap --backup=none "$PO_FILE" "$POT_FILE" # Update PO file with POT file | ||
echo "Updated $PO_FILE with new strings from $POT_FILE" | ||
else | ||
echo "File $PO_FILE not found. Skipping..." | ||
continue | ||
fi | ||
|
||
echo 'location,msgid,msgstr,msgctxt' > "$CSV_FILE" | ||
echo 'line,msgid' > "$UNTRANSLATED_FILE" | ||
|
||
# Initialize variables | ||
location="" | ||
msgid="" | ||
msgstr="" | ||
msgctxt="" | ||
line_no=0 | ||
|
||
# Function to write to CSV | ||
write_to_csv() { | ||
echo "\"$location\",\"$msgid\",\"$msgstr\",\"$msgctxt\"" >> "$CSV_FILE" | ||
if [[ -z "$msgstr" && -n "$msgid" ]]; then | ||
echo "$line_no,\"$msgid\"" >> "$UNTRANSLATED_FILE" | ||
fi | ||
# Reset variables | ||
location="" | ||
msgid="" | ||
msgstr="" | ||
msgctxt="" | ||
} | ||
|
||
while IFS= read -r line || [[ -n "$line" ]]; do # also handle the last line | ||
((line_no++)) | ||
|
||
if [[ "$line" =~ ^\#:\ (.+)$ ]]; then | ||
location="${BASH_REMATCH[1]}" | ||
elif [[ "$line" =~ ^msgid\ \"(.*)\"$ ]]; then | ||
if [[ -n "$msgid" || -n "$msgstr" ]]; then | ||
write_to_csv | ||
fi | ||
msgid="${BASH_REMATCH[1]}" | ||
elif [[ "$line" =~ ^msgstr\ \"(.*)\"$ ]]; then | ||
msgstr="${BASH_REMATCH[1]}" | ||
elif [[ "$line" =~ ^msgctxt\ \"(.+)\"$ ]]; then | ||
msgctxt="${BASH_REMATCH[1]}" | ||
fi | ||
done < "$PO_FILE" | ||
|
||
# For the last msgid in the file | ||
if [[ -n "$msgid" || -n "$msgstr" ]]; then | ||
write_to_csv | ||
fi | ||
|
||
echo "Created CSV $CSV_FILE and $UNTRANSLATED_FILE for $PO_FILE" | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
CSV_DIR="languages/translated_csv" | ||
PO_DIR="languages" | ||
MO_DIR="languages" | ||
|
||
for csv_file in "$CSV_DIR"/*.csv; do | ||
[ -e "$csv_file" ] || continue | ||
|
||
base_name=$(basename -- "$csv_file" .csv) | ||
po_file="$PO_DIR/$base_name.po" | ||
mo_file="$MO_DIR/$base_name.mo" | ||
|
||
awk -F'"' ' | ||
BEGIN { OFS=""; print "msgid \"\""; print "msgstr \"\""; print "\"Content-Type: text/plain; charset=UTF-8\\n\""; } | ||
NR > 1 { | ||
gsub(/\\/, "\\\\", $2); | ||
gsub(/\"/, "\\\"", $2); | ||
gsub(/\\/, "\\\\", $4); | ||
gsub(/\"/, "\\\"", $4); | ||
print "\n#: " $2; | ||
print "msgid \"" $4 "\""; | ||
print "msgstr \"" $6 "\""; | ||
}' "$csv_file" > "$po_file" | ||
|
||
echo "Created PO file: $po_file" | ||
|
||
msgfmt "$po_file" -o "$mo_file" | ||
echo "Created MO file: $mo_file" | ||
done |
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
Oops, something went wrong.