Bug in i18n ResourceBundle for unknown translation?

The logic inside ResourceBundle.cfc seems to suggest that if the
UnknownTranslation setting is not present, the raw string
_UNKNOWNTRANSLATION_ will be returned but that does not seem to be the
case.

Because ColdBox sets a default string of "" for the UnknownTranslation
setting, the logic in the ResourceBundle thinks the setting *is*
present and returns it's (empty) value:

          if( settingExists('UnknownTranslation') ){ return
getSetting("UnknownTranslation"); }

Consequently, _UNKNOWNTRANSLATION_ is never returned - and an empty
string is returned instead.

This seems to be a bug but I'm not sure whether it's:
a. A bug in how the UnknownTranslation setting is defaulted in the
loader (two places).
b. A bug in how settingExists() behaves - should it be true for an
empty (default) setting?
c. A bug in how unknown translations are handled.

All the config settings appear to be defaulted the same way which
suggests the bug is b. or c.

For now I can work around this by setting
<UnknownTranslation>_UNKNOWNTRANSLATION_</UnknownTranslation> but that
seems a bit redundant :slight_smile:

Thanks Sean,

I agree with your excellent explanation. I wish everybody reported things like you do! :slight_smile:

I have logged it and just in time for M4. It should check if its empty. If it is, then return the default one.

Thanks again.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Luis,

I used to do it like this:

Remove the <UnknownTranslation>_UNKNOWNTRANSLATION_</UnknownTranslation>
from config.xml
and replace line 183 in resourceBundle.cfc with <cfreturn "{" &
arguments.resource & "}">

This way it's easy to see which rb key is missing in rb.

Ernst

You know that (in 3.0.0) you can add a
coldbox.system.extensions.plugins.ResourceBundle CFC that extends
coldbox.system.plugins.ResourceBundle and overrides only the
getResource() method - and then handle the modification of the result
that way?

Here's what I have:

<cfcomponent extends="coldbox.system.plugins.ResourceBundle"
       output="false"
       cache="true"
       cachetimeout="0">

  <cffunction name="getResource" access="public" output="false"
returnType="any" hint="Returns bundle resource from loaded bundle, if
it exists, according to locale. To get a resource string from non
loaded RB's, use getRBString">
    <cfargument name="resource" type="any" required="true" hint="The
resource to retrieve from the loaded bundle.">
    <cfargument name="default" type="any" required="false" hint="A
default value to send back if resource not found" >
    <cfargument name="locale" type="any" required="false"
default="#getfwLocale()#" hint="Pass in which locale to take the
resource from. By default it uses the user's current set locale" >
    <cfscript>
      var result = super.getResource( argumentCollection = arguments );
      
      // Our debugging variant:
      if ( result is '_UNKNOWNTRANSLATION_' ) {
        return '**' & arguments.resource & '**';
      }
      
      // Since we don't use default in getResource() calls, we should
trap such usage:
      if ( structKeyExists( arguments, 'default' ) ) {
        $throw( 'i18n ResourceBundle getResource() call has default value!',
          'Perhaps you accidentally called getResource() with a second
positional argument instead of using named arguments?' );
      }
      
      // Special debugging logic for Mike:
      if ( structKeyExists( URL, 'debugi18n' ) ) cookie.debugi18n = URL.debugi18n;
      if ( structKeyExists( cookie, 'debugi18n' ) and cookie.debugi18n )
return '[[' & arguments.resource & ']]';
      
      // Return Resource
      return result;
    </cfscript>
  </cffunction>

</cfcomponent>

This way there are no changes to the ColdBox core files!

Any missing resources are replaced by **key** and we have a debugging
flag to show existing resources as [[key]] so that we can tell the
difference between static text (bad) and dynamic text (good). Also, we
require no default values in calls to getResource() so we've added a
test for that.

We also have a domain-based skinning system that uses a Renderer.cfc
(again in /coldbox/system/extensions/plugins) that extends the core
Renderer.cfc and just overrides locateView() and locateLayout() (now
that Luis has refactored the system Renderer!). It's not quite as
clean since we've had to copy the existing methods and just modify
part of them but it's much cleaner than what we were doing before Luis
made those changes recently :slight_smile:

WOOOt!!

I still have not forgetten about your ticket for the bundle Sean. I just have it scheduled for M5. I will let you know when it is done as I might ask you some more questions about it.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com