Created
January 9, 2014 14:17
-
-
Save mathiasverraes/8334759 to your computer and use it in GitHub Desktop.
Translating Value Objects
----
In response to https://gist.github.com/wkocmann/4f6843e15db5401cdefc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class Country | |
{ | |
private $isoCode; // private! Value Objects are immutable | |
public function __construct($isoCode) | |
{ | |
$this->isoCode = $isoCode; | |
} | |
// no setter, again for immutability | |
public function __toString() | |
{ | |
return $this->isoCode; | |
} | |
} | |
/** | |
## translation.nl.ini or yaml or... depending on translation framework | |
AT=Oostenrijk | |
DE=Duitsland | |
BE=België | |
*/ | |
// in a template: | |
/* | |
<% trans(country) %> | |
*/ | |
// in code | |
$country = new Country('BE'); | |
echo $translator->translate($country); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment