1# xopen-msg.awk - Convert Uniforum style .po file to X/Open style .msg file 2# Copyright (C) 2012-2022 Free Software Foundation, Inc. 3# 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 2, or (at your option) 7# any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, see <https://www.gnu.org/licenses/>. 16# 17# 18# The first directive in the .msg should be the definition of the 19# message set number. We use always set number 1. 20# 21BEGIN { 22 print "$set 1 # Automatically created by xopen-msg.awk" 23 num = 0 24} 25 26# 27# The .msg file contains, other then the .po file, only the translations 28# but each given a unique ID. Starting from 1 and incrementing by 1 for 29# each message we assign them to the messages. 30# It is important that the .po file used to generate the ../intl/msg.h file 31# (with po2test.awk) is the same as the one used here. (At least the order 32# of declarations must not be changed.) 33# 34function output_message() { 35 # Ignore messages containing <PRI.*> which would have to be replaced 36 # by the correct format depending on the word size 37 if (msg && msg !~ /<PRI.*>/) { 38 if (msgtype == "msgid") { 39 # We copy the original message as a comment into the .msg file. 40 gsub(/\n/, "\n$ ", msg) 41 printf "$ Original Message: %s\n", msg 42 } else { 43 gsub(/\n/, "\\\n", msg) 44 printf "%d %s\n", ++num, msg 45 } 46 } 47 msg = 0 48} 49 50$1 ~ "msg(id|str)" { 51 # Output collected message 52 output_message() 53 # Collect next message 54 msgtype = $1 55 sub(/^msg(id|str)[ \t]*"/, "", $0) 56 sub(/"$/, "", $0) 57 msg = $0 58 next 59} 60 61/^"POT-Creation-Date: [0-9-]+ [0-9:+-]+\\n"/ { 62 # Ignore POT-Creation-Date to match what is done in intl/Makefile. 63 next 64} 65 66/^".*"/ { 67 # Append to current message 68 sub(/^"/, "", $0) 69 sub(/"$/, "", $0) 70 msg = msg "\n" $0 71 next 72} 73 74END { 75 # Output last collected message 76 output_message() 77} 78