updated xmail po-deconf translation
[debian-ro-repo.git] / _bin / polibs
blob804859353465db9a392d9a363900ddcb5715c8cc
1 #!/bin/sh
3 msg ()
5 echo "$@"
8 emsg ()
10 msg "E: $@" >&2
13 wmsg ()
15 msg "W: $@" >&2
18 po_rearrange ()
20 if [ "$1" ] && [ ! -f "$1" ] ; then
21 msg "No input file or file doesn't exist."
22 return 1
25 msgcat --width=79 "$1" | sponge "$1"
28 po_merge ()
30 local XPARAMS=""
31 if [ "$HAS_COMPENDIUM" = "1" ] && [ "$COMPENDIUM" ]; then
32 XPARAMS="-C $COMPENDIUM"
34 BACKUP_FILE="$1.premerge"
35 if [ -f "$BACKUP_FILE" ] ; then
36 msg "backup file $BACKUP_FILE exists. Can not do a safe merge. Quitting."
37 return 1
39 cp -a "$1" "$BACKUP_FILE"
40 msg "Merging '$1' with '$2'"
41 msgmerge -U $XPARAMS "$1" "$2"
42 po_rearrange "$1"
45 find_compendium ()
47 if [ -f _data/compendium.po ] ; then
48 export HAS_COMPENDIUM=1
49 export COMPENDIUM="$(pwd)/_data/compendium.po"
50 else
51 export HAS_COMPENDIUM=0
52 export COMPENDIUM=""
56 fetch_compendium ()
58 local COMPENDIUM_URL="http://i18n.debian.net/debian-l10n/compendia/po/$POLANG/compendium-$POLANG-LATEST.po"
60 mkdir -p _data
61 wget -q -O "$(pwd)/_data/compendium.po" "$COMPENDIUM_URL"
64 po_config ()
66 unset POURL PACKAGE PODIR_URL SUBDIR SECTION BASE_MATERIAL_URL PO_LOCAL_FILE
68 [ -x "$POCONF" ] && . "$POCONF" || :
70 if [ -z "$PODIR_URL" ] ; then
72 if [ -z "$PACKAGE" ] ; then
73 PACKAGE="$(pwd)"
74 PACKAGE=${PACKAGE##*/}
77 if [ -z "$SUBDIR" ] ; then
78 SUBDIR=${PACKAGE:0:4}
79 [ "${SUBDIR:0:3}" = "lib" ] || SUBDIR=${SUBDIR:0:1}
82 if [ -z "$BASE_MATERIAL_URL" ] ; then
83 BASE_MATERIAL_URL=${BASE_MATERIAL_URL-'http://i18n.debian.net/material'}
86 SECTION=main #assume main; for contrib and non-free there should be conf files
88 if [ -z "$PODIR_URL" ] ; then
89 PODIR_URL="$BASE_MATERIAL_URL/po/unstable/$SECTION/$SUBDIR/$PACKAGE/debian/po"
92 if [ -z "$PO_LOCAL_FILE" ] ; then
93 PO_LOCAL_FILE="$POLANG.po"
99 get_gz_pot_filename ()
101 links2 -dump "$1" | grep -o -E "$2_[^_]*_templates\.pot\.gz"
104 get_gz_po_filename ()
106 links2 -dump "$1" | grep -o -E "$2_[^_]*_$3\.po\.gz"
109 gen_poconf ()
111 cat >$POCONF <<EOCONF
112 PACKAGE="$PACKAGE"
113 PODIR_URL="$PODIR_URL"
114 BASE_MATERIAL_URL="$BASE_MATERIAL_URL"
115 SUBDIR="$SUBDIR"
116 PO_LOCAL_FILE="$PO_LOCAL_FILE"
117 EOCONF
120 # get the config status.
121 # returns:
122 # - 0 if configured
123 # - 1 if not configured
124 # - 2 if po not present
125 # An optional parameter specifying the subdirectory can be added
126 po_get_config_status ()
128 local PODIR
129 [ $# -ge 1 ] && PODIR="$1" || PODIR="."
130 if [ -f "$PODIR/$POLANG.po" ] ; then
131 [ -f "$PODIR/$POCONF" ] && return 0 || return 1
132 else
133 return 2
137 po_check_possible_vcs_po ()
139 po_get_config_status ; POCFGST=$?
140 if [ $POCFGST -eq 1 ] ; then
141 emsg "A translation file is present, but it's origin isn't declared via the '$POCONF' file."
142 emsg "Please create an adequate '$POCONF' file to prevent breakage or losing translations."
143 emsg " NOTE: Normally this operation should be done automatically or by the coordinator."
144 elif [ $POCFGST -eq 2 ] ; then
145 emsg "No translation file found."
147 return $POCFGST
151 po_refresh ()
153 po_check_possible_vcs_po || return 1
154 po_config
156 GZ_PO_FILENAME="$(get_gz_po_filename "$PODIR_URL" "$PACKAGE" "$POLANG")"
157 if [ -z "$GZ_PO_FILENAME" ] ; then
158 emsg "It seems there is no official $POLANG translation for the package $PACKAGE."
159 emsg "Maybe the config file ($POCONF) is broken, incorrect or absent?"
160 #emsg "Please run po_new_translation to configure this translation."
161 return 1
164 REMOTE_GZ_URL="$PODIR_URL/$GZ_PO_FILENAME"
165 wget -q "$REMOTE_GZ_URL" -O - | gunzip > "$PO_LOCAL_FILE.remote"
167 if [ ! -f "$PO_LOCAL_FILE" ] ; then
168 mv "$PO_LOCAL_FILE.remote" "$PO_LOCAL_FILE"
169 msg "No local file was present."
170 msg "Brought in $PO_LOCAL_FILE from $REMOTE_GZ_URL"
172 if [ ! -f "$POCONF" ] ; then
173 gen_poconf
174 msg "Config file generated"
176 return 0
177 else
178 po_merge "$PO_LOCAL_FILE" "$PO_LOCAL_FILE.remote"
182 check_command ()
184 if [ ! -x $(command -v $1) ] ; then
185 msg "You do not have the $1 utility. Please install $2."
186 return 1
190 po_make_disambiguated_copy ()
192 po_config
194 if [ -e "$PO_LOCAL_FILE" ]
195 then
196 if [ "$PO_LOCAL_FILE" != "$PACKAGE.po" ] ; then
197 cp "$PO_LOCAL_FILE" "$PACKAGE.po"
198 echo "Translation disambiguated as '$PACKAGE.po'. Please remove it after sending it."
199 rerun 0
200 else
201 echo "File is already disambiguated an is the local .po file '$PACKAGE.po'."
202 echo " !!! DO NOT REMOVE IT AFTER SENDING IT !!!"
203 return 0
205 else
206 echo "No local file to disambiguate, please run po_refresh to grab the file or"
207 echo "contact the language coordinator for an update."
208 return 1
212 export POLANG=ro
213 export POCONF=".poconf"
215 check_command sponge moreutils
216 check_command wget wget
217 check_command msgmerge gettext
218 check_command msgcat gettext
219 check_command links2 links2
222 # vi:ts=4:sw=4:noet