forked from mollie/WooCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-to-po.sh
More file actions
executable file
·30 lines (24 loc) · 839 Bytes
/
csv-to-po.sh
File metadata and controls
executable file
·30 lines (24 loc) · 839 Bytes
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
#!/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