sfxcode / sapphire-core

Scala - JavaFX Application Framework (CDI, Binding, Expressions)
https://sfxcode.github.io/sapphire-javafx
Apache License 2.0
8 stars 1 forks source link

i18n better integration #18

Closed ASchmidt84 closed 5 years ago

ASchmidt84 commented 5 years ago

Hi Tom, I have an idea for better integration of i18n. The resource is loaded in the controller. That is fine. The key could contain variable placeholders. So MessageFormat can used. But I think it is redundant to use that. I suggest this additional class:

class Messages(bundle: ResourceBundle) {

  def getString(key: String, params: AnyRef*): String = {
    Try(bundle.getString(key)).map{f ⇒
      MessageFormat.format(f,params:_*)
    }.getOrElse(s"!!--$key--!!")
  }

}

and a method in ViewController

private lazy val msg: Messages = new Messages(resources)

  def i18n(key: String, params: AnyRef*): String = {
    msg.getString(key,params)
  }

So it is a little bit easier to translate.

sfxcode commented 5 years ago

Will be released in the next version

sfxcode commented 5 years ago

Implemented in the 1.6.6 Release