X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FResources.php;h=54cfc95b4f18086dc3ec0d8d9b8565fd6b74f0df;hb=d09edf64e678a73669cff34014a55a06604de75a;hp=8baab9edf67ef841be823233f4c2835ac6d41f0b;hpb=13607d6e9346d7adeef72866afb4ded9046305d0;p=civicrm-core.git
diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php
index 8baab9edf6..744e5be721 100644
--- a/CRM/Core/Resources.php
+++ b/CRM/Core/Resources.php
@@ -1,29 +1,29 @@
'js-strings',
- 'prefetch' => FALSE,
- ));
+ 'group' => 'js-strings',
+ 'prefetch' => FALSE,
+ ));
self::$_singleton = new CRM_Core_Resources(
$sys->getMapper(),
$cache,
@@ -125,15 +125,17 @@ class CRM_Core_Resources {
}
/**
- * Construct a resource manager
+ * Construct a resource manager.
*
- * @param CRM_Extension_Mapper $extMapper Map extension names to their base path or URLs.
- * @param CRM_Utils_Cache_Interface $cache JS-localization cache
+ * @param CRM_Extension_Mapper $extMapper
+ * Map extension names to their base path or URLs.
+ * @param CRM_Utils_Cache_Interface $cache
+ * JS-localization cache.
* @param string|null $cacheCodeKey Random code to append to resource URLs; changing the code forces clients to reload resources
*/
public function __construct($extMapper, $cache, $cacheCodeKey = NULL) {
$this->extMapper = $extMapper;
- $this->cache = $cache;
+ $this->strings = new CRM_Core_Resources_Strings($cache);
$this->cacheCodeKey = $cacheCodeKey;
if ($cacheCodeKey !== NULL) {
$this->cacheCode = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, $cacheCodeKey);
@@ -149,17 +151,26 @@ class CRM_Core_Resources {
/**
* Add a JavaScript file to the current page using \n", $js);
}
@@ -294,7 +336,7 @@ class CRM_Core_Resources {
* Variable substitutions can happen from client-side
*
* Note: this function rarely needs to be called directly and is mostly for internal use.
- * @see CRM_Core_Resources::addScriptFile which automatically adds translated strings from js files
+ * See CRM_Core_Resources::addScriptFile which automatically adds translated strings from js files
*
* Simple example:
* // From php:
@@ -314,16 +356,23 @@ class CRM_Core_Resources {
* CRM_Core_Resources::singleton()->addSetting(array('myNamespace' => array('myString' => ts('Your %1 has been %2', array(subs)))));
* And from javascript access it at CRM.myNamespace.myString
*
- * @param $text string|array
+ * @param string|array $text
+ * @param string|NULL $domain
* @return CRM_Core_Resources
*/
- public function addString($text) {
+ public function addString($text, $domain = 'civicrm') {
foreach ((array) $text as $str) {
- $translated = ts($str);
+ $translated = ts($str, array(
+ 'domain' => ($domain == 'civicrm') ? NULL : array($domain, NULL),
+ ));
+
// We only need to push this string to client if the translation
// is actually different from the original
if ($translated != $str) {
- $this->addSetting(array('strings' => array($str => $translated)));
+ $bucket = $domain == 'civicrm' ? 'strings' : 'strings::' . $domain;
+ $this->addSetting(array(
+ $bucket => array($str => $translated),
+ ));
}
}
return $this;
@@ -332,10 +381,14 @@ class CRM_Core_Resources {
/**
* Add a CSS file to the current page using .
*
- * @param $ext string, extension name; use 'civicrm' for core
- * @param $file string, file path -- relative to the extension base dir
- * @param $weight int, relative weight within a given region
- * @param $region string, location within the file; 'html-header', 'page-header', 'page-footer'
+ * @param string $ext
+ * extension name; use 'civicrm' for core.
+ * @param string $file
+ * file path -- relative to the extension base dir.
+ * @param int $weight
+ * relative weight within a given region.
+ * @param string $region
+ * location within the file; 'html-header', 'page-header', 'page-footer'.
* @return CRM_Core_Resources
*/
public function addStyleFile($ext, $file, $weight = self::DEFAULT_WEIGHT, $region = self::DEFAULT_REGION) {
@@ -345,51 +398,62 @@ class CRM_Core_Resources {
/**
* Add a CSS file to the current page using .
*
- * @param $url string
- * @param $weight int, relative weight within a given region
- * @param $region string, location within the file; 'html-header', 'page-header', 'page-footer'
+ * @param string $url
+ * @param int $weight
+ * relative weight within a given region.
+ * @param string $region
+ * location within the file; 'html-header', 'page-header', 'page-footer'.
* @return CRM_Core_Resources
*/
public function addStyleUrl($url, $weight = self::DEFAULT_WEIGHT, $region = self::DEFAULT_REGION) {
CRM_Core_Region::instance($region)->add(array(
- 'name' => $url,
- 'type' => 'styleUrl',
- 'styleUrl' => $url,
- 'weight' => $weight,
- 'region' => $region,
- ));
+ 'name' => $url,
+ 'type' => 'styleUrl',
+ 'styleUrl' => $url,
+ 'weight' => $weight,
+ 'region' => $region,
+ ));
return $this;
}
/**
* Add a CSS content to the current page using