i18n-compile.tcl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env tclsh
  2. #
  3. # Compile messages (msg files) from translation files (po files).
  4. #
  5. # Copyright 2015-2017 OpenIndex.de.
  6. # Distributed under the MIT License.
  7. # See accompanying LICENSE.txt file or at http://opensource.org/licenses/MIT
  8. #
  9. # initialization
  10. source [file join [file normalize [file dirname $argv0]] init.tcl]
  11. puts ""
  12. puts "========================================================================="
  13. puts " $PROJECT $VERSION: compile translations"
  14. puts "========================================================================="
  15. puts ""
  16. if {$MSGFMT == "" || ![file isfile $MSGFMT] || ![file executable $MSGFMT]} {
  17. puts "ERROR: Can't find the msgfmt application!"
  18. exit 1
  19. }
  20. # Remove old translation files.
  21. foreach msg [glob -nocomplain -directory $SRC_MSGS_DIR -type f "*.msg"] {
  22. puts "remove $msg"
  23. file delete $msg
  24. }
  25. # Build new translation files.
  26. foreach po [glob -nocomplain -directory $I18N_PO_DIR -type f "*.po"] {
  27. puts "compile $po"
  28. set name [file tail $po]
  29. set pos [string last "." $name]
  30. if {$pos<1} {
  31. puts "ERROR: invalid translation file at $po"
  32. }
  33. set lang [string range $name 0 [expr {$pos - 1}]]
  34. set msg [file join $SRC_MSGS_DIR [concat $name ".msg"]]
  35. if { [catch {exec $MSGFMT --tcl [file nativename $po] -l $lang -d [file nativename $SRC_MSGS_DIR]} result] } {
  36. puts "ERROR: Can't compile translation!"
  37. puts "at: $po"
  38. puts $::errorInfo
  39. }
  40. }