From 717e3acd9bfa816e7ebe75c1a4d468995eba2acb Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 13:34:52 +0100 Subject: [PATCH 1/7] autoload app's js translations --- lib/private/util.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/private/util.php b/lib/private/util.php index d2d286fc11e..2f2d7fb9ed3 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -10,6 +10,7 @@ class OC_Util { public static $headers = array(); private static $rootMounted = false; private static $fsSetup = false; + private static $loadedScriptTranslations = array(); private static function initLocalStorageRootFS() { // mount local file backend as root @@ -362,6 +363,12 @@ class OC_Util { public static function addScript($application, $file = null) { $path = OC_Util::generatePath($application, 'js', $file); if (!in_array($path, self::$scripts)) { + // load javascript translations if it is the first time an app's + // script is loaded. + if (!in_array($application, self::$loadedScriptTranslations)) { + self::addTranslations($application); + self::$loadedScriptTranslations[] = $application; + } self::$scripts[] = $path; } } From 8cb60b23660c284cf59280e31b1e262dfdb2cf4e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 13:39:29 +0100 Subject: [PATCH 2/7] make translation lookup faster (O(n) -> O(1)) --- lib/private/util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/util.php b/lib/private/util.php index 2f2d7fb9ed3..5db33776173 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -365,9 +365,9 @@ class OC_Util { if (!in_array($path, self::$scripts)) { // load javascript translations if it is the first time an app's // script is loaded. - if (!in_array($application, self::$loadedScriptTranslations)) { + if (!isset(self::$loadedScriptTranslations[$application])) { self::addTranslations($application); - self::$loadedScriptTranslations[] = $application; + self::$loadedScriptTranslations[$application] = true; } self::$scripts[] = $path; } From d6f1ff79933447975127acc1961905afa5783840 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 13:48:21 +0100 Subject: [PATCH 3/7] only load translsations for apps --- lib/private/util.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/private/util.php b/lib/private/util.php index 5db33776173..54e4f2b1d2e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -365,7 +365,9 @@ class OC_Util { if (!in_array($path, self::$scripts)) { // load javascript translations if it is the first time an app's // script is loaded. - if (!isset(self::$loadedScriptTranslations[$application])) { + if (!isset(self::$loadedScriptTranslations[$application]) && $file) { + error_log("adding " . $application . " " . $file); + self::addTranslations($application); self::$loadedScriptTranslations[$application] = true; } From 87f81e592620c753061de7f09e14a2c974ee5c79 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 14 Jan 2015 14:36:23 +0100 Subject: [PATCH 4/7] Remove unneeded addTranslations() calls --- apps/files/index.php | 1 - apps/files_encryption/appinfo/app.php | 1 - apps/files_external/appinfo/app.php | 2 -- apps/files_sharing/appinfo/app.php | 1 - apps/files_trashbin/appinfo/app.php | 2 -- apps/files_versions/appinfo/app.php | 1 - apps/user_ldap/appinfo/app.php | 1 - apps/user_webdavauth/appinfo/app.php | 2 -- 8 files changed, 11 deletions(-) diff --git a/apps/files/index.php b/apps/files/index.php index 767cb156ca2..fe2cd4f5543 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -29,7 +29,6 @@ OCP\User::checkLoggedIn(); OCP\Util::addStyle('files', 'files'); OCP\Util::addStyle('files', 'upload'); OCP\Util::addStyle('files', 'mobile'); -OCP\Util::addTranslations('files'); OCP\Util::addscript('files', 'app'); OCP\Util::addscript('files', 'file-upload'); OCP\Util::addscript('files', 'jquery.iframe-transport'); diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index f2dc63c340d..842b1a1ff27 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -1,6 +1,5 @@ getL10N('files_trashbin'); -OCP\Util::addTranslations('files_trashbin'); - // register hooks \OCA\Files_Trashbin\Trashbin::registerHooks(); diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index ae29bceb37c..e13dc64c46e 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -1,6 +1,5 @@ 0) { OC_Group::useBackend($groupBackend); } -OCP\Util::addTranslations('user_ldap'); OCP\Backgroundjob::registerJob('OCA\user_ldap\lib\Jobs'); OCP\Backgroundjob::registerJob('\OCA\User_LDAP\Jobs\CleanUp'); diff --git a/apps/user_webdavauth/appinfo/app.php b/apps/user_webdavauth/appinfo/app.php index 125f5f40654..3cd227bddbe 100644 --- a/apps/user_webdavauth/appinfo/app.php +++ b/apps/user_webdavauth/appinfo/app.php @@ -28,8 +28,6 @@ OC_APP::registerAdmin('user_webdavauth', 'settings'); OC_User::registerBackend("WEBDAVAUTH"); OC_User::useBackend( "WEBDAVAUTH" ); -OCP\Util::addTranslations('user_webdavauth'); - // add settings page to navigation $entry = array( 'id' => "user_webdavauth_settings", From 1cce1f0e6b9eb4ba6bbee4535076b523c97237ca Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 14:42:19 +0100 Subject: [PATCH 5/7] dont load core scritps --- lib/private/util.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/private/util.php b/lib/private/util.php index 54e4f2b1d2e..13208911f4e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -365,7 +365,7 @@ class OC_Util { if (!in_array($path, self::$scripts)) { // load javascript translations if it is the first time an app's // script is loaded. - if (!isset(self::$loadedScriptTranslations[$application]) && $file) { + if (!isset(self::$loadedScriptTranslations[$application]) && $file && $application !== 'core') { error_log("adding " . $application . " " . $file); self::addTranslations($application); @@ -406,7 +406,9 @@ class OC_Util { $path = "l10n/$languageCode"; } if (!in_array($path, self::$scripts)) { + error_log("translation " . $path); self::$scripts[] = $path; + error_log(print_r(self::$scripts, true)); } } From 4ec4914bb4ad6ef161e9093ec1d76573626c9367 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 14:57:56 +0100 Subject: [PATCH 6/7] move check into addTranslation method --- lib/private/util.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/private/util.php b/lib/private/util.php index 13208911f4e..f544b7b6b3e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -10,7 +10,6 @@ class OC_Util { public static $headers = array(); private static $rootMounted = false; private static $fsSetup = false; - private static $loadedScriptTranslations = array(); private static function initLocalStorageRootFS() { // mount local file backend as root @@ -363,14 +362,7 @@ class OC_Util { public static function addScript($application, $file = null) { $path = OC_Util::generatePath($application, 'js', $file); if (!in_array($path, self::$scripts)) { - // load javascript translations if it is the first time an app's - // script is loaded. - if (!isset(self::$loadedScriptTranslations[$application]) && $file && $application !== 'core') { - error_log("adding " . $application . " " . $file); - - self::addTranslations($application); - self::$loadedScriptTranslations[$application] = true; - } + self::addTranslations($application); self::$scripts[] = $path; } } @@ -406,9 +398,7 @@ class OC_Util { $path = "l10n/$languageCode"; } if (!in_array($path, self::$scripts)) { - error_log("translation " . $path); self::$scripts[] = $path; - error_log(print_r(self::$scripts, true)); } } From 6737dd111d582973abd3f40651d4d38ca5576df3 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 Jan 2015 15:27:37 +0100 Subject: [PATCH 7/7] ignore core --- lib/private/util.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/util.php b/lib/private/util.php index f544b7b6b3e..3b943f046bf 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -362,7 +362,10 @@ class OC_Util { public static function addScript($application, $file = null) { $path = OC_Util::generatePath($application, 'js', $file); if (!in_array($path, self::$scripts)) { - self::addTranslations($application); + // core js files need separate handling + if ($application !== 'core' && $file !== null) { + self::addTranslations($application); + } self::$scripts[] = $path; } }