currently I’m having users module in my application. I’m getting text from resource bundles and I have no issue when below code is in layers.
We are integrating service and DAO layers for this application I moved this code to root/model/home/homeService.cfc and I’m getting Getresource is undefined error.
Please provide any solution for this and Do I need to change any settings in modules if I moved these code into modules.
That is because getResource() and other convenience methods are part of the framework super type and are only defined in “framework” files such as handlers, views, layouts, interceptors, and plugins. Your models are separate from the framework, but they can still access anything you want. You just need to inject the plugin and call the getResource() method on it like so.
public string function usertext() {
return rb.getResource( ‘userattn’ );
}
}
Note, when you upgrade to ColdBox 4, the i18n functionality is all part of a module and instead of injecting a plugin, you’ll inject a model named “resourceBundle@i18n”.
Do I need to inject anything for getsetting(‘lang’) also.
I’m having lang variable in coldbox.cfc and please suggest me best practice that where I need to add my custom variables in config.cfc.
Now, if I may offer some commentary/questions on your approach…
Are you sure you want to store the language in a setting. Settings are application-scoped and shared by all users. Usually the current locale is on a per-user basis and the getResource() function takes care of all that.
I noticed you are passing the “lang” setting in as the second parameter, which is not the language, but the default value. Is that what you wanted to do?
Thanks!