|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +cd languages || exit |
| 4 | + |
| 5 | +POT_FILE="en_GB.pot" |
| 6 | +CSV_DIR="untranslated_csv" |
| 7 | + |
| 8 | +LANG_EXT=("-de_DE" "-de_DE_formal" "-es_ES" "-fr_FR" "-it_IT" "-nl_NL" "-nl_NL_formal" "-nl_BE" "-nl_BE_formal") |
| 9 | + |
| 10 | +if [[ ! -e $POT_FILE ]]; then |
| 11 | + echo "File $POT_FILE not found." |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +mkdir -p $CSV_DIR # Create the directory if it does not exist |
| 16 | + |
| 17 | +# Loop through each language extension |
| 18 | +for lang in "${LANG_EXT[@]}"; do |
| 19 | + PO_FILE="mollie-payments-for-woocommerce${lang}.po" |
| 20 | + CSV_FILE="$CSV_DIR/mollie-payments-for-woocommerce${lang}.csv" |
| 21 | + UNTRANSLATED_FILE="$CSV_DIR/mollie-payments-for-woocommerce${lang}_untranslated.csv" |
| 22 | + |
| 23 | + if [[ -e $PO_FILE ]]; then |
| 24 | + msgmerge --update --no-wrap --backup=none "$PO_FILE" "$POT_FILE" # Update PO file with POT file |
| 25 | + echo "Updated $PO_FILE with new strings from $POT_FILE" |
| 26 | + else |
| 27 | + echo "File $PO_FILE not found. Skipping..." |
| 28 | + continue |
| 29 | + fi |
| 30 | + |
| 31 | + echo 'location,msgid,msgstr,msgctxt' > "$CSV_FILE" |
| 32 | + echo 'line,msgid' > "$UNTRANSLATED_FILE" |
| 33 | + |
| 34 | + # Initialize variables |
| 35 | + location="" |
| 36 | + msgid="" |
| 37 | + msgstr="" |
| 38 | + msgctxt="" |
| 39 | + line_no=0 |
| 40 | + |
| 41 | + # Function to write to CSV |
| 42 | + write_to_csv() { |
| 43 | + echo "\"$location\",\"$msgid\",\"$msgstr\",\"$msgctxt\"" >> "$CSV_FILE" |
| 44 | + if [[ -z "$msgstr" && -n "$msgid" ]]; then |
| 45 | + echo "$line_no,\"$msgid\"" >> "$UNTRANSLATED_FILE" |
| 46 | + fi |
| 47 | + # Reset variables |
| 48 | + location="" |
| 49 | + msgid="" |
| 50 | + msgstr="" |
| 51 | + msgctxt="" |
| 52 | + } |
| 53 | + |
| 54 | + while IFS= read -r line || [[ -n "$line" ]]; do # also handle the last line |
| 55 | + ((line_no++)) |
| 56 | + |
| 57 | + if [[ "$line" =~ ^\#:\ (.+)$ ]]; then |
| 58 | + location="${BASH_REMATCH[1]}" |
| 59 | + elif [[ "$line" =~ ^msgid\ \"(.*)\"$ ]]; then |
| 60 | + if [[ -n "$msgid" || -n "$msgstr" ]]; then |
| 61 | + write_to_csv |
| 62 | + fi |
| 63 | + msgid="${BASH_REMATCH[1]}" |
| 64 | + elif [[ "$line" =~ ^msgstr\ \"(.*)\"$ ]]; then |
| 65 | + msgstr="${BASH_REMATCH[1]}" |
| 66 | + elif [[ "$line" =~ ^msgctxt\ \"(.+)\"$ ]]; then |
| 67 | + msgctxt="${BASH_REMATCH[1]}" |
| 68 | + fi |
| 69 | + done < "$PO_FILE" |
| 70 | + |
| 71 | + # For the last msgid in the file |
| 72 | + if [[ -n "$msgid" || -n "$msgstr" ]]; then |
| 73 | + write_to_csv |
| 74 | + fi |
| 75 | + |
| 76 | + echo "Created CSV $CSV_FILE and $UNTRANSLATED_FILE for $PO_FILE" |
| 77 | +done |
0 commit comments