-
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.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 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,27 @@ | ||
me: CSV-To-PO | ||
|
||
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 ./csv-to-po.sh | ||
./csv-to-po.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
cd languages || exit | ||
|
||
CSV_FILE="en_GB.csv" | ||
OUTPUT_DIR="intermediate_po" | ||
TEMPLATE_POT="en_GB.pot" | ||
|
||
if [[ ! -e $CSV_FILE ]]; then | ||
echo "File $CSV_FILE not found." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p $OUTPUT_DIR | ||
|
||
# Remove surrounding quotes | ||
trim_quotes() { | ||
local val="$1" | ||
echo "$val" | sed -e 's/^"//' -e 's/"$//' | ||
} | ||
|
||
# Parse the header to get the list of languages | ||
IFS=',' read -ra HEADER <<< "$(head -n 1 $CSV_FILE)" | ||
|
||
# For each language in the CSV, create an intermediate .po file | ||
for i in "${!HEADER[@]}"; do | ||
if (( $i > 3 )); then | ||
LANGUAGE=$(trim_quotes "${HEADER[$i]}") | ||
echo -n "" > "$OUTPUT_DIR/$LANGUAGE.po" | ||
while IFS=',' read -ra LINE; do | ||
# Skip the header line | ||
if [[ "${LINE[0]}" != "msgid" ]]; then | ||
if [[ -n "${LINE[3]}" ]]; then | ||
echo "#: $(trim_quotes "${LINE[3]}")" >> "$OUTPUT_DIR/$LANGUAGE.po" | ||
fi | ||
if [[ -n "${LINE[2]}" ]]; then | ||
echo "msgctxt \"$(trim_quotes "${LINE[2]}")\"" >> "$OUTPUT_DIR/$LANGUAGE.po" | ||
fi | ||
echo "msgid \"$(trim_quotes "${LINE[0]}")\"" >> "$OUTPUT_DIR/$LANGUAGE.po" | ||
echo "msgstr \"$(trim_quotes "${LINE[$i]}")\"" >> "$OUTPUT_DIR/$LANGUAGE.po" | ||
echo "" >> "$OUTPUT_DIR/$LANGUAGE.po" | ||
fi | ||
done < "$CSV_FILE" | ||
fi | ||
done | ||
# Append intermediate .po to existing .po | ||
for po in $OUTPUT_DIR/*.po; do | ||
BASENAME=$(basename "$po" ".po" | tr -d ' ') | ||
EXISTING_PO="mollie-payments-for-woocommerce${BASENAME}.po" | ||
if [[ -e $EXISTING_PO ]]; then | ||
cat "$po" >> $EXISTING_PO | ||
fi | ||
done | ||
|
||
# Compile .po to .mo | ||
for po in *.po; do | ||
MO_FILE="${po%.po}.mo" | ||
msgfmt "$po" -o "$MO_FILE" | ||
done |