Skip to content

io.taig.babel.StringFormat6+ works incorrectly #321

@skrauchenia

Description

@skrauchenia

build.sbt

...
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.5.2",
libraryDependencies += "io.taig" %% "babel-core" % "0.5.2",
libraryDependencies += "io.taig" %% "babel-loader" % "0.5.2",
libraryDependencies += "io.taig" %% "babel-generic" % "0.5.2",
libraryDependencies += "io.taig" %% "babel-cats" % "0.5.2"
...

conf/arguments/en.conf

test1 = "{0}"
test2 = "{0} {1}"
test3 = "{0} {1} {2}"
test4 = "{0} {1} {2} {3}"
test5 = "{0} {1} {2} {3} {4}"
test6 = "{0} {1} {2} {3} {4} {5}"
test7 = "{0} {1} {2} {3} {4} {5} {6}"
test8 = "{0} {1} {2} {3} {4} {5} {6}, {7}"
test9 = "{0} {1} {2} {3} {4} {5} {6}, {7}, {8}"

Test.scala

object Test extends App {

  import cats.effect._
  import cats.effect.unsafe.implicits.global
  import cats.syntax.all._
  import io.taig.babel._
  import io.taig.babel.generic.auto._

  final case class I18n(
      test1: StringFormat1,
      test2: StringFormat2,
      test3: StringFormat3,
      test4: StringFormat4,
      test5: StringFormat5,
      test6: StringFormat6,
      test7: StringFormat7,
      test8: StringFormat8,
      test9: StringFormat9
  )

  val i18ns = Loader
    .default[IO]
    .load("arguments", Set(Locales.en))
    .map(Decoder[I18n].decodeAll)
    .rethrow
    .map(_.withFallback(Locales.en))
    .flatMap(_.liftTo[IO](new IllegalStateException("Translations for en missing")))
    .unsafeRunSync()

  println(i18ns(Locales.en).test1("1"))
  println(i18ns(Locales.en).test2("1", "2"))
  println(i18ns(Locales.en).test3("1", "2", "3"))
  println(i18ns(Locales.en).test4("1", "2", "3", "4"))
  println(i18ns(Locales.en).test5("1", "2", "3", "4", "5"))
  println(i18ns(Locales.en).test6("1", "2", "3", "4", "5", "6"))
  println(i18ns(Locales.en).test7("1", "2", "3", "4", "5", "6", "7"))
  println(i18ns(Locales.en).test8("1", "2", "3", "4", "5", "6", "7", "8"))
  println(i18ns(Locales.en).test9("1", "2", "3", "4", "5", "6", "7", "8", "9"))

}

Expected result

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9

Actual result

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 62 3 4 5 
1 6 2 73 4 5 
1 6 2 7, 3 84 5 
1 6 2 7, 3 8, 4 95

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions