Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
2.0 kB · 68 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869<?php
final class PhutilTranslatedHTMLTestCase extends PhutilTestCase {
public function testHTMLTranslations() { $string = '%s awoke <strong>suddenly</strong> at %s.'; $when = '<4 AM>';
$translator = $this->newTranslator('en_US');
// When no components are HTML, everything is treated as a string. $who = '<span>Abraham</span>'; $translation = $translator->translate( $string, $who, $when); $this->assertEqual( 'string', gettype($translation)); $this->assertEqual( '<span>Abraham</span> awoke <strong>suddenly</strong> 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( '<span>Abraham</span> awoke <strong>suddenly</strong> at <4 AM>.', $translation->getHTMLContent());
$translation = $translator->translate( $string, $who, new PhutilNumber(1383930802)); $this->assertEqual( '<span>Abraham</span> awoke <strong>suddenly</strong> 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 <kbd>ls</kbd> 123 times.', (string)$translator->translate( 'Run the command %s %d time(s).', hsprintf('<kbd>%s</kbd>', 'ls'), 123)); }
private function newTranslator($locale_code) { $locale = PhutilLocale::loadLocale($locale_code); return id(new PhutilTranslator()) ->setLocale($locale); }
}