Shorthand for language tags?

9 views
Skip to first unread message

Patrick Logan

unread,
Sep 2, 2011, 9:03:54 PM9/2/11
to sca...@googlegroups.com
New to scardf, I am wondering if there is a shorthand notation for plain literals with language tags, e.g. longhand would be:

PlainLiteral("foo") @@ LangTag("en")

Is there a shorter way to express the same thing?

Leif Warner

unread,
Sep 2, 2011, 10:27:29 PM9/2/11
to scardf
Well, looking in http://code.google.com/p/scardf/source/browse/trunk/src/main/scala/org/scardf/core.scala#222
there's PlainLiteral("foo", Some(LangTag("en"))), which doesn't look
any shorter.
Perhaps something could be added to the constructors starting from
line 55?
Down at line 257, it looks like LangTag has an apply method that
generates a PlainLiteral, so you could say:
LangTag("en")("foo")

Leif Warner

unread,
Sep 2, 2011, 10:41:43 PM9/2/11
to scardf
Maybe the thing to do would be to add an overrided apply to the
PlainLiteral object, e.g.
def apply( lf: String, lang:String ) = new PlainLiteral( lf,
Some(LangTag(lang)) )

But also, you could simulate that with an implicit conversion String-
>Option[LangTag], e.g.
implicit def toLangTagOpt(s:String) = Some(LangTag(s))

Then (either way) you could call PlainLiteral("foo", "en")

On Sep 2, 7:27 pm, Leif Warner <abimel...@gmail.com> wrote:
> Well, looking in http://code.google.com/p/scardf/source/browse/trunk/src/main/scala/or...

Hrvoje Šimić

unread,
Sep 3, 2011, 12:49:19 AM9/3/11
to sca...@googlegroups.com
I was going for something like this:

"foo"@@en

provided you define val en = LangTag("en") and import object Literal,
which contains implicit def toPlainLiteral(String).

If you use a small set of language tags, it makes sense to have
explicit variables for them. If not, I would go with Leif's advice
about a new implicit.

Hrvoje

Reply all
Reply to author
Forward
0 new messages