View Issue Details

IDProjectCategoryView StatusLast Update
0012759mantisbtplug-inspublic2014-09-23 18:05
Reportersveyret Assigned Todregad  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.4 
Target Version1.2.7Fixed in Version1.2.7 
Summary0012759: Error loading language string when plugin is not current
Description

If plugin_lang_get is called from a plugin with the optional $p_basename parameter, the function will build the full string name accordingly, then call lang_get.
But in lang_get, if the string is not found, which likely will be the case for a plug-in, the function is doing plugin_get_current() to load the appropriate language file.
In most of the cases, it will work, either because the plugin language file is already loaded, or because plugin_lang_get is called from inside the plug-in. But in some specific cases, when outside plugin and plugin strings not loaded yet, the function will fail.

Steps To Reproduce
  1. Create a plug-in which defines a filter.
  2. In the filter constructor, call plugin_lang_get to get a localized string for the name of the filtered field.
  3. Select "english" in your preferences (could not state why it was working with "auto" or another selected language but "english").
  4. Go to "View bugs". The filter constructor is called, but the plug-in is not active. You should then get a warning message saying it did not find the string.
Tagspatch
Attached Files
plugin_lang_get.patch (1,232 bytes)   
From 63a288c1010754852473d448703304d36a30854a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=82phane=20Veyret?= <sveyret@axway.com>
Date: Thu, 10 Feb 2011 14:58:57 +0100
Subject: [PATCH] 12759: Error loading language string when plugin is not current

---
 core/plugin_api.php |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/core/plugin_api.php b/core/plugin_api.php
index e4188f8..cdeaae0 100644
--- a/core/plugin_api.php
+++ b/core/plugin_api.php
@@ -228,15 +228,18 @@ function plugin_config_defaults( $p_options ) {
  * @return string Language string
  */
 function plugin_lang_get( $p_name, $p_basename = null ) {
-	if( is_null( $p_basename ) ) {
-		$t_basename = plugin_get_current();
-	} else {
-		$t_basename = $p_basename;
+	if( !is_null( $p_basename ) ) {
+		plugin_push_current( $p_basename );
 	}
 
+	$t_basename = plugin_get_current();
 	$t_name = 'plugin_' . $t_basename . '_' . $p_name;
+	$t_string = lang_get( $t_name );
 
-	return lang_get( $t_name );
+	if( !is_null( $p_basename ) ) {
+		plugin_pop_current();
+	}
+	return $t_string;
 }
 
 function plugin_history_log( $p_bug_id, $p_field_name, $p_old_value, $p_new_value = '', $p_user_id = null, $p_basename = null ) {
-- 
1.7.1

plugin_lang_get.patch (1,232 bytes)   

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

sveyret

sveyret

2011-02-10 09:02

reporter   ~0028200

Added a patch built against branch master-1.2.x which push/pop the plug-in if basename is given while getting the string.

dregad

dregad

2011-07-28 12:00

developer   ~0029320

Hi Stéphane,

I just committed your patch, thanks for your contribution !

As a side and unrelated note, I got the following warning while applying it:

$ git am -s /tmp/plugin_lang_get.patch
Applying: 12759: Error loading language string when plugin is not current
Warning: commit message does not conform to UTF-8.
You may want to amend it after fixing the message, or set the config
variable i18n.commitencoding to the encoding your project uses.

And then in the git log your name shows up like this:
Author: St<82>phane Veyret <sveyret@nospam.com>

I edited the patch file to put the "é" and then everything was fine. Not sure what is causing this, if it's on your end or mine.

dregad

dregad

2011-07-28 12:03

developer   ~0029321

Last edited: 2011-07-28 12:58

Oh, and one more thing: in your commit message, when referencing a bug on the tracker, please make sure to prepend a "#" before the bug ID, this way the commit gets picked up automatically by source control plugin

Something like Fix #00000

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036419

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master-1.2.x 4c9eb5a2

2011-02-10 00:58

sveyret


Details Diff
12759: Error loading language string when plugin is not current

Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
Affected Issues
0012759
mod - core/plugin_api.php Diff File

MantisBT: master 9dda347b

2011-02-10 00:58

sveyret


Details Diff
12759: Error loading language string when plugin is not current

Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
Affected Issues
0012759
mod - core/plugin_api.php Diff File