scalajs-scaposer


License

License

Categories

Categories

JavaScript Languages Scala
GroupId

GroupId

com.github.fbaierl
ArtifactId

ArtifactId

scalajs-scaposer_sjs0.6_2.12
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

scalajs-scaposer
scalajs-scaposer
Project URL

Project URL

https://github.com/fbaierl/scalajs-scaposer
Project Organization

Project Organization

com.github.fbaierl
Source Code Management

Source Code Management

https://github.com/fbaierl/scalajs-scaposer

Download scalajs-scaposer_sjs0.6_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.fbaierl/scalajs-scaposer_sjs0.6_2.12/ -->
<dependency>
    <groupId>com.github.fbaierl</groupId>
    <artifactId>scalajs-scaposer_sjs0.6_2.12</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.fbaierl/scalajs-scaposer_sjs0.6_2.12/
implementation 'com.github.fbaierl:scalajs-scaposer_sjs0.6_2.12:0.1.2'
// https://jarcasting.com/artifacts/com.github.fbaierl/scalajs-scaposer_sjs0.6_2.12/
implementation ("com.github.fbaierl:scalajs-scaposer_sjs0.6_2.12:0.1.2")
'com.github.fbaierl:scalajs-scaposer_sjs0.6_2.12:jar:0.1.2'
<dependency org="com.github.fbaierl" name="scalajs-scaposer_sjs0.6_2.12" rev="0.1.2">
  <artifact name="scalajs-scaposer_sjs0.6_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.fbaierl', module='scalajs-scaposer_sjs0.6_2.12', version='0.1.2')
)
libraryDependencies += "com.github.fbaierl" % "scalajs-scaposer_sjs0.6_2.12" % "0.1.2"
[com.github.fbaierl/scalajs-scaposer_sjs0.6_2.12 "0.1.2"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.6
org.scala-js : scalajs-library_2.12 jar 0.6.23
org.scala-lang.modules : scala-parser-combinators_sjs0.6_2.12 jar 1.1.1

test (2)

Group / Artifact Type Version
org.scala-js : scalajs-test-interface_2.12 jar 0.6.23
org.specs2 : specs2-core_sjs0.6_2.12 jar 4.3.3

Project Modules

There are no modules declared in this project.

Build Status Scala.js

scalajs-scaposer

Scala.js version of scaposer.

Basic Usage

See also: xitrum-framework Scaladoc

val po = """
msgid "Hello"
msgstr "Bonjour"
"""

val result = scaposer.Parser.parse(po)
// => An Either,
// Left(scaposer.ParseFailure) or
// Right(Seq[scaposer.Translation])

Use t methods to get the translations:

val translations = result.right.get
val i18n         = scaposer.I18n(translations)
i18n.t("Hello")  // => "Bonjour"

If there's no translation, or the translation is an empty string (not translated yet), the original input is returned:

  i18n.t("Hi")  // => "Hi"

Context

val po = """
msgid "Hello"
msgstr "Bonjour"

msgctxt "Casual"
msgid "Hello"
msgstr "Salut"
"""

val translations = scaposer.Parser.parse(po).right.get
val i18n         = scaposer.I18n(translations)
i18n.tc("Casual", "Hello")  // => "Salut"

If there's no translation for the context, the translation without context is tried:

  i18n.tc("Missing context", "Hello")  // => "Bonjour"

Plural-Forms

val po = """
msgid ""
msgstr "Plural-Forms: nplurals=2; plural=n>1;"

msgid "I have one apple"
msgid_plural "I have %d apples"
msgstr[0] "J'ai une pomme"
msgstr[1] "J'ai %d pommes"
"""

val translations = scaposer.Parser.parse(po).right.get
val i18n         = scaposer.I18n(translations)
i18n.tn("I have one apple", "I have %d apples", 1)                // => "J'ai une pomme"
i18n.tn("I have one apple", "I have %d apples", 2)                // => "J'ai %d pommes"
i18n.tcn("A context", "I have one apple", "I have %d apples", 3)  // => "J'ai %d pommes"

For performance, your po file should define Plural-Forms exactly as at:

Otherwise, Scaposer cannot compare the plural form string, and it needs to parse and evaluate (slower).

Merge Po objects

You can merge multiple I18ns together.

val i18n4 = i18n1 ++ i18n2 ++ i18n3

Just like when you merge maps, translations in i18n3 will overwrite those in i18n2 will overwrite those in i18n1.

Installation

Supported Scala versions: 2.12.x, 2.11.x, 2.10.x

build.sbt example:

libraryDependencies += "com.github.fbaierl" %%% "scalajs-scaposer" % "0.1.2"

Versions

Version
0.1.2
0.1.1
0.1