Page MenuHomePhabricator

D7532.diff
No OneTemporary

D7532.diff

Index: src/internationalization/PhutilTranslator.php
===================================================================
--- src/internationalization/PhutilTranslator.php
+++ src/internationalization/PhutilTranslator.php
@@ -68,6 +68,12 @@
}
array_shift($args);
+ foreach ($args as $k => $arg) {
+ if ($arg instanceof PhutilNumber) {
+ $args[$k] = $this->formatNumber($arg->getNumber(), $arg->getDecimals());
+ }
+ }
+
// Check if any arguments are PhutilSafeHTML. If they are, we will apply
// any escaping necessary and output HTML.
$is_html = false;
@@ -84,12 +90,6 @@
}
}
- foreach ($args as $k => $arg) {
- if ($arg instanceof PhutilNumber) {
- $args[$k] = $this->formatNumber($arg->getNumber(), $arg->getDecimals());
- }
- }
-
$result = vsprintf($translation, $args);
if ($this->language == 'en-ac') {
@@ -178,7 +178,7 @@
/**
* Format number with grouped thousands and optional decimal part. Requires
* translations of '.' (decimal point) and ',' (thousands separator). Both
- * these translations must be 1 byte long.
+ * these translations must be 1 byte long with PHP < 5.4.0.
*
* @param float
* @param int
Index: src/internationalization/__tests__/PhutilTranslatorTestCase.php
===================================================================
--- src/internationalization/__tests__/PhutilTranslatorTestCase.php
+++ src/internationalization/__tests__/PhutilTranslatorTestCase.php
@@ -220,8 +220,8 @@
$who,
$when);
$this->assertEqual(
- true,
- gettype($translation) == 'string');
+ 'string',
+ gettype($translation));
$this->assertEqual(
'<span>Abraham</span> awoke <strong>suddenly</strong> at <4 AM>.',
$translation);
@@ -238,6 +238,14 @@
$this->assertEqual(
'<span>Abraham</span> awoke <strong>suddenly</strong> at &lt;4 AM&gt;.',
$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());
}
}

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 8:32 PM (19 h, 47 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6813723
Default Alt Text
D7532.diff (2 KB)

Event Timeline