Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
b5af2f6a
Commit
b5af2f6a
authored
Sep 10, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed size format plural rule to not format number itself
This fix ensures the format configured in the formatter class is used in the message instead of the default ICU format. fixes #4960
parent
2150fa32
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
47 deletions
+54
-47
DataColumn.php
framework/grid/DataColumn.php
+3
-3
Formatter.php
framework/i18n/Formatter.php
+30
-25
FormatterTest.php
tests/unit/framework/i18n/FormatterTest.php
+21
-19
No files found.
framework/grid/DataColumn.php
View file @
b5af2f6a
...
@@ -60,10 +60,10 @@ class DataColumn extends Column
...
@@ -60,10 +60,10 @@ class DataColumn extends Column
*/
*/
public
$value
;
public
$value
;
/**
/**
* @var string|array in which format should the value of each data model be displayed as (e.g.
"raw", "text", "html"
,
* @var string|array in which format should the value of each data model be displayed as (e.g.
`"raw"`, `"text"`, `"html"`
,
*
['date', 'Y-m-d']
). Supported formats are determined by the [[GridView::formatter|formatter]] used by
*
`['date', 'php:Y-m-d']`
). Supported formats are determined by the [[GridView::formatter|formatter]] used by
* the [[GridView]]. Default format is "text" which will format the value as an HTML-encoded plain text when
* the [[GridView]]. Default format is "text" which will format the value as an HTML-encoded plain text when
* [[\yii\i18n\Formatter
::format()]] or [[\yii\i18n\Formatter::format()]] is used
.
* [[\yii\i18n\Formatter
]] is used as the [[GridView::$formatter|formatter]] of the GridView
.
*/
*/
public
$format
=
'text'
;
public
$format
=
'text'
;
/**
/**
...
...
framework/i18n/Formatter.php
View file @
b5af2f6a
...
@@ -1075,21 +1075,21 @@ class Formatter extends Component
...
@@ -1075,21 +1075,21 @@ class Formatter extends Component
if
(
$this
->
sizeFormatBase
==
1024
)
{
if
(
$this
->
sizeFormatBase
==
1024
)
{
switch
(
$position
)
{
switch
(
$position
)
{
case
0
:
return
Yii
::
t
(
'yii'
,
'{n} B'
,
$params
,
$this
->
locale
);
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} B'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n} KiB'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} KiB'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n} MiB'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} MiB'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n} GiB'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} GiB'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n} TiB'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} TiB'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n} PiB'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} PiB'
,
$params
,
$this
->
locale
);
}
}
}
else
{
}
else
{
switch
(
$position
)
{
switch
(
$position
)
{
case
0
:
return
Yii
::
t
(
'yii'
,
'{n} B'
,
$params
,
$this
->
locale
);
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} B'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n} KB'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} KB'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n} MB'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} MB'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n} GB'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} GB'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n} TB'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} TB'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n} PB'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted
} PB'
,
$params
,
$this
->
locale
);
}
}
}
}
}
}
...
@@ -1119,21 +1119,21 @@ class Formatter extends Component
...
@@ -1119,21 +1119,21 @@ class Formatter extends Component
if
(
$this
->
sizeFormatBase
==
1024
)
{
if
(
$this
->
sizeFormatBase
==
1024
)
{
switch
(
$position
)
{
switch
(
$position
)
{
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# byte} other{#
bytes}}'
,
$params
,
$this
->
locale
);
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{byte} other{
bytes}}'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# kibibyte} other{#
kibibytes}}'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{kibibyte} other{
kibibytes}}'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# mebibyte} other{#
mebibytes}}'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{mebibyte} other{
mebibytes}}'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# gibibyte} other{#
gibibytes}}'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{gibibyte} other{
gibibytes}}'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# tebibyte} other{#
tebibytes}}'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{tebibyte} other{
tebibytes}}'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# pebibyte} other{#
pebibytes}}'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{pebibyte} other{
pebibytes}}'
,
$params
,
$this
->
locale
);
}
}
}
else
{
}
else
{
switch
(
$position
)
{
switch
(
$position
)
{
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# byte} other{#
bytes}}'
,
$params
,
$this
->
locale
);
case
0
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{byte} other{
bytes}}'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# kilobyte} other{#
kilobytes}}'
,
$params
,
$this
->
locale
);
case
1
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{kilobyte} other{
kilobytes}}'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# megabyte} other{#
megabytes}}'
,
$params
,
$this
->
locale
);
case
2
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{megabyte} other{
megabytes}}'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# gigabyte} other{#
gigabytes}}'
,
$params
,
$this
->
locale
);
case
3
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{gigabyte} other{
gigabytes}}'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# terabyte} other{#
terabytes}}'
,
$params
,
$this
->
locale
);
case
4
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{terabyte} other{
terabytes}}'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
, plural, =1{# petabyte} other{#
petabytes}}'
,
$params
,
$this
->
locale
);
default
:
return
Yii
::
t
(
'yii'
,
'{n
Formatted} {n, plural, =1{petabyte} other{
petabytes}}'
,
$params
,
$this
->
locale
);
}
}
}
}
}
}
...
@@ -1167,7 +1167,12 @@ class Formatter extends Component
...
@@ -1167,7 +1167,12 @@ class Formatter extends Component
$this
->
thousandSeparator
=
''
;
$this
->
thousandSeparator
=
''
;
$options
[
NumberFormatter
::
GROUPING_USED
]
=
false
;
$options
[
NumberFormatter
::
GROUPING_USED
]
=
false
;
// format the size value
// format the size value
$params
=
[
'n'
=>
$this
->
asDecimal
(
$value
,
$decimals
,
$options
,
$textOptions
)];
$params
=
[
// this is the unformatted number used for the plural rule
'n'
=>
$value
,
// this is the formatted number used for display
'nFormatted'
=>
$this
->
asDecimal
(
$value
,
$decimals
,
$options
,
$textOptions
),
];
$this
->
thousandSeparator
=
$oldThousandSeparator
;
$this
->
thousandSeparator
=
$oldThousandSeparator
;
return
[
$params
,
$position
];
return
[
$params
,
$position
];
...
...
tests/unit/framework/i18n/FormatterTest.php
View file @
b5af2f6a
...
@@ -746,16 +746,13 @@ class FormatterTest extends TestCase
...
@@ -746,16 +746,13 @@ class FormatterTest extends TestCase
$this
->
formatter
->
sizeFormatBase
=
1024
;
$this
->
formatter
->
sizeFormatBase
=
1024
;
$this
->
assertSame
(
"1 kibibyte"
,
$this
->
formatter
->
asSize
(
1024
));
$this
->
assertSame
(
"1 kibibyte"
,
$this
->
formatter
->
asSize
(
1024
));
$this
->
assertSame
(
"1 mebibyte"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
$this
->
assertSame
(
"1 mebibyte"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
// https://github.com/yiisoft/yii2/issues/4960
$this
->
assertSame
(
"1023 bytes"
,
$this
->
formatter
->
asSize
(
1023
));
// $this->assertSame("1023 bytes", $this->formatter->asSize(1023));
$this
->
assertSame
(
"5 gibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
));
$this
->
assertSame
(
"5 gibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
));
$this
->
assertNotEquals
(
"5 pibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
*
1024
*
1024
*
1024
));
// this is 5 EiB not 5 PiB
$this
->
assertNotEquals
(
"5 pibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
*
1024
*
1024
*
1024
));
// this is 5 EiB not 5 PiB
//$this->assertSame("1 YiB", $this->formatter->asSize(pow(2, 80)));
$this
->
assertSame
(
"2 gibibytes"
,
$this
->
formatter
->
asSize
(
2147483647
));
// round 1.999 up to 2
$this
->
assertSame
(
"2 gibibytes"
,
$this
->
formatter
->
asSize
(
2147483647
));
// round 1.999 up to 2
$this
->
formatter
->
decimalSeparator
=
','
;
$this
->
formatter
->
decimalSeparator
=
','
;
$this
->
formatter
->
numberFormatterOptions
=
[];
$this
->
formatter
->
numberFormatterOptions
=
[];
// https://github.com/yiisoft/yii2/issues/4960
$this
->
assertSame
(
"1,001 kibibytes"
,
$this
->
formatter
->
asSize
(
1025
,
3
));
// $this->assertSame("1,001 KiB", $this->formatter->asSize(1025, 3));
// null display
// null display
$this
->
assertSame
(
$this
->
formatter
->
nullDisplay
,
$this
->
formatter
->
asSize
(
null
));
$this
->
assertSame
(
$this
->
formatter
->
nullDisplay
,
$this
->
formatter
->
asSize
(
null
));
...
@@ -767,28 +764,33 @@ class FormatterTest extends TestCase
...
@@ -767,28 +764,33 @@ class FormatterTest extends TestCase
$this
->
formatter
->
sizeFormatBase
=
1000
;
$this
->
formatter
->
sizeFormatBase
=
1000
;
$this
->
assertSame
(
"999 bytes"
,
$this
->
formatter
->
asSize
(
999
));
$this
->
assertSame
(
"999 bytes"
,
$this
->
formatter
->
asSize
(
999
));
$this
->
assertSame
(
"1.05 megabytes"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
$this
->
assertSame
(
"1.05 megabytes"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
// https://github.com/yiisoft/yii2/issues/4960
$this
->
assertSame
(
"1.0486 megabytes"
,
$this
->
formatter
->
asSize
(
1024
*
1024
,
4
));
// $this->assertSame("1.0486 megabytes", $this->formatter->asSize(1024 * 1024, 4));
$this
->
assertSame
(
"1.00 kilobyte"
,
$this
->
formatter
->
asSize
(
1000
));
$this
->
assertSame
(
"1 kilobyte"
,
$this
->
formatter
->
asSize
(
1000
));
$this
->
assertSame
(
"1.02 kilobytes"
,
$this
->
formatter
->
asSize
(
1023
));
$this
->
assertSame
(
"1.02 kilobytes"
,
$this
->
formatter
->
asSize
(
1023
));
$this
->
assertSame
(
"3 gigabytes"
,
$this
->
formatter
->
asSize
(
3
*
1000
*
1000
*
1000
));
$this
->
assertSame
(
"3
.00
gigabytes"
,
$this
->
formatter
->
asSize
(
3
*
1000
*
1000
*
1000
));
$this
->
assertNotEquals
(
"3 PB"
,
$this
->
formatter
->
asSize
(
3
*
1000
*
1000
*
1000
*
1000
*
1000
*
1000
));
// this is 3 EB not 3 PB
$this
->
assertNotEquals
(
"3 PB"
,
$this
->
formatter
->
asSize
(
3
*
1000
*
1000
*
1000
*
1000
*
1000
*
1000
));
// this is 3 EB not 3 PB
// tests for base 1024
// tests for base 1024
$this
->
formatter
->
sizeFormatBase
=
1024
;
$this
->
formatter
->
sizeFormatBase
=
1024
;
$this
->
assertSame
(
"1 kibibyte"
,
$this
->
formatter
->
asSize
(
1024
));
$this
->
assertSame
(
"1.00 kibibyte"
,
$this
->
formatter
->
asSize
(
1024
));
$this
->
assertSame
(
"1 mebibyte"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
$this
->
assertSame
(
"1.00 mebibyte"
,
$this
->
formatter
->
asSize
(
1024
*
1024
));
// https://github.com/yiisoft/yii2/issues/4960
$this
->
assertSame
(
"1023 bytes"
,
$this
->
formatter
->
asSize
(
1023
));
// $this->assertSame("1023 B", $this->formatter->asSize(1023));
$this
->
assertSame
(
"5.00 gibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
));
$this
->
assertSame
(
"5 gibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
));
$this
->
assertNotEquals
(
"5.00 pibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
*
1024
*
1024
*
1024
));
// this is 5 EiB not 5 PiB
$this
->
assertNotEquals
(
"5 pibibytes"
,
$this
->
formatter
->
asSize
(
5
*
1024
*
1024
*
1024
*
1024
*
1024
*
1024
));
// this is 5 EiB not 5 PiB
$this
->
assertSame
(
"2.00 gibibytes"
,
$this
->
formatter
->
asSize
(
2147483647
));
// round 1.999 up to 2
//$this->assertSame("1 YiB", $this->formatter->asSize(pow(2, 80)));
$this
->
assertSame
(
"2 gibibytes"
,
$this
->
formatter
->
asSize
(
2147483647
));
// round 1.999 up to 2
$this
->
formatter
->
decimalSeparator
=
','
;
$this
->
formatter
->
decimalSeparator
=
','
;
$this
->
formatter
->
numberFormatterOptions
=
[];
$this
->
formatter
->
numberFormatterOptions
=
[];
// https://github.com/yiisoft/yii2/issues/4960
$this
->
assertSame
(
"1,001 kibibytes"
,
$this
->
formatter
->
asSize
(
1025
,
3
));
// $this->assertSame("1,001 kibibytes", $this->formatter->asSize(1025));
// null display
// null display
$this
->
assertSame
(
$this
->
formatter
->
nullDisplay
,
$this
->
formatter
->
asSize
(
null
));
$this
->
assertSame
(
$this
->
formatter
->
nullDisplay
,
$this
->
formatter
->
asSize
(
null
));
}
}
/**
* https://github.com/yiisoft/yii2/issues/4960
*/
public
function
testAsSizeConfiguration
()
{
// $this->formatter->thousandSeparator = '';
$this
->
assertSame
(
"1023 bytes"
,
$this
->
formatter
->
asSize
(
1023
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment