/**
  * Determine the best module to be given ownership over this key
  *
  * @param array $entitiesByModule
  * @param string $key
  * @return string Best module, if found
  */
 protected function getBestModuleForKey($entitiesByModule, $key)
 {
     // Check classes
     $class = current(explode('.', $key));
     $owner = i18n::get_owner_module($class);
     if ($owner) {
         return $owner;
     }
     // @todo - How to determine ownership of templates? Templates can
     // exist in multiple locations with the same name.
     // Display notice if not found
     Debug::message("Duplicate key {$key} detected in multiple modules with no obvious owner", false);
     // Fall back to framework then cms modules
     foreach (array('framework', 'cms') as $module) {
         if (isset($entitiesByModule[$module][$key])) {
             return $module;
         }
     }
     // Do nothing
     return null;
 }
示例#2
0
 /**
  * Provide menu titles to the i18n entity provider
  */
 function provideI18nEntities()
 {
     $cmsClasses = self::get_cms_classes();
     $entities = array();
     foreach ($cmsClasses as $cmsClass) {
         $defaultTitle = LeftAndMain::menu_title_for_class($cmsClass);
         $ownerModule = i18n::get_owner_module($cmsClass);
         $entities["{$cmsClass}.MENUTITLE"] = array($defaultTitle, PR_HIGH, 'Menu title', $ownerModule);
     }
     return $entities;
 }
 /**
  * Given a partial class name, attempt to determine the best module to assign strings to.
  *
  * @param string $class Either a FQN class name, or a non-qualified class name.
  * @return string Name of module
  */
 protected function findModuleForClass($class)
 {
     if (ClassInfo::exists($class)) {
         return i18n::get_owner_module($class);
     }
     // If we can't find a class, see if it needs to be fully qualified
     if (strpos($class, '\\') !== false) {
         return null;
     }
     // Find FQN that ends with $class
     $classes = preg_grep('/' . preg_quote("\\{$class}", '\\/') . '$/i', SS_ClassLoader::instance()->getManifest()->getClassNames());
     // Find all modules for candidate classes
     $modules = array_unique(array_map(function ($class) {
         return i18n::get_owner_module($class);
     }, $classes));
     if (count($modules) === 1) {
         return reset($modules);
     }
     // Couldn't find it! Exists in none, or multiple modules.
     return null;
 }