示例#1
0
 public function testCheckLanguageKeyExists()
 {
     $translator = new Translator();
     $translator->addTranslation('en', array('__elgg_php_unit:test_key' => 'Dummy'));
     $this->assertTrue($translator->languageKeyExists('__elgg_php_unit:test_key'));
     $this->assertFalse($translator->languageKeyExists('__elgg_php_unit:test_key:missing'));
 }
示例#2
0
 /**
  * Get body for the notification
  *
  * Plugin can define a subtype specific body simply by providing a
  * translation for the string "notification:body:<action>:<type>:<subtype".
  *
  * For example in mod/blog/languages/en.php:
  *
  *    'notification:body:publish:object:blog' => '
  *         Hi %s!
  *
  *         %s has created a new post called "%s" in the group %s.
  *
  *         It says:
  *
  *         "%s"
  *
  *         You can comment the post here:
  *         %s
  *     ',
  *
  * The arguments passed into the translation are:
  *     1. Recipient's name
  *     2. Name of the user who triggered the notification
  *     3. Title of the content
  *     4. Name of the content's container
  *     5. The actual content (entity's 'description' field)
  *     6. URL to the content
  *
  * Argument swapping can be used to change the order of the parameters.
  * See http://php.net/manual/en/function.sprintf.php#example-5427
  *
  * @param NotificationEvent $event     Notification event
  * @param ElggUser          $recipient Notification recipient
  * @return string Notification body in the recipient's language
  */
 private function getNotificationBody(NotificationEvent $event, ElggUser $recipient)
 {
     $actor = $event->getActor();
     $object = $event->getObject();
     /* @var \ElggObject $object */
     $language = $recipient->language;
     // Check custom notification body for the action/type/subtype combination
     $body_key = "notification:{$event->getDescription()}:body";
     if ($this->translator->languageKeyExists($body_key, $language)) {
         if ($object instanceof \ElggEntity) {
             $display_name = $object->getDisplayName();
             $container_name = '';
             $container = $object->getContainerEntity();
             if ($container) {
                 $container_name = $container->getDisplayName();
             }
         } else {
             $display_name = '';
             $container_name = '';
         }
         return $this->translator->translate($body_key, array($recipient->name, $actor->name, $display_name, $container_name, $object->description, $object->getURL()), $language);
     }
     // Fall back to default body
     return $this->translator->translate('notification:body', array($object->getURL()), $language);
 }
示例#3
0
 public function setUp()
 {
     $this->actionsDir = dirname(dirname(__FILE__)) . "/test_files/actions";
     $session = ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
     $config = $this->config();
     _elgg_services()->setValue('config', $config);
     $this->input = new Input();
     _elgg_services()->setValue('input', $this->input);
     $this->actions = new ActionsService($config, $session, _elgg_services()->crypto);
     _elgg_services()->setValue('actions', $this->actions);
     $this->request = $this->prepareHttpRequest();
     _elgg_services()->setValue('request', $this->request);
     $this->translator = new Translator();
     $this->translator->addTranslation('en', ['__test__' => 'Test']);
     $this->hooks = new PluginHooksService();
     $this->system_messages = new SystemMessagesService(elgg_get_session());
     _elgg_services()->logger->disable();
 }
示例#4
0
文件: RouterTest.php 项目: elgg/elgg
 function setUp()
 {
     $this->pages = dirname(dirname(__FILE__)) . '/test_files/pages';
     $this->fooHandlerCalls = 0;
     $session = ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
     $config = $this->config();
     _elgg_services()->setValue('config', $config);
     $this->input = new Input();
     _elgg_services()->setValue('input', $this->input);
     $this->request = $this->prepareHttpRequest('', 'GET');
     _elgg_services()->setValue('request', $this->request);
     $this->translator = new Translator();
     $this->translator->addTranslation('en', ['__test__' => 'Test']);
     $this->hooks = new PluginHooksService();
     $this->router = new Router($this->hooks);
     $this->system_messages = new SystemMessagesService(elgg_get_session());
     $this->viewsDir = dirname(dirname(__FILE__)) . "/test_files/views";
     $this->createService();
     _elgg_services()->logger->disable();
 }
示例#5
0
 /**
  * Upgrades Elgg Database and code
  *
  * @return bool
  */
 protected function processUpgrades()
 {
     $dbversion = (int) $this->datalist->get('version');
     if ($this->upgradeCode($dbversion)) {
         system_message($this->translator->translate('upgrade:core'));
         // Now we trigger an event to give the option for plugins to do something
         $upgrade_details = new \stdClass();
         $upgrade_details->from = $dbversion;
         $upgrade_details->to = elgg_get_version();
         $this->events->trigger('upgrade', 'upgrade', $upgrade_details);
         return true;
     }
     return false;
 }
示例#6
0
文件: EntityTable.php 项目: elgg/elgg
 /**
  * Get a user by GUID even if the entity is hidden or disabled
  *
  * @param int $guid User GUID. Default is logged in user
  *
  * @return ElggUser|false
  * @throws UserFetchFailureException
  * @access private
  */
 public function getUserForPermissionsCheck($guid = 0)
 {
     if (!$guid) {
         return $this->session->getLoggedInUser();
     }
     // need to ignore access and show hidden entities for potential hidden/disabled users
     $ia = $this->session->setIgnoreAccess(true);
     $show_hidden = access_show_hidden_entities(true);
     $user = $this->get($guid, 'user');
     $this->session->setIgnoreAccess($ia);
     access_show_hidden_entities($show_hidden);
     if (!$user) {
         // requested to check access for a specific user_guid, but there is no user entity, so the caller
         // should cancel the check and return false
         $message = $this->translator->translate('UserFetchFailureException', array($guid));
         $this->logger->warn($message);
         throw new UserFetchFailureException();
     }
     return $user;
 }
示例#7
0
/**
 * Initializes simplecache views for translations
 * 
 * @return void
 */
function _elgg_translations_init()
{
    $translations = \Elgg\I18n\Translator::getAllLanguageCodes();
    foreach ($translations as $language_code) {
        // make the js view available for each language
        elgg_extend_view("js/languages/{$language_code}.js", "js/languages");
        // register the js view for use in simplecache
        elgg_register_simplecache_view("js/languages/{$language_code}.js");
    }
}
示例#8
0
 public function testDoesNotProcessArgsOnKey()
 {
     $this->assertEquals('nonexistent:%s', $this->translator->translate('nonexistent:%s', [1]));
 }