diff --git a/lib/I18n.php b/lib/I18n.php index 287e2a00..14c109bf 100644 --- a/lib/I18n.php +++ b/lib/I18n.php @@ -297,6 +297,19 @@ class I18n return in_array(self::$_language, array('ar', 'he')); } + /** + * get OS-specific copy hotkey modifier key name based on user agent + * + * @access public + * @static + * @return string 'Cmd' on macOS, 'Ctrl' otherwise + */ + public static function getCopyHotkey() + { + return isset($_SERVER['HTTP_USER_AGENT']) && + strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ? 'Cmd' : 'Ctrl'; + } + /** * set the default language * diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 9a542234..4a60b534 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -626,8 +626,7 @@ endif;
%s (Hit %s+c to copy)', $SHORTURL, $SHORTURL, $hotkey); + echo I18n::_('Your document is %s (Hit %s+c to copy)', $SHORTURL, $SHORTURL, I18n::getCopyHotkey()); ?>
assertEquals('Cmd', I18n::getCopyHotkey(), 'returns Cmd on macOS'); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'; + $this->assertEquals('Ctrl', I18n::getCopyHotkey(), 'returns Ctrl on Windows'); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64)'; + $this->assertEquals('Ctrl', I18n::getCopyHotkey(), 'returns Ctrl on Linux'); + + unset($_SERVER['HTTP_USER_AGENT']); + $this->assertEquals('Ctrl', I18n::getCopyHotkey(), 'returns Ctrl when user agent absent'); + } + public function testMessageIdsExistInAllLanguages() { $messageIds = array();