xopen-msg.awk 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # xopen-msg.awk - Convert Uniforum style .po file to X/Open style .msg file
  2. # Copyright (C) 2012-2026 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. #
  21. BEGIN {
  22. print "$set 1 # Automatically created by xopen-msg.awk"
  23. num = 0
  24. }
  25. #
  26. # The .msg file contains, other then the .po file, only the translations
  27. # but each given a unique ID. Starting from 1 and incrementing by 1 for
  28. # each message we assign them to the messages.
  29. # It is important that the .po file used to generate the ../intl/msg.h file
  30. # (with po2test.awk) is the same as the one used here. (At least the order
  31. # of declarations must not be changed.)
  32. #
  33. function output_message() {
  34. # Ignore messages containing <PRI.*> which would have to be replaced
  35. # by the correct format depending on the word size
  36. if (msg && msg !~ /<PRI.*>/) {
  37. if (msgtype == "msgid") {
  38. # We copy the original message as a comment into the .msg file.
  39. gsub(/\n/, "\n$ ", msg)
  40. printf "$ Original Message: %s\n", msg
  41. } else {
  42. gsub(/\n/, "\\\n", msg)
  43. printf "%d %s\n", ++num, msg
  44. }
  45. }
  46. msg = 0
  47. }
  48. $1 ~ "msg(id|str)" {
  49. # Output collected message
  50. output_message()
  51. # Collect next message
  52. msgtype = $1
  53. sub(/^msg(id|str)[ \t]*"/, "", $0)
  54. sub(/"$/, "", $0)
  55. msg = $0
  56. next
  57. }
  58. /^"POT-Creation-Date: [0-9-]+ [0-9:+-]+\\n"/ {
  59. # Ignore POT-Creation-Date to match what is done in intl/Makefile.
  60. next
  61. }
  62. /^".*"/ {
  63. # Append to current message
  64. sub(/^"/, "", $0)
  65. sub(/"$/, "", $0)
  66. msg = msg "\n" $0
  67. next
  68. }
  69. END {
  70. # Output last collected message
  71. output_message()
  72. }