Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created January 9, 2014 14:17
Show Gist options
  • Save mathiasverraes/8334759 to your computer and use it in GitHub Desktop.
Save mathiasverraes/8334759 to your computer and use it in GitHub Desktop.
Translating Value Objects ---- In response to https://gist.github.com/wkocmann/4f6843e15db5401cdefc
<?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