jenkins-bot has submitted this change and it was merged.

Change subject: Add i18n support in MwTimeIsoFormatter
......................................................................


Add i18n support in MwTimeIsoFormatter

Bug: 60100
Change-Id: Id7fa930d02dfc072b353bbe56e650710708ac2cc
---
M lib/includes/formatters/MwTimeIsoFormatter.php
M lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
M repo/Wikibase.i18n.php
3 files changed, 63 insertions(+), 50 deletions(-)

Approvals:
  WikidataJenkins: Verified
  Adrian Lang: Looks good to me, approved
  Siebrand: Looks good to me, but someone else must approve
  Jeroen De Dauw: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/lib/includes/formatters/MwTimeIsoFormatter.php 
b/lib/includes/formatters/MwTimeIsoFormatter.php
index 52031c6..bcc1cea 100644
--- a/lib/includes/formatters/MwTimeIsoFormatter.php
+++ b/lib/includes/formatters/MwTimeIsoFormatter.php
@@ -4,6 +4,7 @@
 
 use DataValues\TimeValue;
 use Language;
+use Message;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\TimeIsoFormatter;
 use ValueFormatters\ValueFormatter;
@@ -126,59 +127,40 @@
         * @return string the formatted year
         */
        private function formatYear( $fullYear, $precision ) {
-               $beforeYear = '';
-               $afterYear = '';
-
-               //todo i18n below
                switch( $precision ) {
                        case TimeValue::PRECISION_Ga:
                                $fullYear = round( $fullYear, -9 );
                                $fullYear = substr( $fullYear, 0, -9 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' billion years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-Gannum', $fullYear );
                        case TimeValue::PRECISION_100Ma:
                                $fullYear = round( $fullYear, -8 );
                                $fullYear = substr( $fullYear, 0, -6 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' million years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-Mannum', $fullYear );
                        case TimeValue::PRECISION_10Ma:
                                $fullYear = round( $fullYear, -7 );
                                $fullYear = substr( $fullYear, 0, -6 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' million years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-Mannum', $fullYear );
                        case TimeValue::PRECISION_Ma:
                                $fullYear = round( $fullYear, -6 );
                                $fullYear = substr( $fullYear, 0, -6 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' million years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-Mannum', $fullYear );
                        case TimeValue::PRECISION_100ka:
                                $fullYear = round( $fullYear, -5 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-annum', $fullYear );
                        case TimeValue::PRECISION_10ka:
                                $fullYear = round( $fullYear, -4 );
-                               $beforeYear = 'in ';
-                               $afterYear = ' years';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-annum', $fullYear );
                        case TimeValue::PRECISION_ka:
                                $fullYear = round( $fullYear, -3 );
                                $fullYear = substr( $fullYear, 0, -3 );
-                               $afterYear = '.millennium';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-millennium', $fullYear );
                        case TimeValue::PRECISION_100a:
                                $fullYear = round( $fullYear, -2 );
                                $fullYear = substr( $fullYear, 0, -2 );
-                               $afterYear = '.century';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-century', $fullYear );
                        case TimeValue::PRECISION_10a:
                                $fullYear = round( $fullYear, -1 );
-                               $afterYear = 's';
-                               break;
+                               return $this->getMessage( 
'wikibase-time-precision-10annum', $fullYear );
                        default:
                                //If not one of the above make sure the year 
have at least 4 digits
                                $fullYear = ltrim( $fullYear, '0' );
@@ -186,9 +168,24 @@
                                if( $fullYearLength < 4 ) {
                                        $fullYear = str_repeat( '0', 4 - 
$fullYearLength ) . $fullYear;
                                }
-                               break;
+                               //only add separators if there are more than 4 
digits
+                               if( strlen( $fullYear ) > 4 ) {
+                                       $fullYear = $this->language->formatNum( 
$fullYear );
+                               }
+                               return $fullYear;
                }
-               return $beforeYear . $fullYear . $afterYear;
+       }
+
+       /**
+        * @param string $key
+        * @param string $fullYear
+        * @return String
+        */
+       private function getMessage( $key, $fullYear ) {
+               $message = new Message( $key );
+               $message->inLanguage( $this->language );
+               $message->numParams( array( $fullYear ) );
+               return $message->text();
        }
 
 }
diff --git a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php 
b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
index cfc36ab..2a7675a 100644
--- a/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
+++ b/lib/tests/phpunit/formatters/MwTimeIsoFormatterTest.php
@@ -40,7 +40,7 @@
                                '+00000000001-01-14T00:00:00Z',
                                TimeValue::PRECISION_DAY,
                        ),
-                       '1 January 10000' => array(
+                       '1 January 10,000' => array(
                                '+00000010000-01-01T00:00:00Z',
                                TimeValue::PRECISION_DAY,
                        ),
@@ -56,76 +56,76 @@
                                '+00000000013-07-16T00:00:00Z',
                                TimeValue::PRECISION_YEAR,
                        ),
-                       '2222013' => array(
+                       '2,222,013' => array(
                                '+00002222013-07-16T00:10:00Z',
                                TimeValue::PRECISION_YEAR,
                        ),
-                       '12342222013' => array(
+                       '12,342,222,013' => array(
                                '+12342222013-07-16T00:10:00Z',
                                TimeValue::PRECISION_YEAR,
                        ),
                        //stepping through precisions
-                       '12345678910s' => array(
+                       '12,345,678,910s' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_10a,
                        ),
-                       '12345678920s' => array(
+                       '12,345,678,920s' => array(
                                '+12345678919-01-01T01:01:01Z',
                                TimeValue::PRECISION_10a,
                        ),
-                       '123456789.century' => array(
+                       '123,456,789. century' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_100a,
                        ),
-                       '123456790.century' => array(
+                       '123,456,790. century' => array(
                                '+12345678992-01-01T01:01:01Z',
                                TimeValue::PRECISION_100a,
                        ),
-                       '12345678.millennium' => array(
+                       '12,345,678. millennium' => array(
                                '+12345678112-01-01T01:01:01Z',
                                TimeValue::PRECISION_ka,
                        ),
-                       '12345679.millennium' => array(
+                       '12,345,679. millennium' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_ka,
                        ),
-                       'in 12345670000 years' => array(
+                       'in 12,345,670,000 years' => array(
                                '+12345671912-01-01T01:01:01Z',
                                TimeValue::PRECISION_10ka,
                        ),
-                       'in 12345680000 years' => array(
+                       'in 12,345,680,000 years' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_10ka,
                        ),
-                       'in 12345600000 years' => array(
+                       'in 12,345,600,000 years' => array(
                                '+12345618912-01-01T01:01:01Z',
                                TimeValue::PRECISION_100ka,
                        ),
-                       'in 12345700000 years' => array(
+                       'in 12,345,700,000 years' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_100ka,
                        ),
-                       'in 12345 million years' => array(
+                       'in 12,345 million years' => array(
                                '+12345178912-01-01T01:01:01Z',
                                TimeValue::PRECISION_Ma,
                        ),
-                       'in 12346 million years' => array(
+                       'in 12,346 million years' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_Ma,
                        ),
-                       'in 12340 million years' => array(
+                       'in 12,340 million years' => array(
                                '+12341678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_10Ma,
                        ),
-                       'in 12350 million years' => array(
+                       'in 12,350 million years' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_10Ma,
                        ),
-                       'in 12300 million years' => array(
+                       'in 12,300 million years' => array(
                                '+12345678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_100Ma,
                        ),
-                       'in 12400 million years' => array(
+                       'in 12,400 million years' => array(
                                '+12375678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_100Ma,
                        ),
@@ -137,7 +137,7 @@
                                '+12545678912-01-01T01:01:01Z',
                                TimeValue::PRECISION_Ga,
                        ),
-                       //The below still return the full timestamp
+                       //The below should still return the full timestamp as 
we can not yet format
                        '-00000000001-01-01T00:00:00Z' => array(
                                '-00000000001-01-01T00:00:00Z',
                                TimeValue::PRECISION_DAY,
diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 87badb6..ddc163e 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -19,6 +19,7 @@
  * @author Anja Jentzsch
  * @author Daniel Werner
  * @author Michał Łazowik
+ * @author Adam Shorland
  */
 $messages['en'] = array(
        'wikibase-desc' => 'Structured data repository',
@@ -453,9 +454,18 @@
        'action-label-update' => 'update labels',
        'action-description-remove' => 'erase descriptions',
        'action-description-update' => 'update descriptions',
+
+       // TimeFormats
+       'wikibase-time-precision-Gannum' => 'in $1 billion years',
+       'wikibase-time-precision-Mannum' => 'in $1 million years',
+       'wikibase-time-precision-annum' => 'in $1 years',
+       'wikibase-time-precision-millennium' => '$1. millennium',
+       'wikibase-time-precision-century' => '$1. century',
+       'wikibase-time-precision-10annum' => '$1s',
 );
 
 /** Message documentation (Message documentation)
+ * @author Adam Shorland
  * @author AS
  * @author Amire80
  * @author Aude
@@ -1323,6 +1333,12 @@
        'action-label-update' => '{{doc-action|label-update}}',
        'action-description-remove' => '{{doc-action|description-remove}}',
        'action-description-update' => '{{doc-action|description-update}}',
+       'wikibase-time-precision-Gannum' => 'Used to indicate a timespan in $1 
number of billions of years',
+       'wikibase-time-precision-Mannum' => 'Used to indicate a timespan in $1 
number of millions of years',
+       'wikibase-time-precision-annum' => 'Used to indicate a timespan in $1 
number of years',
+       'wikibase-time-precision-millennium' => 'Used to indicate a timespan in 
$1 number of millennium',
+       'wikibase-time-precision-century' => 'Used to indicate a timespan in $1 
number of centuries',
+       'wikibase-time-precision-10annum' => 'Used to indicate a timespan in $1 
number of 10s of years',
 );
 
 /** Achinese (Acèh)

-- 
To view, visit https://gerrit.wikimedia.org/r/109685
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id7fa930d02dfc072b353bbe56e650710708ac2cc
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to