1 #!/bin/sh 2 # 3 # This script modifies configure.in, .po files, po/Makefile.in.in and so on 4 # to configure l10n for Sun platforms. '--help' option shows the usage. 5 # 6 # CDDL HEADER START 7 # 8 # The contents of this file are subject to the terms of the 9 # Common Development and Distribution License, Version 1.0 only 10 # (the "License"). You may not use this file except in compliance 11 # with the License. 12 # 13 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 14 # or http://www.opensolaris.org/os/licensing. 15 # See the License for the specific language governing permissions 16 # and limitations under the License. 17 # 18 # When distributing Covered Code, include this CDDL HEADER in each 19 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 20 # If applicable, add the following below this CDDL HEADER, with the 21 # fields enclosed by brackets "[]" replaced with your own identifying 22 # information: Portions Copyright [yyyy] [name of copyright owner] 23 # 24 # CDDL HEADER END 25 # 26 # 27 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 28 # Use is subject to license terms. 29 # 30 31 PROGNAME=`basename $0` 32 PROG_VERSION=1.1 33 SUN_ALL_LINGUAS="cs de es fr hu it ja ko pl pt_BR ru sv zh_CN zh_HK zh_TW" 34 ENABLE_COPYRIGHT=0 35 ENABLE_SUN_ALL_LINGUAS=0 36 DISABLE_GNU_EXTENSIONS=0 37 L10N_POTFILES=${L10N_POTFILES:-"no"} 38 CONFIGURE= 39 SED=/usr/xpg4/bin/sed 40 41 usage () { 42 printf "This script modify ALL_LINGUAS parameter in configure.in file. \n" 43 printf "\n" 44 printf "usage: $PROGNAME Version $PROG_VERSION [OPTION...] \n" 45 printf " -c, --enable-copyright Modify po/Makefile.in.in and gnome-doc-utils.make\n" 46 printf " so that the copyright information is installed\n" 47 printf " from .po files. intltoolize and\n" 48 printf " gnome-doc-prepare need to be run before\n" 49 printf " this script is run if you run them.\n" 50 printf " -l, --enable-sun-linguas Modify ALL_LINGUAS for Sun translations.\n" 51 printf " -p, --enable-pot Generate .pot file for internal. \n" 52 printf " -x, --disable-gnu-extensions Remove GNU extensions in po/*.po files. \n" 53 printf " -h, --help Show this message. \n" 54 printf " -V, --version Show version. \n" 55 } 56 57 check_args_solgetopts () 58 { 59 while [ $# -gt 0 ] 60 do 61 case "$1" in 62 -c|--enable-copyright) 63 ENABLE_COPYRIGHT=1;; 64 -h|--help|--usage) 65 usage 66 exit 0;; 67 -l|--enable-sun-linguas) 68 ENABLE_SUN_ALL_LINGUAS=1;; 69 -p|--enable-pot) 70 L10N_POTFILES="yes";; 71 -V|--version) 72 echo $PROG_VERSION; 73 exit 0;; 74 -x|--disable-gnu-extensions) 75 DISABLE_GNU_EXTENSIONS=1;; 76 *) 77 echo "$PROGNAME: processing error: $1" 1>&2 78 exit 1;; 79 esac 80 shift 81 done 82 } 83 84 init () { 85 # GNU SUNWgnugetopt is not installed on Solaris. 86 check_args_solgetopts $@ 87 88 if [ -f configure.in ] ; then 89 CONFIGURE=configure.in 90 elif [ -f configure.ac ] ; then 91 CONFIGURE=configure.ac 92 fi 93 } 94 95 pre_check () { 96 if [ "$CONFIGURE" = "" -a $ENABLE_SUN_ALL_LINGUAS -eq 1 ] ; then 97 echo "#### Not Found configure.in" 98 exit 0 99 fi 100 101 if [ ! -d po ] ; then 102 echo "#### Not Found po dir" 103 exit 0 104 fi 105 } 106 107 configure_copyright () 108 { 109 DQ='"' 110 DL='$' 111 GA='`' 112 BS='\\\' 113 114 if [ -f .sun-l10n-copyright ] ; then 115 return 0; 116 fi 117 118 if [ -f po/Makefile.in.in ] ; then 119 sed -e "/^install-data-yes: all/a\\ 120 mkdir_p=$DL(mkdir_p); $BS 121 mkdir_p=$DL${DL}{mkdir_p:-${DQ}mkdir -p$DQ}; $BS 122 itlocaledir=$DL(itlocaledir); $BS 123 itlocaledir=$DL${DL}{itlocaledir:-${DL}(gnulocaledir)}; $BS 124 itlocaledir=$DL${DL}{itlocaledir:-${DL}(localedir)}; $BS 125 GETTEXT_PACKAGE=$DL(GETTEXT_PACKAGE); $BS 126 GETTEXT_PACKAGE=$DL${DL}{GETTEXT_PACKAGE:-${DL}(DOMAIN)}; $BS 127 $DL${DL}mkdir_p $DL(DESTDIR)$DL${DL}itlocaledir; $BS 128 catalogs=$DQ$DL(CATALOGS)$DQ; $BS 129 for cat in $DL${DL}catalogs; do $BS 130 cat=${GA}basename $DL${DL}cat$GA; $BS 131 lang=${GA}echo $DL${DL}cat | sed -e 's/${BS}.gmo$DL${DL}//'$GA; $BS 132 dir=$DL(DESTDIR)$DL${DL}itlocaledir/$DL${DL}lang/LC_MESSAGES; $BS 133 $DL${DL}mkdir_p $DL${DL}dir; $BS 134 echo ${DQ}Copyright for $DL${DL}{GETTEXT_PACKAGE}.mo$DQ > $DL${DL}dir/$DL${DL}{GETTEXT_PACKAGE}.ui.copyright; $BS 135 cat $DL${DL}lang.po | while read line; $BS 136 do $BS 137 is_comment=${GA}echo $DL${DL}line | grep '^#' | grep -v '^#,'$GA; $BS 138 if [ x$DQ$DL${DL}is_comment$DQ = x ] ; then $BS 139 break; $BS 140 fi; $BS 141 echo $DQ$DL${DL}line$DQ | sed -e ${DQ}s/^#$BS(.*$BS)/ ${BS}1/$DQ >> $DL${DL}dir/$DL${DL}{GETTEXT_PACKAGE}.ui.copyright; $BS 142 done; $BS 143 echo ${DQ}-------------------------------------------------------------$DQ $BS 144 >> $DL${DL}dir/$DL${DL}{GETTEXT_PACKAGE}.ui.copyright; $BS 145 echo $DQ$DQ >> $DL${DL}dir/$DL${DL}{GETTEXT_PACKAGE}.ui.copyright; $BS 146 echo ${DQ}installing $DL${DL}{GETTEXT_PACKAGE}.ui.copyright in $DL${DL}dir$DQ; $BS 147 done" po/Makefile.in.in >> po/Makefile.in.in.$$ 148 mv po/Makefile.in.in.$$ po/Makefile.in.in 149 fi 150 151 if [ -f gnome-doc-utils.make ] ; then 152 sed -e "/^install-doc-docs:/a\\ 153 @for lc in $DL(_DOC_REAL_LINGUAS); do ${BS} 154 echo $DQ$DL(mkinstalldirs) $DL(DESTDIR)$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc$DQ; ${BS} 155 $DL(mkinstalldirs) $DL(DESTDIR)$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc; ${BS} 156 if test -d $DQ$DL${DL}lc$DQ; then d=; else d=$DQ$DL(srcdir)/$DQ; fi; ${BS} 157 if [ -f $DL${DL}d$DL${DL}lc/$DL${DL}lc.po ] ; then ${BS} 158 echo ${DQ}Copyright for $DL(DOC_MODULE)$DQ >> $DL(DESTDIR)/$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc/$DL(DOC_MODULE).help.copyright; ${BS} 159 cat $DL${DL}d$DL${DL}lc/$DL${DL}lc.po | while read line; ${BS} 160 do ${BS} 161 is_comment=${GA}echo $DL${DL}line | grep '^#' | grep -v '^#,'$GA; ${BS} 162 if [ x$DQ$DL${DL}is_comment$DQ = x ] ; then ${BS} 163 break; ${BS} 164 fi; ${BS} 165 echo $DQ$DL${DL}line$DQ | sed -e ${DQ}s/^#$BS(.*$BS)/ ${BS}1/$DQ >> $DL(DESTDIR)/$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc/$DL(DOC_MODULE).help.copyright; ${BS} 166 done; ${BS} 167 echo ${DQ}-------------------------------------------------------------$DQ ${BS} 168 >> $DL(DESTDIR)/$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc/$DL(DOC_MODULE).help.copyright; ${BS} 169 echo $DQ$DQ >> $DL(DESTDIR)/$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc/$DL(DOC_MODULE).help.copyright; ${BS} 170 echo ${DQ}installing $DL(DOC_MODULE).help.copyright in $DL(DESTDIR)/$DL(HELP_DIR)/$DL(DOC_MODULE)/$DL${DL}lc$DQ; ${BS} 171 fi; ${BS} 172 done" gnome-doc-utils.make > gnome-doc-utils.make.$$ 173 mv gnome-doc-utils.make.$$ gnome-doc-utils.make 174 fi 175 176 touch .sun-l10n-copyright 177 return 0 178 } 179 180 181 # GNU .po has several GNU extensions. 182 # http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html 183 # http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00881.html 184 disable_gnu_extensions () { 185 cd po 186 187 # Replace "%-m" with "%m" for strftime(3C). 188 # Replace "%Id" with "%d" for printf(3C) and don't use "." for the workaround 189 # Replace "%l" with "%I" for strptime(3C) and also grep %M for the workaround 190 # so that we do not change %ld for printf(3C). 191 # Replace "%k" with "%H" for strptime(3C). 192 for po in `egrep -l \ 193 '^msgstr ".*%[_0^-][md].*"|'\ 194 '^msgstr "%I[doxXnfFeEgGaAcspCSm]"|'\ 195 '^msgstr ".*%[_0^-]*l.*%[MpP].*"|'\ 196 '^msgstr ".*%[MpP].*%[_0^-]*l.*"|'\ 197 '^msgstr ".*%[_0^-]*k.*"'\ 198 *.po` 199 do 200 env LANG=C LC_ALL=C \ 201 $SED -e '/^msgstr "/s/%[_0^-]\([md]\)/%\1/g' $po | 202 env LANG=C LC_ALL=C \ 203 $SED -e 's/^\(msgstr "%\)I\([doxXnfFeEgGaAcspCSm]"\)/\1\2/g' | 204 env LANG=C LC_ALL=C \ 205 $SED -e '/^msgstr ".*%[_0^-]*l.*%[MpP]/s/%[_0^-]*l/%I/g' | 206 env LANG=C LC_ALL=C \ 207 $SED -e '/^msgstr ".*%[MpP].*%[_0^-]*l/s/%[_0^-]*l/%I/g' | 208 env LANG=C LC_ALL=C \ 209 $SED -e '/^msgstr "/s/%[_0^-]*k/%H/g' > $po.$$ 210 mv $po.$$ $po 211 done 212 213 # Replace "%Id" with "%d" for printf(3C) forcibly for RTL languages only. 214 for po in `egrep -l \ 215 '%I[doxXnfFeEgGaAcspCSm][^a-zA-Z]'\ 216 ar.po az.po fa.po he.po ur.po yi.po` 217 do 218 env LANG=C LC_ALL=C \ 219 $SED -e 's/\(%\)I\([doxXnfFeEgGaAcspCSm][^a-zA-Z]\)/\1\2/g' $po > $po.$$ 220 mv $po.$$ $po 221 done 222 223 cd .. 224 } 225 226 apply_sun_all_linguas_file () { 227 PO_LINGUAS=`cat po/LINGUAS | grep -v "^#"` 228 PO_LINGUAS=`echo "$PO_LINGUAS $SUN_ALL_LINGUAS"\ 229 | tr " " "\n" \ 230 | env LC_ALL=C LANG=C sort \ 231 | uniq \ 232 | tr "\n" " "` 233 234 SAVE_COMMENT=`grep "^#" po/LINGUAS` 235 echo "$SAVE_COMMENT" > po/LINGUAS 236 echo "$PO_LINGUAS" >> po/LINGUAS 237 } 238 239 apply_sun_all_linguas_configure () { 240 ALL_LINGUAS=`grep '^ALL_LINGUAS=' $CONFIGURE \ 241 | $SED -e 's/ALL_LINGUAS=//' -e 's/"//g'` 242 ALL_LINGUAS=`echo "${ALL_LINGUAS} ${SUN_ALL_LINGUAS}"\ 243 | tr " " "\n" \ 244 | sort \ 245 | uniq \ 246 | tr "\n" " "` 247 248 DQ='"' 249 $SED -e "/^ALL_LINGUAS=/s/^\(ALL_LINGUAS=\)\(.*\)/\1$DQ${ALL_LINGUAS}$DQ/" \ 250 $CONFIGURE > ${CONFIGURE}.chg 251 mv ${CONFIGURE}.chg $CONFIGURE 252 } 253 254 apply_sun_all_linguas () { 255 if [ -f po/LINGUAS ] ; then 256 apply_sun_all_linguas_file 257 else 258 apply_sun_all_linguas_configure 259 fi 260 } 261 262 update_po () { 263 PO_DIRS=po*/POTFILES.in 264 PO_DIRS=`echo $PO_DIRS | $SED -e 's|/POTFILES.in||g'` 265 266 for po in $PO_DIRS 267 do 268 # 269 # This is needed to avoid build errors. 270 # 271 (cd $po; touch `echo "$SUN_ALL_LINGUAS" | $SED -e 's/\([a-z_A-Z][a-z_A-Z]*\)/\1.po/g'`) 272 done 273 } 274 275 update_pot () { 276 OS=`uname -s` 277 if [ "$OS" = Linux ] ; then 278 TOPDIR=/usr/src/packages 279 else 280 TOPDIR=/jds/packages 281 fi 282 POT_DATA='"POT-Creation-Date: ' 283 284 cd po 285 rm -f *.pot 286 echo "[encoding: UTF-8]" > POTFILES.in 287 intltool-update --maintain 2>/dev/null 288 cat missing >> POTFILES.in 289 intltool-update --pot 290 POT=`ls *.pot` 291 if [ "x$POT" != "x" ] ; then 292 $SED -e "/^$POT_DATA/d" $POT > ${POT}.$$ 293 mv ${POT}.$$ $POT 294 mkdir -p $TOPDIR/l10n/pot 295 mkdir -p $TOPDIR/l10n/diff 296 mkdir -p $TOPDIR/l10n/new 297 if [ -f $TOPDIR/l10n/pot/$POT ] ; then 298 diff $TOPDIR/l10n/pot/$POT $POT > ${POT}.diff 299 if [ -s ${POT}.diff ] ; then 300 cp ${POT}.diff $TOPDIR/l10n/diff 301 echo "#### Translation should be updated!!!" 302 fi 303 else 304 cp $POT $TOPDIR/l10n/pot 305 cp $POT $TOPDIR/l10n/new 306 fi 307 else 308 echo "#### Failed to create the potfile in `pwd`" 309 fi 310 cd .. 311 } 312 313 main () { 314 init $@ 315 pre_check 316 317 if [ $DISABLE_GNU_EXTENSIONS -eq 1 ] ; then 318 disable_gnu_extensions 319 fi 320 if [ $ENABLE_SUN_ALL_LINGUAS -eq 1 ] ; then 321 apply_sun_all_linguas 322 update_po 323 fi 324 if [ $ENABLE_COPYRIGHT -eq 1 ] ; then 325 configure_copyright 326 fi 327 if [ "x$L10N_POTFILES" = "xyes" ] ; then 328 update_pot 329 fi 330 } 331 332 main $@ 333