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 dd75569 commit 2a9c988
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
59 changes: 56 additions & 3 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ of the type-class I18N[A] for the type.
that loads bundles of resources containing message key to message format files
(named by their locale) from all jars located on the classpath.

== Example
== Example (US)

----
scala> :paste
// Entering paste mode (ctrl-D to finish)
import java.util.Locale
import s_mach.i18n._
Expand All @@ -63,10 +65,61 @@ val m_test = 'm_test.m[Int,I18NString]
// Using i18ncfg, resolve the message key to a message format and interpolate the arguments
// Note: the Int argument is automatically converted to I18NString by invoking the
// I18N[Int] type-class
val test_i18n_str = m_test(1,"test".asI18N)
val test_message_lookup = m_test(1,"test".asI18N)
// Note: the Double argument is automatically converted to I18NString by invoking the
// I18N[Double] type-class
i18n"interpolate some arguments $test_i18n_str ${25.0}"
val test_i18n_str = i18n"interpolate some arguments $test_message_lookup ${25.0}"
// Exiting paste mode, now interpreting.
import java.util.Locale
import s_mach.i18n._
import s_mach.i18n.messages._
i18ncfg: s_mach.i18n.I18NConfig = I18NConfig(Messages(keys=test_key,m_false,fmt_test1_key,m_true,fmt_choice_key,fmt_test2_key,m_test),StrictInterpolator,StrictMessageResolver,DefaultStdI18N)
m_test: s_mach.i18n.messages.Message2[Int,s_mach.i18n.I18NString] = Message2('m_test)
test_message_lookup: s_mach.i18n.I18NString = this is a test message format that accepts two arguments 1 and test
test_i18n_str: String with s_mach.i18n.I18NStringTag with s_mach.codetools.IsDistinctTypeAlias[String] = interpolate some arguments this is a test message format that accepts two arguments 1 and test 25
scala>
----

== Example (FR)

----
scala> :paste
// Entering paste mode (ctrl-D to finish)
import java.util.Locale
import s_mach.i18n._
import s_mach.i18n.messages._
// Uses UTF8Messages by default
implicit val i18ncfg = I18NConfig(Locale.FRENCH)
// Create a message with the key m_test that accepts 2 arguments, an Int and an I18NString
val m_test = 'm_test.m[Int,I18NString]
// Using i18ncfg, resolve the message key to a message format and interpolate the arguments
// Note: the Int argument is automatically converted to I18NString by invoking the
// I18N[Int] type-class
val test_message_lookup = m_test(1,"test".asI18N)
// Note: the Double argument is automatically converted to I18NString by invoking the
// I18N[Double] type-class
val test_i18n_str = i18n"nous allons interpoler certains arguments $test_message_lookup ${25.0}"
// Exiting paste mode, now interpreting.
import java.util.Locale
import s_mach.i18n._
import s_mach.i18n.messages._
i18ncfg: s_mach.i18n.I18NConfig = I18NConfig(Messages(keys=test_key,m_false,fmt_test1_key,m_true,fmt_choice_key,fmt_test2_key,m_test),StrictInterpolator,StrictMessageResolver,DefaultStdI18N)
m_test: s_mach.i18n.messages.Message2[Int,s_mach.i18n.I18NString] = Message2('m_test)
test_message_lookup: s_mach.i18n.I18NString = c'est un format de message de test qui accepte deux arguments 1 et test
test_i18n_str: String with s_mach.i18n.I18NStringTag with s_mach.codetools.IsDistinctTypeAlias[String] = nous allons interpoler certains arguments c'est un format de message de test qui accepte deux arguments 1 et test 25
scala>
----
1 change: 1 addition & 0 deletions src/test/resources/conf/messages_fr.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
m_test=c''est un format de message de test qui accepte deux arguments {0} et {1}
m_true=vrai
m_false=faux
fmt_choice_key=Il {0,choice,0#n''y a pas de pommes|1#y a une pomme|1<y a {0,number,integer} pommes}.
24 changes: 24 additions & 0 deletions src/test/scala/s_mach/i18n/example/ExampleUsageFR.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package s_mach.i18n.example

object ExampleUsageFR {

import java.util.Locale
import s_mach.i18n._
import s_mach.i18n.messages._

// Uses UTF8Messages by default
implicit val i18ncfg = I18NConfig(Locale.FRENCH)

// Create a message with the key m_test that accepts 2 arguments, an Int and an I18NString
val m_test = 'm_test.m[Int,I18NString]

// Using i18ncfg, resolve the message key to a message format and interpolate the arguments
// Note: the Int argument is automatically converted to I18NString by invoking the
// I18N[Int] type-class
val test_message_lookup = m_test(1,"test".asI18N)

// Note: the Double argument is automatically converted to I18NString by invoking the
// I18N[Double] type-class
val test_i18n_str = i18n"nous allons interpoler certains arguments $test_message_lookup ${25.0}"

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package s_mach.i18n.example

object ExampleUsage {
object ExampleUsageUS {

import java.util.Locale
import s_mach.i18n._
Expand All @@ -15,9 +15,10 @@ val m_test = 'm_test.m[Int,I18NString]
// Using i18ncfg, resolve the message key to a message format and interpolate the arguments
// Note: the Int argument is automatically converted to I18NString by invoking the
// I18N[Int] type-class
val test_i18n_str = m_test(1,"test".asI18N)
val test_message_lookup = m_test(1,"test".asI18N)

// Note: the Double argument is automatically converted to I18NString by invoking the
// I18N[Double] type-class
i18n"interpolate some arguments $test_i18n_str ${25.0}"
val test_i18n_str = i18n"interpolate some arguments $test_message_lookup ${25.0}"

}

0 comments on commit 2a9c988

Please sign in to comment.