suddenly at %s.';
$when = '<4 AM>';
$translator = $this->newTranslator('en_US');
// When no components are HTML, everything is treated as a string.
$who = 'Abraham';
$translation = $translator->translate(
$string,
$who,
$when);
$this->assertEqual(
'string',
gettype($translation));
$this->assertEqual(
'Abraham awoke suddenly at <4 AM>.',
$translation);
// When at least one component is HTML, everything is treated as HTML.
$who = phutil_tag('span', array(), 'Abraham');
$translation = $translator->translate(
$string,
$who,
$when);
$this->assertTrue($translation instanceof PhutilSafeHTML);
$this->assertEqual(
'Abraham awoke suddenly at <4 AM>.',
$translation->getHTMLContent());
$translation = $translator->translate(
$string,
$who,
new PhutilNumber(1383930802));
$this->assertEqual(
'Abraham awoke suddenly at 1,383,930,802.',
$translation->getHTMLContent());
// In this translation, we have no alternatives for the first conversion.
$translator->setTranslations(
array(
'Run the command %s %d time(s).' => array(
array(
'Run the command %s once.',
'Run the command %s %d times.',
),
),
));
$this->assertEqual(
'Run the command ls 123 times.',
(string)$translator->translate(
'Run the command %s %d time(s).',
hsprintf('%s', 'ls'),
123));
}
private function newTranslator($locale_code) {
$locale = PhutilLocale::loadLocale($locale_code);
return id(new PhutilTranslator())
->setLocale($locale);
}
}