Skip to content

Instantly share code, notes, and snippets.

@gusrub
Last active April 16, 2018 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusrub/d8cd63312f9e4db0df2c99d8daab44b5 to your computer and use it in GitHub Desktop.
Save gusrub/d8cd63312f9e4db0df2c99d8daab44b5 to your computer and use it in GitHub Desktop.
Internationalization PHP 1
<?php
class Person
{
const VERSION = '1.0.0';
public $firstName;
public $lastName;
public $dob;
function __construct($firstName, $lastName, $dob)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->dob = $dob;
}
public function printInfo()
{
$age = $this->calculateAge();
echo sprintf(_("Hello my name is %s %s and I'm %s\n"), $this->firstName, $this->lastName, $age);
}
public function goodBye()
{
echo _("That's it, good bye!\n");
}
public function printVersion()
{
echo sprintf("\n(running version %s)\n", self::VERSION);
}
private function calculateAge()
{
$dob = date_create($this->dob);
$now = date_create();
$age = date_diff($dob, $now)->format("%y");
$response = null;
if($age < 18) {
$response = sprintf(_("%s years which means I'm a teen"), $age);
} else {
$response = sprintf(_("%s years which means I'm a grown up"), $age);
}
return $response;
}
}
$p = new Person(
'John',
'Wayne',
'1980-01-20'
);
$p->printInfo();
$p->goodBye();
$p->printVersion();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment