[Codeigniter-users] ユーザガイド Sphinx への移行について

Back to archive index

Fumito Mizuno ounzi****@gmail*****
2011年 10月 7日 (金) 07:20:17 JST


水野です。

説明不足ですいません。
rst英語はsphinx対応のドキュメント、html英語は今までのドキュメントを指します。

やろうとしたのは、rst英語=>rst日本語のテキスト置換です。
その置換のためのデータを、html英語とhtml日本語から取ってくる、というものです。
(今までのhtml日本語をrst化、ではないです。)

html英語の行とhtml日本語の行がそろっているので、
例えば、※「x行めのhtml英語」があったら、「x行めのhtml日本語」に差し替える
というものです。 ※
(このときに英語、日本語の対を作るので、CSV形式の対訳ファイル生成は可能。
omegaTは用語集がCSV形式対応)

※の作業を、rst英語に実行すれば、日本語に置換されたものができるかも、ということです。

テキスト置換のコードは以下のとおりです。(str_replaceのところで複数適用されてしまうケースがある)
<?php
$source_file = "en.html"; // 古いユーザーガイドの原文
$target_file = "ja.html"; // 古いユーザーガイドの日本語
$sphinx_file = "en.rst"; // 新しいユーザーガイドの原文
$output_file = "ja.rst"; // 新しいユーザーガイドの日本語

$fh_source = fopen($source_file,'rb');
$fh_target = fopen($target_file,'rb');
$fh_sphinx = fopen($sphinx_file,'rb');
$fh_output = fopen($output_file,'wb');

// $line_source $line_target の同じ行が対応することを想定
$line_source_array = array();
$line_target_array = array();
for( $line_source = fgets($fh_source); !feof($fh_source);$line_source
= fgets($fh_source)){
    $line_target = fgets($fh_target);

    // タグなどを取り除き、それぞれの配列に格納する
    $line_source_stripped = trim(strip_tags($line_source));
    if ($line_source_stripped != "") {
        $line_source_array[] = $line_source_stripped;
    }
    $line_target_stripped = trim(strip_tags($line_target));
    if ($line_target_stripped != "") {
        $line_target_array[] = $line_target_stripped;
    }

}

// 力技で置換する
for( $line_sphinx = fgets($fh_sphinx); !feof($fh_sphinx);$line_sphinx
= fgets($fh_sphinx)){
    $data = str_replace($line_source_array,$line_target_array,$line_sphinx);
    fwrite($fh_output,$data);
}
fclose($fh_source);
fclose($fh_target);
fclose($fh_sphinx);
fclose($fh_output);
?>




-- 
Fumito Mizuno
Standing on the Shoulder of Linus
http://ounziw.com/




Codeigniter-users メーリングリストの案内
Back to archive index