Attribute localization within template

272 views
Skip to first unread message

ced

unread,
Oct 5, 2010, 1:16:53 PM10/5/10
to Lift
An element's content can easily be localized inside a template with
the handy lift:loc snippet:

<div><lift:loc locid="loc-key"/></div>

But if I want to localize an attribute, e.g. a title attribute, I used
to bind that attibute inside a snippet where I pulled the localization
via S.?. But especially for those title attributes I want to keep
localization inside the template.

As I couldn't find sometimes analog for attributes I came up with the
following. Any thoughts? Or is there even a method right in front of
me I didn't see?


<a href="#" lift:attrLoc.r="title:loc-key">Link</a>

turns into

<a href="#" title="follow me">Link</a>

import xml.{Text, UnprefixedAttribute, MetaData, Null}
import net.liftweb.http.S

class AttrLoc {
val Split = "(.+?):(.+?)".r
def r(attr: MetaData): MetaData = {
attr.value.text match {
case Split(attrName, locId) => new UnprefixedAttribute(attrName,
S.loc(attr.value.text, Text(locId)), Null)
case _ => Null
}
}
}

ced

unread,
Oct 5, 2010, 1:29:49 PM10/5/10
to Lift
Sorry, paste error.. It must be:

class AttrLoc {
val Split = "(.+?):(.+?)".r
def r(attr: MetaData): MetaData = {
attr.value.text match {
case Split(attrName, locId) => new UnprefixedAttribute(attrName,
S.loc(locId, Text(locId)), Null)
case _ => Null
}
}
}

tbje

unread,
Oct 10, 2010, 11:39:37 AM10/10/10
to Lift
This would be useful to me as well.

+1

David Pollak

unread,
Oct 19, 2010, 9:17:58 AM10/19/10
to lif...@googlegroups.com
Please open a ticket at http://ticket.liftweb.net for this feature


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Denis Nevmerzhitsky

unread,
Dec 9, 2011, 7:58:37 AM12/9/11
to lif...@googlegroups.com
Hi!

Any progress for this feature? Can't find nothing in docs and tickets.
Thank you!

Peter Petersson

unread,
Dec 9, 2011, 10:20:22 AM12/9/11
to lif...@googlegroups.com
Is this what you are looking for, type ...

<span class="lift:Loc?locid=top.link.lable.admin">internationalized</span>
or alt.
<span class="lift:Loc.i">top.link.lable.admin</span>

Or was your question about something else entirely ?
As you are asking about "attribute localization" it makes me think there
is a missing reference to some discussion(?) that would have made your
question more clear.

Was this helpful?

best regards
Peter Petersson

> --
> Lift, the simply functional web framework: http://liftweb.net

> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Denis Nevmerzhitsky

unread,
Dec 9, 2011, 12:29:48 PM12/9/11
to lif...@googlegroups.com
Hi!

I mean "attribute localization". David asked to create ticket for this feature, but i can't find any, so i don't know about state of feature request. Also I didn't find anything about attribute localization in docs (assembla wiki, simply lift, snippet.Loc Api-doc).
Possibly i don't understand this thread correctly. I need localization of attributes such as placeholder, title etc. Loc snippet can localize only node's content. One way is to do it manually in snippets, but it is hell for me. Another way is to create own snippet for attribute localization but i shouldn't if liftweb already can do this.
Thank you.

Diego Medina

unread,
Dec 9, 2011, 1:39:59 PM12/9/11
to lif...@googlegroups.com
Peter, this is the original thread
http://groups.google.com/group/liftweb/browse_thread/thread/77fceab8913ac06a

Denis: I don't think that ticket was ever entered, and as David
already said to enter one, I think you can go ahead an enter that
ticket, and reference the thread:

http://groups.google.com/group/liftweb/browse_thread/thread/77fceab8913ac06a

so that David or any committer who gets to it knows what the ticket is for.

But until that feature gets added, have you tried what ced wrote?

regards,

Diego

> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code

--
Diego Medina
Web Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Denis Nevmerzhitsky

unread,
Dec 9, 2011, 3:11:47 PM12/9/11
to lif...@googlegroups.com
Hi!

No, i have not tried it yet. My vision is a little different:

<a href="#" data-lift="Loc.attr?name=title" title="Some titile">link</a>
<input data-lift="Loc.attr?name=placeholder" placeholder="Placeholder..." />

or even

<a href="#" data-lift="Loc.title" title="Some titile">link</a>
<input data-lift="Loc.placeholder" placeholder="Placeholder..." />

but i'm not sure that second is possible, because Loc.res_name is used for localization by "res_name". I see 2 ways:
1. Additional snippet LocAttr for this
2. deprecate Loc.res_name

I will go with LocAttr (will create own snippet)

Thank you for the answer, i will create a ticket.

Denis Nevmerzhitsky

unread,
Dec 12, 2011, 8:09:07 AM12/12/11
to lif...@googlegroups.com
Hi!

Ticket was created: http://www.assembla.com/spaces/liftweb/tickets/1159-localization-of-attribute-values

About my snippet, i have created one - L10n. It is a modified version of builtin Loc (here is a gist).
Usage examples are:
      <p class="lift:L10n.i">res.name</p> => <p>Localized</p>
      <p><span class="lift:L10n">res.name</span></p> => <p>Localaized</p>
      <a href="#" title="res.name" class="lift:L10n.title">Title</a> => <a href="#" title="Localized">Title</a>
      <input class="lift:L10n.placeholder" placeholder="res.name" /> => <input placeholder="Localized" />
Only one fail for me, i expected:
      <a href="#" title="res.name" class="lift:L10n.title lift:L10n.i">res.name</a> =>  <a href="#" title="Localized">Localized</a>
but as i understand, only one snippet can be invoked.
Possibly my snippet will help somebody.

Sandarenu

unread,
Jan 26, 2012, 8:49:30 PM1/26/12
to lif...@googlegroups.com
Hi Denis,

I was looking for a way to localize button caption.
<input type="submit" id="id_cancel" class="btn" value="Cancel"></input>

Your snippet was to solution for it.
<input type="submit" id="id_cancel" class="btn lift:AttributeLocalizer.value" value="loginform.cancel"></input>
Thanks
Reply all
Reply to author
Forward
0 new messages