Looks good Derek. I'll add the overloaded method later and commit it. Everyone happy with this?
Cheers, Tim On Mar 7, 6:41 am, Derek Chen-Becker <dchenbec...@gmail.com> wrote: > I think that adding an overload for loc(String,String) that maps to > loc(String,NodeSeq) with null testing provides simplicity for the user (not > having to explicitly wrap everything in Text() unless you have specific need > for it). At the risk of making this a little more complex but adding some > flexibility, how about > > def loc(key : String, default : => String) = > loc(str).openOr(Text(Box.!!(default).openOr(""))) > > I'm not sure what we really want to return if the provided default is null. > I was also wondering if we want to Log a failed lookup key so that you could > easily determine that you missed some l10n properties. That could look like: > > def loc(key : String, default : => String) = loc(str).openOr({ > Log.warn({() => "Failed lookup of " + key + " for locale " + S.locale}) > Text(Box.!!(default).openOr("")) > > } > > Cheers, > > Derek > > On Fri, Mar 6, 2009 at 4:57 PM, David Pollak > <feeder.of.the.be...@gmail.com>wrote: > > > > > On Fri, Mar 6, 2009 at 3:52 PM, Timothy Perrett > > <timo...@getintheloop.eu>wrote: > > >> Isn't the danger here that Text() will explode if for some reason default > >> was null (e.g Reading from a DB)? > > >> It's not a massive issue, as people should be diligent about supplying > >> defaults but it's just a though. > > > You can always add null testing. > > - Show quoted text - > > >> Cheers, Tim > > >> Sent from my iPhone > > >> On 6 Mar 2009, at 18:32, Derek Chen-Becker <dchenbec...@gmail.com> wrote: > > >> It would be a little cleaner if there was a helper overload: > > >> def loc (key : String, default : String) = loc(key, Text(default)) > > >> Derek > > >> On Fri, Mar 6, 2009 at 12:16 PM, Timothy Perrett <timo...@getintheloop.eu > >> > wrote: > > >>> I've just been looking at some of the other method overloads in S and > >>> it appears we already have: > > >>> S.loc(String, NodeSeq) > > >>> This is exactly what I need anyway - wondering if there is any need to > >>> override S.? with another method now? > > >>> Cheers, Tim > > >>> On Mar 6, 5:03 pm, Timothy Perrett <timo...@getintheloop.eu> wrote: > >>> > Sounds cool - I'll make the change and commit it. > > >>> > Cheers, Tim > > >>> > On 06/03/2009 16:56, "marius d." <marius.dan...@gmail.com> wrote: > > >>> > > +1 for overloading '? ' > > >>> > > On Mar 6, 4:52 pm, Derek Chen-Becker <dchenbec...@gmail.com> wrote: > >>> > >> I think this is a reasonable addition, but I would use > > >>> > >> def ?(key : String, defaultKey : String) = ... > > >>> > >> That way changing the default text just doesn't require changes to > >>> code. > > >>> > >> Derek > > >>> > >> On Fri, Mar 6, 2009 at 6:29 AM, Tim Perrett <timo...@getintheloop.eu> > >>> wrote: > > >>> > >>> Guys, > > >>> > >>> I have a situation where I want to localize a bunch of dynamic > >>> texts, > >>> > >>> however the current behavior of S.? is to return the input text if > >>> its > >>> > >>> found in a resource bundle. Whilst I see the rational for this, I > >>> have > >>> > >>> another situation where I want to pass a key, and if it doesn't > >>> find > >>> > >>> it, display something else (the english version). Id rather not use > >>> > >>> the english text as the translation key, as if the english text > >>> > >>> changes, my database translations will break (not good!) > > >>> > >>> I can achieve the functionality needed right by doing something > >>> like: > > >>> > >>> S.loc(item.localization_key.toString + ".name") match { > >>> > >>> case Full(t) => t > >>> > >>> case _ => Text(doc.name.toString) > >>> > >>> } > > >>> > >>> But it would be nice if we could have a utility method in S which > >>> > >>> allowed you do do: > > >>> > >>> ?("my.localization.key", defaultText.toString) > > >>> > >>> Thoughts? > > >>> > >>> Cheers, Tim > > > -- > > Lift, the simply functional web frameworkhttp://liftweb.net > > Beginning Scalahttp://www.apress.com/book/view/1430219890 > > Follow me:http://twitter.com/dpp > > Git some:http://github.com/dpp-Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---