Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance Gatlin committed May 1, 2016
1 parent 3d322f5 commit b1dde8b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/s_mach/i18n/messages/Interpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package s_mach.i18n.messages

import MessageFormat.Interpolation
import s_mach.i18n._
import s_mach.i18n.impl.{InterpolatorOps, LaxInterpolator, StrictInterpolator}
import s_mach.i18n.impl.{LaxInterpolator, StrictInterpolator}

/**
* A trait for interpolating arguments into a message format interpolation
Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/s_mach/i18n/messages/MessageResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ object MessageResolver {
/** A message resolver that never throws an error if a problem is encountered and instead
* returns an error I18NString */
val lax = new LaxMessageResolver(
missingKey = (missingKey,args) => s"{${missingKey.name}:null}(${args.mkString(",")})",
missingKey = (missingKey,args) => s"{${missingKey.name}:missing}${
if(args.nonEmpty) {
s"(${args.mkString(",")})"
} else {
""
}
}",
invalidFormat = (key,args) => s"{${key.name}:invalid}(${args.mkString(",")})"
)
val default = strict
Expand Down
32 changes: 29 additions & 3 deletions src/test/scala/s_mach/i18n/test/MessageResolverTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,44 @@ import s_mach.i18n.messages._
class MessageResolverTest extends FlatSpec with Matchers {
implicit val cfg = I18NConfig(Messages(Locale.ENGLISH))

"MessageResolver.strict.interpolate" should "throw if key is missing" in {
"MessageResolver.strict.resolveInterpolation" should "throw if key is missing" in {
an[NoSuchElementException] should be thrownBy MessageResolver.strict.resolveInterpolation(
'test,
"1".asI18N
)
}

"MessageResolver.lax.interpolate" should "show key and args for missing keys" in {
"MessageResolver.strict.resolveLiteral" should "throw if key is missing" in {
an[NoSuchElementException] should be thrownBy MessageResolver.strict.resolveLiteral(
'test
)
}

"MessageResolver.strict.resolveChoice" should "throw if key is missing" in {
an[NoSuchElementException] should be thrownBy MessageResolver.strict.resolveChoice(
'test,
BigDecimal("1")
)
}

"MessageResolver.lax.resolveInterpolation" should "show key and args for missing keys" in {
MessageResolver.lax.resolveInterpolation(
'test,
"1".asI18N,
"2".asI18N
) should equal("{test:null}(1,2)")
) should equal("{test:missing}(1,2)")
}

"MessageResolver.lax.resolveLiteral" should "show key and args for missing keys" in {
MessageResolver.lax.resolveLiteral(
'test
) should equal("{test:missing}")
}

"MessageResolver.lax.resolveChoice" should "show key and args for missing keys" in {
MessageResolver.lax.resolveChoice(
'test,
BigDecimal("1")
) should equal("{test:missing}(1)")
}
}

0 comments on commit b1dde8b

Please sign in to comment.