<?php
class Resource
{
"goodmoring" => "おはようございます",
"goodafternoon" => "こんにちは",
"goodevening" => "こんばんは"
);
"goodmoring" => "Good Morning",
"goodafternoon" => "Good Afternoon",
"goodevening" => "Good Evening"
);
private static $instance = null;
public static function Get()
{
{
self::$instance = new Resource();
}
return self::$instance;
}
{
$locale = Locale::getDefault();
if($locale == "ja")
return $this->ja_msg[$msg];
if($locale == "en")
return $this->en_msg[$msg];
return $this->ja_msg[$msg];
}
}
Class Greet
{
public function __construct()
{
}
public function greet($timestamp)
{
}
public function greet2($date)
{
$res = Resource::Get();
$hour = $date["hour"];
if($hour >= 5 && $hour < 12)
return $res->GetText("goodmoring"); if($hour >= 12 && $hour < 18)
return $res->GetText("goodafternoon"); if($hour >= 18 && $hour <= 23)
return $res->GetText("goodevening"); if($hour >= 0 && $hour < 5)
return $res->GetText("goodevening"); }
}
TestMessage();
Locale::setDefault('en');
TestMessage();
Locale::setDefault('ja');
TestMessage();
function TestMessage()
{
$res = Resource::Get();
$greeter = new Greet();
$result = $greeter->greet2(date_parse("2013/12/01 5:00:00")); if($result != $res->GetText("goodmoring")) {
}
$result = $greeter->greet2(date_parse("2013/12/01 12:00:00")); if($result != $res->GetText("goodafternoon")) {
}
$result = $greeter->greet2(date_parse("2013/12/01 18:00:00")); if($result != $res->GetText("goodevening")) {
}
}
PD9waHAKCmRhdGVfZGVmYXVsdF90aW1lem9uZV9zZXQoIkFzaWEvVG9reW8iKTsKCmNsYXNzIFJlc291cmNlCnsKCXByaXZhdGUgJGphX21zZyA9IGFycmF5KAoJCSJnb29kbW9yaW5nIiA9PiAi44GK44Gv44KI44GG44GU44GW44GE44G+44GZIiwKCQkiZ29vZGFmdGVybm9vbiIgPT4gIuOBk+OCk+OBq+OBoeOBryIsCgkJImdvb2RldmVuaW5nIiA9PiAi44GT44KT44Gw44KT44GvIgoJKTsKCXByaXZhdGUgJGVuX21zZyA9IGFycmF5KAoJCSJnb29kbW9yaW5nIiA9PiAiR29vZCBNb3JuaW5nI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