Hey all –

 

I purposely didn’t add any multi-lingual support into reactor.  I don’t think its reactor’s responsibility.  Furthermore, there are a lot of pre-existing systems which are very good at it. 

 

My plans for i18n was to add content keys into the xml, rather than the actual message.  For example:

 

<teacherId>

            <label>TeacherIdLabel</label>

            <comment>TeacherIdComment</label>

            <notProvided>TecherIdNotProvided</notProvided>

            .. etc..

</teacherId>

 

You can still use the Dictionary.getValue(“teacherId.label”) to get this key, which you can pass to whatever you use for internationalization.

 

For example, I have a ContentFacade with a method to get content for the configured locale.  I could get the localized label by doing something like this:

 

ContentFacade.getContent(Dictionary.getValue(“teacherId.label”))

 

Once thing I’m thinking about doing is creating an interface-based system which would let you inject a localization object into the dictionary.  This might make the dictionary call a standard method on the object to get the localized version of a specific message.

 

Let’s say that do this.  I might add a method called “setTranslator” to the dictionary which you could pass any cfc to.  When you call getContent() it would get the value and then pass it into the Translator’s translate() method and would return the results.  This would let you create a façade to your i18n system and reactor wouldn’t care at all.

 

More thoughts?  Keep em’ commin’.

 

(I’ll think about the dtd or xsd suggestion.)

 

Doug

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Clayton Partridge
Sent: Friday, March 10, 2006 1:31 PM
To: [email protected]
Subject: Re: [Reactor For CF] Update to validation

 

The new Dictionary object is very cool. 

I have one suggestion, and one request regarding the dictionary xml file.

 

Everything will function great just the way you have described. 

I think it might better if the column names were a attribute of a element rather than the element name though. 

For instance something like:

 

<dictionary>

            <item name="teacherId">

                        <label>teacherId</label>

                        <comment/>

                        <notProvided>The teacherId field is required but was not provided.</notProvided>

                        <invalidType>The teacherId field does not contain valid data.  This field must be a numeric value.</invalidType>

            </item>

That way a dtd or xsd can be made for the xml file format.

 

I'd also like to ask for multilingual support. It's a big issue for most large Canadian sites, most apps I build have to work in French and English. I can think of situations in other countries where many more languages than that might have to be supported as well. Maybe this could be done by adding a "lang" attribute to each of the tags that contain text with the value being a standard (ISO?) language code. Something like:

 

<notProvided lang="en">The teacherId field is required but was not provided.</notProvided>

 

Getting the result in the appropriate language could be returned by calling validate with a argument like record.validate("en"). The argument should probably be optional. So that if it wasn't provided validate would just return items without a lang attriubute, a lang attribute of "en", or there could even be a way of defining a default language in the configuration xml file, or dictionary xml file.

 

Clayton

 

 

On 10-Mar-06, at 12:54 PM, Doug Hughes wrote:



 

Hey all,

 

I just committed a large change to validation. In the past there was an ErrorManager that would read data from the ErrorMessages.xml.  There were a few problems with this:

 

1)       All data for all objects was stored in one big file.

 

3)       More, but I’m too lazy to get into it.

 

I’ve added a new type of object, a Dictionary to Reactor.  You can now, if need be, call createDictionary(name) on the reactorFactory.  This will return a very simple reactor.dictionary.dictionary object which has one method, getValue(). 

 

The dictionary object reads a dictionary xml file stored under /yourDataMapping/Dictionary/yourObjectNamedictionary.xml.  Each dictionary XML file is created for one type of object and has a structure like this:

 

<dictionary>

            <teacherId>

                        <label>teacherId</label>

                        <comment/>

                        <notProvided>The teacherId field is required but was not provided.</notProvided>

                        <invalidType>The teacherId field does not contain valid data.  This field must be a numeric value.</invalidType>

            </teacherId>

            … (more nodes for each field) …

</dictionary>

 

The teacherId node represents one field.   You can get messages out of the dictionary with the Dictionary object’s getValue method.  For example:

 

MyDictionary.getValue(“teacherId.label”)

 

That will return the label text. 

 

MyDictionary.getValue(“teacherId.invalidType”)

 

That will return the invalidType text.

 

You can add as many messages in there as you want.   I haven’t tested it, but I’m pretty sure you can nest other messages, etc.  For example, this might work:

 

<dictionary>

            <mymessage>Foobar</mymessage>

            <teacherId>

                        <label>teacherId</label>

                        <comment/>

                        <notProvided>The teacherId field is required but was not provided.</notProvided>

                        <invalidType>The teacherId field does not contain valid data.  This field must be a numeric value.</invalidType>

            </teacherId>

            … (more nodes for each field) …

</dictionary>

 

MyDictionary.getValue(“mymessage”)

 

If you delete any one of the generated messages (for example, teacherId.notProvided) it will be regenerated (when not in production mode).

 

I suggest keeping all your validation messages in your Dictionary XML files. 

 

The label and comment messages can be used with something like form generators.  You can update your label to be human readable.  You could also add a comment and then just pass the record or dictionary into a custom tag that generates a form field for you (or something).  I’ve been thinking about other messages that could be in here by default, but nothing else comes to mind.

 

To start using this get latest and delete your project files.   You’ll probably want to move your error messages into the new dictionaries and to delete your old xml file.

 

Doug

 

-- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/

 

-- Reactor for ColdFusion Mailing List -- [email protected] -- Archives at http://www.mail-archive.com/reactor%40doughughes.net/

Reply via email to