Coldbox 4.2 i18n module conflict

Hello,

I have a module that uses cbi18n, and the box.json file is in the dependencies part like this

`

“dependencies”:{

“cbi18n”:“1.0.2”,

“cbstorages”:“1.0.0”,

“cbmessagebox”:“1.0.0”,

“cbcommons”:“1.1.0”

},

“devDependencies”:{

“cbdebugger”:“1.1.0”

},

“installPaths”:{

“cbi18n”:“modules/cb-bundle/cbi18n”,

“cbdebugger”:“modules/cb-bundle/cbdebugger”,

“cbstorages”:“modules/cb-bundle/cbstorages”,

“cbmessagebox”:“modules/cb-bundle/cbmessagebox”,

“cbcommons”:“modules/cb-bundle/cbcommons”

}, …
`

Then in commandbox if I type install all those modules get installed in the specified cb-bundle directory and everything works fine, the i18n structure in the moduleConfig.cfc looks like this

`

i18n = {

// The base path of the default resource bundle to load

defaultResourceBundle = “#modulePath#/includes/i18n/canvas”,

// The default locale of the application valid es_MX|en_US

defaultLocale = “en_US”,//es_MX

// The storage to use for user’s locale: session, client, cookie, request

localeStorage = “cookie”,

// The value to show when a translation is not found

unknownTranslation = “NOT FOUND”,

}

`

Now, I have a second module that dependes on cbORM to perform some initial setup insertions in the db, and it has a chain of dependencies cbORM → cbValidation → cbi18n
When in commandbox you type install, those 3 modules get installed, then if I run the application I get this error

The LocaleStorage setting cannot be found. Please make sure you create the i18n elements.

and I can see the path to the cfc that is throwing the exception is this
modules/cborm/modules/cbvalidation/modules/cbi18n/models/i18n.cfc:102):102

Both modules have their i18n structure and in the config.cfc there is one too, why is not loading the settings?.
If I exclude the second module from loading in the app, the first one works fine, I think the reason is that the i18n module is duplicated because it was already installed with the first module, and the second module installed it automatically according to the dependencies.

If I delete the i18n folder inside cborm.cbvalidation I get this error.

The module has not been registered, register the module first and then activate it.

  1. In the first module I had to write these lines in the onLoad method to avoid errors like the last one.

`

controller.getModuleService().registerAndActivateModule(‘cbmessagebox’,’#this.cfmapping#.modules.cb-bundle’);

controller.getModuleService().registerAndActivateModule(‘cbi18n’,’#this.cfmapping#.modules.cb-bundle’);

controller.getModuleService().registerAndActivateModule(‘cbdebugger’,’#this.cfmapping#.modules.cb-bundle’);

`

What would be the best way to avoid this duplicity, to check if the module cbi18n (or any other module) is already installed and avoid reinstallation in a subfolder.?

Thanks,

Angel Chrystian Torres

I found that for using i18n per module you have to add an alias and use it in the getResource function.
No the moduleConfig.cfc i18n structure looks like this

moduleConfig.cfc

`
i18n = {

// The base path of the default resource bundle to load
defaultResourceBundle = “#modulePath#/includes/i18n/torugaSlider”,

// The default locale of the application valids es_MX|en_US
defaultLocale = “en_US”,//es_MX

// The storage to use for user’s locale: session, client, cookie, request
localeStorage = “cookie”,

// The value to show when a translation is not found
unknownTranslation = “NOT FOUND”,

//Alias
//In this case my alias name is torugaSlider
resourceBundles = {
torugaSlider = "#modulePath#/includes/i18n/torugaSlider"
}
};
`

And in any view or layout inside the module

`
$r(‘dark’,‘Oscuro’, getFwLocale(), ‘’, ‘torugaSlider’)

`

So the solution was in each module I define its respective alias in the i18n structure, and use it in their own views and layouts.

Thanks.

Hello

I got the same error… with CB4.1

in my shoppingcart module config I added as suggest from Angel:

i18n = {
// The base path of the default resource bundle to load

defaultResourceBundle = “#modulePath#/includes/i18n/main”,

defaultLocale = “de_CH”,
localeStorage = “cookie”,
unknownTranslation = “NOT FOUND

};

the file #modulePath#/includes/i18n/main_de_CH.properties is created

First I installed the cborm module, all worked OK. Than the cbstorages module and after a reinit:

when I browse to the module homepage it throws an error:

“The LocaleStorage setting cannot be found. Please make sure you create the i18n elements.”

“modules\cborm\modules\cbvalidation\modules\cbi18n\models\i18n.cfc”

any ideas?

Daniel

Hi Daniel,

Try adding this to your module i18n structure

`

// Extra resource bundles to load

i18n{
…,
resourceBundles = {

yourBundleAlias = “#modulePath#/includes/i18n/main”

}
}

`
This creates an alias that you can now reference in your views and/or layouts like this
$r(‘dark’,‘Oscuro’, getFwLocale(), ‘’, ‘yourBundleAlias’)

  • $r is a shortcut to getResource function

Make sure you have your resource bundle file inside includes/i18n folder in your module.

This setting looks for the file in the application’s includes folder so even when you specify “#modulePath#” it wont look into the module’s directory.
defaultResourceBundle = “#modulePath#/includes/i18n/main”,

Thanks.

Angel Chrystian

Hi Angel

thanks for the tipp, but it didin’t work for me.

The problem when th i18m modul configures the ‘instance.localeStorage’ value is empty…

The i18n module uses the afterConfigurationLoad interceptor event to read the i18n setting from other modules

var modules = controller.getSetting( “modules” );

for( var thisModule in modules ){
var oConfig = moduleConfigCache[ thisModule ];

var i18nSettings = oConfig.getPropertyMixin( “i18n”, “variables”, structnew() );

}

although I added the i18n setting in module config. When I dump it out inside “afterConfigurationLoad” method I can’t find a structure with i18n-setting thus it defaults and adds empty values.

my question would why the i18n settings in my modulConfig don’t appear and load in i18n.cfc

Daniel

Hi Daniel,

Yes you are right, I rencently ran accross the case you expose, while trying an application if I run it with CommandBox and Lucee, everything goes as expected, but if I run it in CF11 the i18n error occurs, this is an app in a subfolder of the root, perhaps something about mappings.
In CommandBox it runs as if the application is in the root.

Have you found a workaround to this?

Regards.

Angel ChrystianTorres

Hi Angel

Unfortunatly I did not find a clean solution…

Finally I hardcoded the values into init constructor of i18n.cfc

“// internal settings
instance.localeStorage = “session”;
instance.defaultResourceBundle = “/includes/i18n/main”;
instance.defaultLocale = “en_US”;”

that worked, but of course it would be nicer it the settings are read from the config…

Daniel

Did anybody every figure out the problem with this? I’ve fixed the error with the same solution, but like Daniel, I find it disheartening that the configuration is not being read from the config file