Re: Access bindings at runtime
Re: Access bindings at runtime
- Subject: Re: Access bindings at runtime
- From: Chuck Hill <email@hidden>
- Date: Tue, 03 Feb 2004 16:20:06 -0800
- Organization: Global Village Consulting, Inc.
You should probably also have a look at Project Wonder, I'm pretty
sure there is localization stuff there. They've got everything
else... Also poke around www.wodev.com and www.wocode.com.
If you are new to localization, replacing localization might be a lot
to bite off.
Chuck
Chuck Hill wrote:
David Griffith wrote:
Ok, to use your example:
The name of the WOString below is DateTitle. Perfect. I want to take
the
name of the WOString (i.e. DateTitle), as that is a logical name that is
recognisable when looking at the WOComponent in design mode, and I
want to
combine that with a Language setting (say from the session or from a user
selected language option from the DB) which is for example 'en' for
english.
I then want to lookup DateTitle in the database, returning the resulting
string to be displayed in English in this case, or whatever language.
That is not how WO works. The Name is just a key into a dictionary of
the bindings that define where the value comes from. Its only meaning
is to match something in the HTML template.
So, if I was to describe it in steps:
Create a WOString in the WOComponent called DateTitle.
Bind a method called getDisplayString to it.
getDisplayString would need access to the name of the current Dynamic
Element being processed, i.e. In this case DateTitle.
The element knows neither its name or its position in the template. You
need to pass DateTitle to it.
A language setting, for example 'en' as chosen by the user held in a
variable called currentLanguage.
er, the browser should send this. See languages() on Session. You
might need to interpret the contents a bit. IIRC, they are not standard.
GetDisplayString looks up the database for a record which matches
DateTitle
and 'en' and returns the relevant string for the relevant language.
The string is passed back to the binding and displayed in the
WOComponent.
That is going to kill performance.
This would allow me to display all the relevant strings on the
WOComponent
in the correct language using one method. If I could get access to
the name
of the current element. Which apparently I can't.
Hopefully this makes sense, although I'm sure you'll tell me it's a
load of
rubbish ;-)
Sort of. :-)
P.s. Looking at the example below, at first I didn't really
understand it.
Like I said, I don't really understand how the WO Localisation works.
Where
you have put 'session.localizedString.todaysDateIs' - is
'todaysDateIs' like
a placeholder or identifier for the string to be looked up?
I wrote that a bit too fast. localizedString will need to return an
object that implements KVC to handle 'todaysDateIs' specially. The code
I posted was off the cuff and wrong. You could also do this by
overriding KVC on Session, but I think keeping it in another object is
cleaner. I like clean.
That's
basically what I am looking for. And by implementing 'stringInLocale' to
search in the database, is this intended to search the database
instead of
the localised.strings file?
Yes. Or, better, a memory cache before going to the DB. There is no
need to go to the DB everytime every English speaking user needs to see
this title.
If so, how does
'session.localizedString.todaysDateIs' pass the value to the method in
the
session? I.e. The 'key'
Key Value coding. This is shorthand for
session().localizedString().todaysDateIs() but you can re-implement this
to interpret this as session().localizedString("todaysDateIs") or even
session().localizedString().todaysDateIs().stringInLocale("todaysDateIs",
"en") etc. Fun with KVC!
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
It is a funny thing about life; if you refuse to accept
anything but the best, you very often get it."
-- W. Somerset Maugham
<shamelessPlug>
Practical WebObjects
http://www.amazon.com/exec/obidos/tg/detail/-/1590592964
</shamelessPlug>
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.