#!/usr/bin/env sh
#
# ===================================
# %s/""$\n\|"$\n^"\|$\n^$\|^#.*$\n//g
# ===================================
# 1. s/""$\n//g 删除空字符串
# 2. s/"$\n^"//g 多行合并为一行
# 3. s/$\n^$//g 删除空行
# 4. s/^#.*$//g 删除注释
#
# =================
# %g/^msgstr/-1join
# =================
# 合并 msgid 和 msgstr 到一行
#
# ====================================================
# %s/^msgid "\(.\+\)" msgstr "\?\([^"]*\)"\?$/\1\t\2/g
# ====================================================
# 用制表符 <TAB> 格式化,并删除字符串前后的双引号
#
# =======================================================
# 1s/^msgid msgstr ".*$/msgid\tmsgstr\tmsgstr in french /
# =======================================================
# 更新第一行,作为标题栏
#
# ===========
# U s e a g e
# ===========
# $ chmod u+x po2xls
# $ po2xls *.po
#
for file in "$@"; do
vim -E -s ${file} <<-EOF
%s/""$\n\|"$\n^"\|$\n^$\|^#.*$\n//g
%g/^msgstr/-1join
%s/^msgid "\(.\+\)" msgstr "\?\([^"]*\)"\?$/\1\t\2/g
1s/^msgid msgstr ".*$/msgid\tmsgstr\tmsgstr in french /
wq! %:r.tsv
EOF
done