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.
 
 
 
 
 
 

112 lines
3.0 KiB

  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="-path ./vendor -prune -or"
  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="-path ./vendor -prune -or"
  39. echo "Extract strings for single addon '$ADDONNAME'"
  40. ;;
  41. 'default')
  42. cd "$FULLPATH/.."
  43. OUTFILE="$FULLPATH/../view/lang/C/messages.po"
  44. FINDSTARTDIR="."
  45. # skip addon folder
  46. FINDOPTS="( -path ./addon -or -path ./addons -or -path ./addons-extra -or -path ./tests -or -path ./view/lang -or -path ./view/smarty3 -or -path ./vendor ) -prune -or"
  47. F9KVERSION=$(cat ./VERSION);
  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. find_result=$(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f)
  55. total_files=$(wc -l <<< "${find_result}")
  56. for file in $find_result
  57. do
  58. ((count++))
  59. echo -ne " \r"
  60. echo -ne "Reading file $count/$total_files..."
  61. # On Windows, find still outputs the name of pruned folders
  62. if [ ! -d "$file" ]
  63. then
  64. xgettext $KEYWORDS -j -o "$OUTFILE" --from-code=UTF-8 "$file" || exit 1
  65. sed -i "s/CHARSET/UTF-8/g" "$OUTFILE"
  66. fi
  67. done
  68. echo -ne "\n"
  69. echo "Interpolate metadata.."
  70. sed -i "s/^\"Plural-Forms.*$//g" "$OUTFILE"
  71. case "$MODE" in
  72. 'addon'|'single')
  73. sed -i "s/SOME DESCRIPTIVE TITLE./ADDON $ADDONNAME/g" "$OUTFILE"
  74. sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER//g" "$OUTFILE"
  75. sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.//g" "$OUTFILE"
  76. sed -i "s/PACKAGE VERSION//g" "$OUTFILE"
  77. sed -i "s/PACKAGE/Friendica $ADDONNAME addon/g" "$OUTFILE"
  78. ;;
  79. 'default')
  80. sed -i "s/SOME DESCRIPTIVE TITLE./FRIENDICA Distributed Social Network/g" "$OUTFILE"
  81. sed -i "s/YEAR THE PACKAGE'S COPYRIGHT HOLDER/2010-$(date +%Y) the Friendica Project/g" "$OUTFILE"
  82. sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Mike Macgirvin, 2010/g" "$OUTFILE"
  83. sed -i "s/PACKAGE VERSION/$F9KVERSION/g" "$OUTFILE"
  84. sed -i "s/PACKAGE/Friendica/g" "$OUTFILE"
  85. ;;
  86. esac
  87. if [ "" != "$1" -a "$MODE" == "default" ]
  88. then
  89. UPDATEFILE="$(readlink -f ${FULLPATH}/$1)"
  90. echo "Merging new strings to $UPDATEFILE.."
  91. msgmerge -U $OUTFILE $UPDATEFILE
  92. fi
  93. echo "Done."