From 420b9c1885420721d93beb2d27c19b5b46ccca9c Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Mon, 22 Feb 2010 20:53:13 +0000
Subject: [PATCH] =?UTF-8?q?-=20Patch=20#332725=20by=20andypost,=20Damien?=
 =?UTF-8?q?=20Tournoud,=20lilou,=20G=C3=A1bor=20Hojtsy:=20locale=5Finc=5Fc?=
 =?UTF-8?q?allback()=20is=20a=20thing=20of=20the=20past.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 modules/field/tests/field.test |  3 ++-
 modules/locale/locale.module   | 19 ++++++-------------
 modules/locale/locale.test     |  7 ++++---
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test
index 7468653b1b2c..d25f120fcfd7 100644
--- a/modules/field/tests/field.test
+++ b/modules/field/tests/field.test
@@ -2576,8 +2576,9 @@ class FieldTranslationsTestCase extends FieldTestCase {
     field_create_instance($instance);
     $this->instance = field_read_instance('test_entity', $this->field_name, 'test_bundle');
 
+    require_once DRUPAL_ROOT . '/includes/locale.inc';
     for ($i = 0; $i < 3; ++$i) {
-      locale_inc_callback('locale_add_language', 'l' . $i, $this->randomString(), $this->randomString());
+      locale_add_language('l' . $i, $this->randomString(), $this->randomString());
     }
   }
 
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 7f308ff937ca..b091f12af644 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -272,16 +272,6 @@ function locale_init() {
   }
 }
 
-/**
- * Wrapper function to be able to set callbacks in locale.inc
- */
-function locale_inc_callback() {
-  $args = func_get_args();
-  $function = array_shift($args);
-  include_once DRUPAL_ROOT . '/includes/locale.inc';
-  return call_user_func_array($function, $args);
-}
-
 /**
  * Implements hook_permission().
  */
@@ -766,6 +756,9 @@ function locale_js_alter(&$javascript) {
   $parsed = variable_get('javascript_parsed', array());
   $files = $new_files = FALSE;
 
+  // Require because locale_js_alter() could be called without locale_init().
+  require_once DRUPAL_ROOT . '/includes/locale.inc';
+
   foreach ($javascript as $item) {
     if ($item['type'] == 'file') {
       $files = TRUE;
@@ -773,7 +766,7 @@ function locale_js_alter(&$javascript) {
       if (!in_array($filepath, $parsed)) {
         // Don't parse our own translations files.
         if (substr($filepath, 0, strlen($dir)) != $dir) {
-          locale_inc_callback('_locale_parse_js_file', $filepath);
+          _locale_parse_js_file($filepath);
           $parsed[] = $filepath;
           $new_files = TRUE;
         }
@@ -785,14 +778,14 @@ function locale_js_alter(&$javascript) {
   // JavaScript translation files for all languages, adding the refresh
   // flags into the existing array.
   if ($new_files) {
-    $parsed += locale_inc_callback('_locale_invalidate_js');
+    $parsed += _locale_invalidate_js();
   }
 
   // If necessary, rebuild the translation file for the current language.
   if (!empty($parsed['refresh:' . $language->language])) {
     // Don't clear the refresh flag on failure, so that another try will
     // be performed later.
-    if (locale_inc_callback('_locale_rebuild_js')) {
+    if (_locale_rebuild_js()) {
       unset($parsed['refresh:' . $language->language]);
     }
     // Store any changes after refresh was attempted.
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 4bfb09cc7a59..33fc3ab4a99c 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -334,7 +334,8 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
     $this->drupalPost($url, $edit, t('Save translations'));
 
     // Trigger JavaScript translation parsing and building.
-    locale_inc_callback('_locale_rebuild_js', $langcode);
+    require_once DRUPAL_ROOT . '/includes/locale.inc';
+    _locale_rebuild_js($langcode);
 
     // Retrieve the JavaScript translation hash code for the custom language to
     // check that the translation file has been properly built.
@@ -350,7 +351,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
     file_unmanaged_delete($js_file);
     $this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found'))));
     cache_clear_all();
-    locale_inc_callback('_locale_rebuild_js', $langcode);
+    _locale_rebuild_js($langcode);
     $this->assertTrue($result = file_exists($js_file), t('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : t('not found'))));
   }
 
@@ -1534,7 +1535,7 @@ class UILanguageNegotiationTest extends DrupalWebTestCase {
     $language_domain = 'example.cn';
 
     // Setup the site languages by installing two languages.
-    require_once('includes/locale.inc');
+    require_once DRUPAL_ROOT . '/includes/locale.inc';
     locale_add_language($language_browser_fallback);
     locale_add_language($language);
 
-- 
GitLab