Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190253

Change subject: Localize calendar names in TimeDetailsFormatter
......................................................................

Localize calendar names in TimeDetailsFormatter

The messages are defined in ValueView. I'm not sure if it's a good
idea to reuse them. This is not a problem now but could become one
when we try to split or move this code into components.

This patch drops the options thingy because this is not used anyway
and I think it is not usefull.

Change-Id: Icbd60f316f55171e06c6c68ec3d2e25f7e605a5e
---
M lib/includes/formatters/TimeDetailsFormatter.php
M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
2 files changed, 17 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/53/190253/1

diff --git a/lib/includes/formatters/TimeDetailsFormatter.php 
b/lib/includes/formatters/TimeDetailsFormatter.php
index 38b2af7..496b276 100644
--- a/lib/includes/formatters/TimeDetailsFormatter.php
+++ b/lib/includes/formatters/TimeDetailsFormatter.php
@@ -21,8 +21,6 @@
  */
 class TimeDetailsFormatter extends ValueFormatterBase {
 
-       const OPT_CALENDARNAMES = 'calendars';
-
        /**
         * @var TimeFormatter
         */
@@ -38,11 +36,6 @@
                        TimeFormatter::OPT_TIME_ISO_FORMATTER,
                        new MwTimeIsoFormatter( $this->options )
                );
-
-               $this->defaultOption( self::OPT_CALENDARNAMES, array(
-                       TimeFormatter::CALENDAR_GREGORIAN => 'Gregorian',
-                       TimeFormatter::CALENDAR_JULIAN => 'Julian',
-               ) );
 
                $this->timeFormatter = new TimeFormatter( $this->options );
        }
@@ -121,12 +114,20 @@
         * @return string HTML
         */
        private function getCalendarModelHtml( $calendarModel ) {
-               $calendarNames = $this->getOption( self::OPT_CALENDARNAMES );
-               if ( array_key_exists( $calendarModel, $calendarNames ) ) {
-                       $calendarModel = $calendarNames[$calendarModel];
+               switch ( $calendarModel ) {
+                       case TimeFormatter::CALENDAR_GREGORIAN:
+                               $key = 
'valueview-expert-timevalue-calendar-gregorian';
+                               break;
+                       case TimeFormatter::CALENDAR_JULIAN:
+                               $key = 
'valueview-expert-timevalue-calendar-julian';
+                               break;
+                       default:
+                               return htmlspecialchars( $calendarModel );
                }
 
-               return htmlspecialchars( $calendarModel );
+               $lang = $this->getOption( ValueFormatter::OPT_LANG );
+               $msg = wfMessage( $key )->inLanguage( $lang );
+               return $msg->text();
        }
 
        /**
diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
index 715eddb..725dc41 100644
--- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
@@ -48,7 +48,7 @@
                                                
'<h4[^<>]*>[^<>]*2001[^<>]*</h4>',
                                                
'<td[^<>]*>\+0*2001-01-01T00:00:00Z</td>',
                                                '<td[^<>]*>\+01:00</td>',
-                                               '<td[^<>]*>Gregorian</td>',
+                                               
'<td[^<>]*>\(valueview-expert-timevalue-calendar-gregorian\)</td>',
                                                '<td[^<>]*>\(months: 1\)</td>',
                                                '<td[^<>]*>\(months: 0\)</td>',
                                                '<td[^<>]*>\(months: 1\)</td>',
@@ -56,6 +56,10 @@
                                ) . '@s'
                        ),
                        array(
+                               new TimeValue( '+2001-01-01T00:00:00Z', 0, 0, 
0, $day, TimeFormatter::CALENDAR_JULIAN ),
+                               
'@.*<td[^<>]*calendar">\(valueview-expert-timevalue-calendar-julian\)</td>.*@s'
+                       ),
+                       array(
                                new TimeValue( '+2001-01-01T00:00:00Z', 0, 0, 
0, $day, 'Stardate' ),
                                '@.*<td[^<>]*calendar">Stardate</td>.*@s'
                        ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbd60f316f55171e06c6c68ec3d2e25f7e605a5e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to