Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

PEAR::Date_Holidays_Driver_Japanese 0.2.0

バージョン0.2.0をリリースします。更新内容は以下の通りです。

インストールは

$ sudo pear install -af http://www.doyouphp.jp/pear/Date_Holidays_Driver_Japanese-0.2.0.tgz

アップグレードは

$ sudo pear upgrade -af http://www.doyouphp.jp/pear/Date_Holidays_Driver_Japanese-0.2.0.tgz

な感じで。コード一式はCodeReposからどうぞ。

翻訳ファイルの使い方は、ざっと以下の通り。

<?php
require_once "Date/Holidays.php";
define('LANG_FILE', '/path/to/pear/data/Date_Holidays_Driver_Japanese/lang');

$obj =& Date_Holidays::factory('Japanese', 2008);
if (Date_Holidays::isError($obj)) {
    die('Factory was unable to produce driver-object');
}

/**
 * 翻訳ファイルをロケール=ja_JPとして登録(XML形式の場合)
 * シリアライズされたデータファイルを使う場合は、addCompiledTranslationFile
 * メソッドを使う
 */
$obj->addTranslationFile(LANG_FILE . '/Japanese/ja_JP.xml', 'ja_JP');
//	$obj->addCompiledTranslationFile(LANG_FILE . '/Japanese/ja_JP.ser', 'ja_JP');
if (Date_Holidays::isError($obj)) {
    die($obj->getMessage());
}

/**
 * ロケール=Cでタイトルを表示
 */
var_dump($obj->getHolidayTitles());

/**
 * ロケール=ja_JPでタイトルを表示
 */
var_dump($obj->getHolidayTitles(null, 'ja_JP'));

実行結果は、次のようになります。

array(17) {
  ["newYearsDay"]=>
  string(14) "New Year's Day"
  ["comingOfAgeDay"]=>
  string(17) "Coming of Age Day"
  ["nationalFoundationDay"]=>
  string(23) "National Foundation Day"
  ["Vernal Equinox Day"]=>
  string(18) "Vernal Equinox Day"
  ["showaDay"]=>
  string(9) "Showa Day"
  ["constitutionMemorialDay"]=>
  string(25) "Constitution Memorial Day"
  ["greeneryDay"]=>
  string(12) "Greenery Day"
  ["childrensDay"]=>
  string(14) "Children's Day"
  ["marineDay"]=>
  string(10) "Marine Day"
  ["respectfortheAgedDay"]=>
  string(24) "Respect for the Aged Day"
  ["autumnalEquinoxDay"]=>
  string(20) "Autumnal Equinox Day"
  ["healthandSportsDay"]=>
  string(21) "Health and Sports Day"
  ["nationalCultureDay"]=>
  string(20) "National Culture Day"
  ["laborThanksgivingDay"]=>
  string(22) "Labor Thanksgiving Day"
  ["emperorsBirthday"]=>
  string(18) "Emperor's Birthday"
  ["substituteHolidayForgreeneryDay"]=>
  string(35) "Substitute Holiday for Greenery Day"
  ["substituteHolidayForlaborThanksgivingDay"]=>
  string(45) "Substitute Holiday for Labor Thanksgiving Day"
}
array(17) {
  ["newYearsDay"]=>
  string(6) "元日"
  ["comingOfAgeDay"]=>
  string(12) "成人の日"
  ["nationalFoundationDay"]=>
  string(18) "建国記念の日"
  ["Vernal Equinox Day"]=>
  string(12) "春分の日"
  ["showaDay"]=>
  string(12) "昭和の日"
  ["constitutionMemorialDay"]=>
  string(15) "憲法記念日"
  ["greeneryDay"]=>
  string(15) "みどりの日"
  ["childrensDay"]=>
  string(15) "こどもの日"
  ["marineDay"]=>
  string(9) "海の日"
  ["respectfortheAgedDay"]=>
  string(12) "敬老の日"
  ["autumnalEquinoxDay"]=>
  string(12) "秋分の日"
  ["healthandSportsDay"]=>
  string(12) "体育の日"
  ["nationalCultureDay"]=>
  string(12) "文化の日"
  ["laborThanksgivingDay"]=>
  string(18) "勤労感謝の日"
  ["emperorsBirthday"]=>
  string(15) "天皇誕生日"
  ["substituteHolidayForgreeneryDay"]=>
  string(12) "振替休日"
  ["substituteHolidayForlaborThanksgivingDay"]=>
  string(12) "振替休日"
}

追記(2008/08/24 14:20)

PEAR::Date_Holidays_Driver_JapaneseはPEAR::Date_Holidays_Japanとして本家PEARに登録されました。