cvs: peardoc /scripts make-chm.php

From: Date: Sat, 29 Jul 2006 06:12:02 +0000
Subject: cvs: peardoc /scripts make-chm.php
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-8182@lists.php.net to get a copy of this message
takagi Sat Jul 29 06:12:02 2006 UTC Modified files: /peardoc/scripts make-chm.php Log: - convert Japanese CHM files to Shift_JIS, because MS HtmlHelp compiler doesn't know anything about UTF-8 http://cvs.php.net/viewvc.cgi/peardoc/scripts/make-chm.php?r1=1.7&r2=1.8&diff_format=u Index: peardoc/scripts/make-chm.php diff -u peardoc/scripts/make-chm.php:1.7 peardoc/scripts/make-chm.php:1.8 --- peardoc/scripts/make-chm.php:1.7 Thu Dec 8 22:05:44 2005 +++ peardoc/scripts/make-chm.php Sat Jul 29 06:12:01 2006 @@ -18,7 +18,7 @@ | Mark Wiesemann <wiesemann@php.net> | +----------------------------------------------------------------------+ - $Id: make-chm.php,v 1.7 2005/12/08 22:05:44 techtonik Exp $ + $Id: make-chm.php,v 1.8 2006/07/29 06:12:01 takagi Exp $ */ /** @@ -42,6 +42,10 @@ * - iconv extension is required to build russian version of CHM. * MS HtmlHelp doesn't support russian KOI8-R encoding in CHM index * and ToC, so pages should be converted to windows-1251 + * - either mbstring extension or iconv extension is required + * to build Japanese version of CHM. + * MS HtmlHelp doesn't support UTF-8 encoding in CHM index + * and ToC, so pages should be converted to Shift_JIS */ // Note: File_SearchReplace >= 1.1.0 is needed @@ -60,6 +64,12 @@ if ($lang === 'ru' && !function_exists('iconv')) { die("Error: Iconv is required to produce russian version of manual"); } +// ja: +if ($lang === 'ja') { + if (!function_exists('mb_convert_encoding') && !function_exists('iconv')) { + die("Error: Either iconv or mbstring is required to produce japanese version of manual"); + } +} $ind = "$cwd/../html"; // source directory $chmd = "$cwd/../chm"; // path for HH project files (autopurged) @@ -235,6 +245,12 @@ $replace[] = 'text/html; charset=windows-1251'; // look conversion code is at the end of this script } +// ja: +if ($lang === 'ja') { + $find_rx[] = '|text/html; charset=UTF-8|ims'; + $replace[] = 'text/html; charset=Shift_JIS'; + // look conversion code is at the end of this script +} $sr = &new File_SearchReplace( $find_rx, @@ -538,6 +554,25 @@ fclose($fp); } } +// ja: MS HtmlHelp engine support only Shift_JIS japanese encoding in ToC and index +if ($lang === 'ja') { + echo "\nJapanese CHM must be converted to Shift_JIS. Processing... "; + $thtmlfiles = array_merge( + glob("$chmd/$pref.hh[kc]"), + glob("$outd/*.html") + ); + foreach ($thtmlfiles as $f) { + $fcontents = file_get_contents($f); + if (function_exists('mb_convert_encoding')) { + $converted = mb_convert_encoding($fcontents, 'sjis', 'utf-8'); + } else if (function_exists('iconv')) { + $converted = iconv('utf-8', 'sjis', $fcontents); + } + $fp = fopen($f,"w"); + fwrite($fp, $converted); + fclose($fp); + } +} echo "Done.\n"; echo "\nNow you can follow into \"$chmd\" directory and launch MS HTMLHELP compiler to build CHM";

« previous php.pear.doc (#8182) next »