Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.8KB

  1. #!/bin/bash
  2. FULLPATH=$(dirname $(readlink -f "$0"))
  3. if [ "$1" == "--help" -o "$1" == "-h" ]
  4. then
  5. echo "$(basename $(readlink -f "$0")) [options]"
  6. echo
  7. echo "-a | --addon <name> extract strings from addon 'name'"
  8. echo "-s | --single single addon mode: extract string from current folder"
  9. exit
  10. fi
  11. MODE='default'
  12. ADDONNAME=
  13. if [ "$1" == "--addon" -o "$1" == "-a" ]
  14. then
  15. MODE='addon'
  16. if [ -z $2 ]; then echo -e "ERROR: missing addon name\n\nrun_xgettext.sh -a <addonname>"; exit 1; fi
  17. ADDONNAME=$2
  18. if [ ! -d "$FULLPATH/../addon/$ADDONNAME" ]; then echo "ERROR: addon '$ADDONNAME' not found"; exit 2; fi
  19. fi
  20. if [ "$1" == "--single" -o "$1" == "-s" ]
  21. then
  22. MODE='single'
  23. fi
  24. case "$MODE" in
  25. 'addon')
  26. cd "$FULLPATH/../addon/$ADDONNAME"
  27. mkdir -p "$FULLPATH/../addon/$ADDONNAME/lang/C"
  28. OUTFILE="$FULLPATH/../addon/$ADDONNAME/lang/C/messages.po"
  29. FINDSTARTDIR="."
  30. FINDOPTS=
  31. ;;
  32. 'single')
  33. FULLPATH=$PWD
  34. ADDONNAME=$(basename $FULLPATH)
  35. mkdir -p "$FULLPATH/lang/C"
  36. OUTFILE="$FULLPATH/lang/C/messages.po"
  37. FINDSTARTDIR="."
  38. FINDOPTS=
  39. echo "Extract strings for single addon '$ADDONNAME'"
  40. ;;
  41. 'default')
  42. cd "$FULLPATH/.."
  43. OUTFILE="$FULLPATH/messages.po"
  44. FINDSTARTDIR="."
  45. # skip addon folder
  46. FINDOPTS="( -wholename */addon -or -wholename */addons-extra -or -wholename */smarty3 ) -prune -o"
  47. F9KVERSION=$(sed -n "s/.*'FRIENDICA_VERSION'.*'\([0-9.]*\)'.*/\1/p" ./boot.php);
  48. echo "Friendica version $F9KVERSION"
  49. ;;
  50. esac
  51. KEYWORDS="-k -kt -ktt:1,2"
  52. echo "extract strings to $OUTFILE.."
  53. rm "$OUTFILE"; touch "$OUTFILE"
  54. for f in $(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
  55. do
  56. if [ ! -d "$f" ]
  57. then
  58. xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$f"
  59. sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
  60. fi
  61. done
  62. echo "setup base info.."
  63. case "$MODE" in
  64. 'addon'|'single')
  65. sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
  66. sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER//g" "$OUTFILE"
  67. sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
  68. sed -i "s/PACKAGE VERSION//g" "$OUTFILE"
  69. sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
  70. sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
  71. sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
  72. ;;
  73. 'default')
  74. sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
  75. sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010, 2011, 2012, 2013 the Friendica Project/g" "$OUTFILE"
  76. sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
  77. sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
  78. sed -i "s/PACKAGE/Friendica/g" "$OUTFILE"
  79. sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
  80. sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
  81. ;;
  82. esac
  83. if [ "" != "$1" -a "$MODE" == "default" ]
  84. then
  85. UPDATEFILE="$(readlink -f ${FULLPATH}/$1)"
  86. echo "merging new strings to $UPDATEFILE.."
  87. msgmerge -U $OUTFILE $UPDATEFILE
  88. fi
  89. echo "done."