diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-05-31 11:54:18 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-05-31 13:37:23 -0600 |
commit | be93a5e25a80b99a00b37334e85d7d815b0b880b (patch) | |
tree | 19ae4543a16950cd96fe60412f206b9e5c503d27 /src | |
parent | 238d56a8dc7614813af3ed36bc6e5c51a6290c15 (diff) |
librexgettext: Support all of the recent changes to libremessages:flag.
Diffstat (limited to 'src')
-rwxr-xr-x | src/lib/librexgettext | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/src/lib/librexgettext b/src/lib/librexgettext index aad79fa..17345cb 100755 --- a/src/lib/librexgettext +++ b/src/lib/librexgettext @@ -25,7 +25,7 @@ default_simple=( --keyword={msg,msg2,warning,error,stat_busy,die} --keyword={lock,slock}:3 ) -default_prose=(--keyword={prose,bullet,flag:2}) +default_prose=(--keyword={prose,bullet}) readonly default_simple default_prose @@ -63,6 +63,61 @@ xgettext-sh() { xgettext --omit-header --from-code=UTF-8 -L shell -k -o - "$@" } +xgettext-flag() { + { + declare -i x=0 + declare -i i + for (( i=1; x < 3; i++ )); do + local out + out="$(xgettext-sh --keyword="flag:$i,\"$i\"" "$@")" + if [[ -n $out ]]; then + printf -- '%s\n' "$out" + else + x+=1 + fi + done + } | whitespace-collapse | sed '/^\#, sh-format/d' | { + declare -i i + + IFS='' + local segments=() + local re='^#\. ([0-9]+)$' + local line + while read -r line; do + if [[ $line =~ $re ]]; then + i=${BASH_REMATCH[1]} + else + segments[$i]+="$line"$'\n' + fi + done + + declare -i last=$(printf '%s\n' "${!segments[@]}"|sed -n '$p') + + IFS=$'\n' + local flag=true + for (( i=1; i <= last; i++ )); do + if $flag; then + local lines=(${segments[$i]}) + if [[ ${lines[1]} == *':"' ]]; then + printf -- '%s\n' "${segments[$i]}" + else + flag=false + fi + else + if [[ -n ${segments[$i]} ]]; then + printf -- '%s\n' "${segments[$i]}" + fi + flag=true + fi + done + } +} + +whitespace-collapse() { + tr '\n' '\r' | sed 's/"\r\s*"//g' | tr '\r' '\n' | # This removes the awkward word-wrapping done by xgettext + sed -r -e 's/(\\n|\\t|\t)/ /g' -e 's/(^|[^.!? ]) +/\1 /g' -e 's/([.!?]) +/\1 /g' # This collapses whitespace +} + main() { local simple=() local prose=() @@ -100,11 +155,9 @@ main() { # Main code { xgettext-sh "${simple[@]}" -- "${files[@]}" - xgettext-sh "${prose[@]}" -- "${files[@]}" | # These are the raw strings given to prose functions - tr '\n' '\r' | sed 's/"\r\s*"//g' | tr '\r' '\n' | # This removes the awkward word-wrapping done by xgettext - sed -r -e 's/(\\n|\\t|\t)/ /g' -e 's/(^|[^.!? ]) +/\1 /g' -e 's/([.!?]) +/\1 /g' | # This collapses whitespace - sed '/^\#, sh-format/d' - } | msguniq -Fi + xgettext-sh "${prose[@]}" -- "${files[@]}" | whitespace-collapse + xgettext-flag -- "${files[@]}" + } | sed '/^\#, sh-format/d' | msguniq -Fi } main "$@" |