- Download the file and put it in your projects model directory, so the url to this CFC would be http://yourlocalproject/model/resourcebundle.cfc.
- Also in your model directory create new folder called "locale_data" and in there add a file called en_US.properties.
- Open up resourceBundle.cfc and change the method(function) "loadResourceBundle" to "init". The reason for this is that we are going to get ColdSpring to inject our required variables into the resource bundle.
- Then around line 53 look for the following bit of code
and change it to
- Next open up your ColdSpring.xml file and add the following:
What we are doing here is initiated the resourcebundle.cfc and passing two arguments to the init method. These arguments consist of the:
rbFile: This must be the path + filename UP to but NOT including the locale. We auto-add .properties to the end. This location is the file we created in point 2.
rbLocale: The locale.
- Then we are going to inject this into our controller and to do this add the following code snippet to your ColdSpring.xml File:
and in your Model Glue controller add
- At this point a lot of the hard work is done. Point 1-3 were just about setting up our environment and 4-6 were about some modification to get everything to play together nicely.
- We'll carry on with the controller. Because we have injected the resourcebundle.cfc in the Controller we can access it via the variable "variables.resourcebundle" and assign it to the viewState with the following code in the onRequestStart function:
- Lets populate the en_US.properties file with the following before we go any further:
name=Namedob=Date Of birthelevator=elevatorcigarette=cigarettesidewalk=sidewalkIf you haven't used blogCFC or the resoucebundle then you probably should know that the for each language/region you need to create a new .properties file with the relevant prefix(from the CFMX's locales) and values. So for France the prefix would be fr_FR and UK(English) file would be called en_GB.properties, and the content would be something like:
name=Namedob=Date Of birthelevator=liftcigarette=fagsidewalk=pavement
- All we need to do now is get the variable we set earlier in OnRequestStart at point xxxxxxxxxxx. Anyone familiar with MG should know this already
- Now that the resourcebundle is referenced to the "rb" variable we use the method "getResource" to access our .properties file and retrieve the translations. So in your view file the final code to display the users name and dob will then look something like
#rg.getResource('dob')#: #dateFormat(dob, 'dd-mm-yyyy')#