gibberize.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. #
  3. # generates gibberish locale for i18n testing
  4. #
  5. # @author Christopher Han <xiphux@gmail.com>
  6. # @copyright Copyright (c) 2012 Christopher Han
  7. # @package GitPHP
  8. # @subpackage Util
  9. #
  10. LOCALESRC="locale/gitphp.pot"
  11. ZZDIR="locale/zz_Debug"
  12. ZZPO="${ZZDIR}/gitphp.po"
  13. if [ -e "${ZZPO}" ]; then
  14. rm "${ZZPO}"
  15. fi
  16. mkdir -p "${ZZDIR}"
  17. cat "${LOCALESRC}" | \
  18. while read -r LINE; do
  19. if [[ $LINE == '# SOME DESCRIPTIVE TITLE'* ]]; then
  20. echo "# GitPHP" >> "${ZZPO}"
  21. continue
  22. fi
  23. if [[ $LINE == '# Copyright'* ]]; then
  24. echo "# Copyright (C) 2012 Christopher Han" >> "${ZZPO}"
  25. continue
  26. fi
  27. if [[ $LINE == '# This file is distributed'* ]]; then
  28. echo "# This file is distributed under the same license as the GitPHP package." >> "${ZZPO}"
  29. continue
  30. fi
  31. if [[ $LINE == '# FIRST AUTHOR'* ]]; then
  32. echo "# Christopher Han <xiphux@gmail.com>, 2012." >> "${ZZPO}"
  33. continue
  34. fi
  35. if [[ $LINE == '#, fuzzy'* ]]; then
  36. continue
  37. fi
  38. if [[ $LINE == '"PO-Revision-Date:'* ]]; then
  39. echo "\"PO-Revision-Date: `date +\"%Y-%m-%d %H:%M%z\"`\n\"" >> "${ZZPO}"
  40. HEADER=1
  41. continue
  42. fi
  43. if [[ $LINE == '"Last-Translator:'* ]]; then
  44. echo "\"Last-Translator: Christopher Han <xiphux@gmail.com>\n\"" >> "${ZZPO}"
  45. HEADER=1
  46. continue
  47. fi
  48. if [[ $LINE == '"Language-Team:'* ]]; then
  49. echo "\"Language-Team: Christopher Han <xiphux@gmail.com>\n\"" >> "${ZZPO}"
  50. HEADER=1
  51. continue
  52. fi
  53. if [[ $LINE == '"Language:'* ]]; then
  54. echo "\"Language: Gibberish\n\"" >> "${ZZPO}"
  55. HEADER=1
  56. continue
  57. fi
  58. if [[ $LINE == '"Plural-Forms:'* ]]; then
  59. echo "\"Plural-Forms: nplurals=2; plural=n != 1;\n\"" >> "${ZZPO}"
  60. HEADER=1
  61. continue
  62. fi
  63. if [[ $LINE == 'msgid '* ]]; then
  64. if [[ $HEADER != 1 ]]; then
  65. echo "${LINE}" >> "${ZZPO}"
  66. continue
  67. fi
  68. MSG="${LINE}"
  69. while read -r LINE; do
  70. if [[ "$LINE" == "" ]] || [[ "$LINE" == '#'* ]]; then
  71. break
  72. fi
  73. if [[ ! "$LINE" == 'msgstr'* ]]; then
  74. MSG="${MSG}\n${LINE}"
  75. fi
  76. done
  77. echo -e "${MSG}" >> "${ZZPO}"
  78. MSGSTR="$MSG"
  79. if [[ "${MSG}" == *'msgid_plural'* ]]; then
  80. MSGSTR="${MSGSTR/msgid_plural/msgstr[1]}"
  81. MSGSTR="${MSGSTR/msgid/msgstr[0]}"
  82. else
  83. MSGSTR="${MSGSTR/msgid/msgstr}"
  84. fi
  85. echo -e "${MSGSTR}" | \
  86. while read -r LINE2; do
  87. PREFIX="`echo "${LINE2}" | sed -e 's/".*//'`"
  88. STRING="`echo "${LINE2}" | sed -e 's/^[^"]*"//' | sed -e 's/"$//'`"
  89. if [[ "${STRING}" == "English" ]]; then
  90. # special locale name token
  91. STRING="Gibberish"
  92. elif [[ ! "${STRING}" == "" ]]; then
  93. # pad string 30% to account for longer languages
  94. STRPADDING=$((${#STRING}*30/100))
  95. STRPADDING=$((${STRPADDING}+1)) # because of integer truncation
  96. for ((i=1; i <= STRPADDING; i++)); do
  97. STRING="${STRING}•"
  98. done
  99. # add non-english characters
  100. STRING="${STRING//a/â}"
  101. STRING="${STRING//e/ȩ}"
  102. STRING="${STRING//i/ȉ}"
  103. STRING="${STRING//o/ø}"
  104. STRING="${STRING//u/ü}"
  105. STRING="${STRING//A/Å}"
  106. STRING="${STRING//E/Ȅ}"
  107. STRING="${STRING//I/Ĭ}"
  108. STRING="${STRING//O/Ɵ}"
  109. STRING="${STRING//U/Ṳ}"
  110. # flag inserted tokens with asterisks
  111. STRING="`echo "${STRING/\$/\\\$}" | sed -e 's/\(%[1-9]\(\$[a-z]\)\?\)/\*\1\*/g'`"
  112. # add boundary markers
  113. STRING="{${STRING}}"
  114. fi
  115. echo "${PREFIX}\"${STRING}\"" >> "${ZZPO}"
  116. done
  117. fi
  118. echo "${LINE}" >> "${ZZPO}"
  119. done