GithubHelp home page GithubHelp logo

taig / babel Goto Github PK

View Code? Open in Web Editor NEW
34.0 4.0 5.0 1.13 MB

Internationalization (i18n) for Scala applications

Home Page: https://taig.github.io/babel/

License: MIT License

Scala 100.00%
i18n internationalization p11n scala scalajs hocon

babel's Introduction

Babel

Internationalization (i18n) for Scala applications

GitHub Maven Central Sonatype Nexus (Snapshots) License Scala Steward badge

Features

  • First class support for plurals
  • Great fit for Scala.js clients, since java.util.Locale is not used
  • Translation definitions in HOCON format
  • Decode translations into data classes
  • Easily share translations of a specific language with the frontend in JSON format
  • Typesafe alternative to String.format or java.util.MessageFormat argument injection
  • Dependency-free core module

Please proceed to taig.github.io/babel for more information.

babel's People

Contributors

bardurdam avatar scala-steward avatar taig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

babel's Issues

Improve Loader module

The loader is currently only capable of loading HOCON files from the classpath resources. It should be more broadly applicable allowing to load arbitrary paths and formats. While the current HOCON loading should remain, additionally it should be possible to load files such as privacy-policy/en.html and privacy-policy/de.html into a Translations[String].

io.taig.babel.StringFormat6+ works incorrectly

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.