LanguageJa.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Japanese (日本語) specific code.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Language
  22. */
  23. /**
  24. * Japanese (日本語)
  25. *
  26. * @ingroup Language
  27. */
  28. class LanguageJa extends Language {
  29. /**
  30. * @param string $string
  31. * @return string
  32. */
  33. function segmentByWord( $string ) {
  34. // Strip known punctuation ?
  35. // $s = preg_replace( '/\xe3\x80[\x80-\xbf]/', '', $s ); # U3000-303f
  36. // Space strings of like hiragana/katakana/kanji
  37. $hiragana = '(?:\xe3(?:\x81[\x80-\xbf]|\x82[\x80-\x9f]))'; # U3040-309f
  38. $katakana = '(?:\xe3(?:\x82[\xa0-\xbf]|\x83[\x80-\xbf]))'; # U30a0-30ff
  39. $kanji = '(?:\xe3[\x88-\xbf][\x80-\xbf]'
  40. . '|[\xe4-\xe8][\x80-\xbf]{2}'
  41. . '|\xe9[\x80-\xa5][\x80-\xbf]'
  42. . '|\xe9\xa6[\x80-\x99])';
  43. # U3200-9999 = \xe3\x88\x80-\xe9\xa6\x99
  44. $reg = "/({$hiragana}+|{$katakana}+|{$kanji}+)/";
  45. $s = self::insertSpace( $string, $reg );
  46. return $s;
  47. }
  48. /**
  49. * Italic is not appropriate for Japanese script
  50. * Unfortunately most browsers do not recognise this, and render `<em>` as italic
  51. *
  52. * @param string $text
  53. * @return string
  54. */
  55. function emphasize( $text ) {
  56. return $text;
  57. }
  58. }