1#!/bin/sh 2# potomo - Convert a .po file to an utf-8 encoded .mo file. 3# Copyright 2008 g10 Code GmbH 4# Copyright 2010 Free Software Foundation, Inc. 5# 6# This file is free software; as a special exception the author gives 7# unlimited permission to copy and/or distribute it, with or without 8# modifications, as long as this notice is preserved. 9# 10# This file is distributed in the hope that it will be useful, but 11# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 12# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 14# This script is used to create the mo files for applications using 15# the simple gettext implementation provided by libgpg-error. That 16# gettext can only cope with utf-8 encoded mo files; thus we make this 17# sure while creating the mo. A conversion is not done if the source 18# file does not exist or if it is not newer than the mo file. 19 20if [ "$1" = "--get-linguas" -a $# -eq 2 ]; then 21 if [ ! -f "$2/LINGUAS" ]; then 22 echo "potomo: directory '$2' has no LINGUAS file" >&2 23 exit 1 24 fi 25 echo $(sed -e "/^#/d" -e "s/#.*//" "$2"/LINGUAS) 26 exit 0 27fi 28 29if [ $# -ne 2 ]; then 30 echo "usage: potomo INFILE.PO OUTFILE.MO" >&2 31 echo " potomo --get-linguas DIR" >&2 32 exit 1 33fi 34infile="$1" 35outfile="$2" 36 37if [ ! -f "$infile" ]; then 38 echo "potomo: '$infile' not found - ignored" 2>&1 39 exit 0 40fi 41 42if [ "$outfile" -nt "$infile" ]; then 43 echo "potomo: '$outfile' is newer than source - keeping" 2>&1 44 exit 0 45fi 46 47# Note that we could use the newer msgconv. However this tool was not 48# widely available back in 2008. 49 50fromset=`sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' \ 51 "$infile"` 52 53case "$fromset" in 54 utf8|utf-8|UTF8|UTF-8) 55 echo "potomo: '$infile' keeping $fromset" >&2 56 msgfmt --output-file="$outfile" "$infile" 57 ;; 58 *) 59 echo "potomo: '$infile' converting from $fromset to utf-8" >&2 60 iconv --silent --from-code=$fromset --to-code=utf-8 < "$infile" |\ 61 sed "/^\"Content-Type:/ s/charset=[a-zA-Z0-9_-]*/charset=utf-8/"|\ 62 msgfmt --output-file="$outfile" - 63 ;; 64esac 65