jenkins-bot has submitted this change and it was merged.
Change subject: Add language functions
......................................................................
Add language functions
RTL support, duration formatting.
Change-Id: I78db53976abfe04fd6529b36c9434e33a3bc90c7
---
M engines/LuaCommon/LanguageLibrary.php
M engines/LuaCommon/lualib/mw.language.lua
2 files changed, 87 insertions(+), 1 deletion(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/engines/LuaCommon/LanguageLibrary.php
b/engines/LuaCommon/LanguageLibrary.php
index 54a94c7..a08955c 100644
--- a/engines/LuaCommon/LanguageLibrary.php
+++ b/engines/LuaCommon/LanguageLibrary.php
@@ -29,6 +29,8 @@
'caseFold',
'formatNum',
'formatDate',
+ 'formatDuration',
+ 'getDurationIntervals',
'parseFormattedNumber',
'convertPlural',
'convertGrammar',
@@ -266,4 +268,34 @@
$this->timeCache[$format][$cacheKey][$langcode][$local] = $ret;
return array( $ret );
}
+
+ /**
+ * formatDuration handler
+ */
+ function formatDuration( $lang, $args ) {
+ $this->checkType( 'formatDuration', 1, $args[0], 'number' );
+ $this->checkTypeOptional( 'formatDuration', 2, $args[1],
'table', array() );
+
+ list( $seconds, $chosenIntervals ) = $args;
+ $langcode = $lang->getCode();
+ $chosenIntervals = array_values( $chosenIntervals );
+
+ $ret = $lang->formatDuration( $seconds, $chosenIntervals );
+ return array( $ret );
+ }
+
+ /**
+ * getDurationIntervals handler
+ */
+ function getDurationIntervals( $lang, $args ) {
+ $this->checkType( 'getDurationIntervals', 1, $args[0], 'number'
);
+ $this->checkTypeOptional( 'getDurationIntervals', 2, $args[1],
'table', array() );
+
+ list( $seconds, $chosenIntervals ) = $args;
+ $langcode = $lang->getCode();
+ $chosenIntervals = array_values( $chosenIntervals );
+
+ $ret = $lang->getDurationIntervals( $seconds, $chosenIntervals
);
+ return array( $ret );
+ }
}
diff --git a/engines/LuaCommon/lualib/mw.language.lua
b/engines/LuaCommon/lualib/mw.language.lua
index da76aaf..69a6cf7 100644
--- a/engines/LuaCommon/lualib/mw.language.lua
+++ b/engines/LuaCommon/lualib/mw.language.lua
@@ -61,7 +61,6 @@
local checkSelf = util.makeCheckSelfFunction( 'mw.language', 'lang',
lang, 'language object' )
local wrappers = {
- isRTL = 0,
lcfirst = 1,
ucfirst = 1,
lc = 1,
@@ -70,6 +69,8 @@
formatNum = 1,
formatDate = 1,
parseFormattedNumber = 1,
+ formatDuration = 1,
+ getDurationIntervals = 1,
convertPlural = 2,
convertGrammar = 2,
gender = 2,
@@ -85,6 +86,16 @@
end
end
+ -- This one could use caching
+ function lang:isRTL()
+ checkSelf( self, 'isRTL' )
+ local rtl = php.isRTL( self.code )
+ self.isRTL = function ()
+ return rtl
+ end
+ return rtl
+ end
+
-- Alias
lang.plural = lang.convertPlural
@@ -94,11 +105,54 @@
return self:convertGrammar( word, case )
end
+ -- Other functions
function lang:getCode()
checkSelf( self, 'getCode' )
return self.code
end
+ function lang:getDir()
+ checkSelf( self, 'getDir' )
+ return self:isRTL() and 'rtl' or 'ltr'
+ end
+
+ function lang:getDirMark( opposite )
+ checkSelf( self, 'getDirMark' )
+ local b = self:isRTL()
+ if opposite then
+ b = not b
+ end
+ return b and '\226\128\143' or '\226\128\142'
+ end
+
+ function lang:getDirMarkEntity( opposite )
+ checkSelf( self, 'getDirMarkEntity' )
+ local b = self:isRTL()
+ if opposite then
+ b = not b
+ end
+ return b and '‏' or '‎'
+ end
+
+ function lang:getArrow( direction )
+ checkSelf( self, 'getArrow' )
+ direction = direction or 'forwards'
+ util.checkType( 'getArrow', 1, direction, 'string' )
+ if direction == 'forwards' then
+ return self:isRTL() and '←' or '→'
+ elseif direction == 'backwards' then
+ return self:isRTL() and '→' or '←'
+ elseif direction == 'left' then
+ return '←'
+ elseif direction == 'right' then
+ return '→'
+ elseif direction == 'up' then
+ return '↑'
+ elseif direction == 'down' then
+ return '↓'
+ end
+ end
+
return lang
end
--
To view, visit https://gerrit.wikimedia.org/r/52205
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I78db53976abfe04fd6529b36c9434e33a3bc90c7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits