A collection of utilities for Scala/Java developers who are targeting Persian (Farsi) speaking users.
Full documentation, tutorials, and interactive Scaladoc API references are published at persianutils.bahmanm.com.
| Library Version | Scala 2.10 | Scala 2.11 | Scala 2.12 | Scala 2.13 | Scala 3.x |
|---|---|---|---|---|---|
| 6.x | - | - | - | ✅ | ✅ |
| 5.x | - | - | ✅ | ✅ | ✅ |
| 4.x | - | ✅ | ✅ | ✅ | - |
| 3.x | - | ✅ | ✅ | - | - |
| 2.x | ✅ | ✅ | - | - | - |
- JVM:
libraryDependencies += "com.bahmanm" %% "persianutils" % "6.0" - Scala.js:
libraryDependencies += "com.bahmanm" %%% "persianutils" % "6.0"
See the Installation Guide for Maven, Mill, Scala-CLI, and Gradle setup instructions.
This is a short review of what you will find in persianutils:
com.bahmanm.persianutils.DateConverter is the Scala port of the original algorithm (in Fortran) The Persian calendar for 3000 years.
Documentation: DateConverter Guide | Scaladoc API
Scala:
import com.bahmanm.persianutils.DateConverter._
val gDate = GregorianDate(2013, 12, 11)
val pDate = gregorianToPersian(gDate) // 1392/9/20
val pDate2 = PersianDate(1392, 1, 1)
val gDate2 = persianToGregorian(pDate2) // 2013/3/21Java:
PersianDate pd = DateConverter.gregorianToPersian(new GregorianDate(2014, 2, 4)); // 1392/11/15
GregorianDate gd = DateConverter.persianToGregorian(new PersianDate(1392, 11, 15)); // 2014/2/4Translates numeric values into written Persian words for both cardinal and ordinal numbering.
Documentation: NumToWord Guide | Scaladoc API
Scala:
import com.bahmanm.persianutils.NumToWord
assert(NumToWord.cardinal(100) == "صد")
assert(NumToWord.ordinal(1) == "یکم")Java:
String hundred = NumToWord.cardinal(100); // صد
String first = NumToWord.ordinal(1); // یکمConverts date objects or date components into full verbal Persian expressions.
Documentation: DateToWord Guide | Scaladoc API
Scala:
import com.bahmanm.persianutils.PersianDate
val pDate = PersianDate(1361, 3, 3)
assert(pDate.toWords == "سوم خرداد یک هزار و سیصد و شصت و یک")Java:
PersianDate pd = new PersianDate(1361, 3, 3);
String words = pd.toWords(); // سوم خرداد یک هزار و سیصد و شصت و یکSanitises and normalises Persian text by standardising character variants (such as Arabic Kaf and Yeh), converting numerals, regularising spacing and zero-width non-joiners (ZWNJ), stripping tatweel, and standardising punctuation.
Documentation: TextSanitiser Guide | Scaladoc API
Scala:
import com.bahmanm.persianutils.TextSanitiser
val cleanText = TextSanitiser.sanitise(" كتاب علي 123 و ١٤٠٣, تست? ")
assert(cleanText == "کتاب علی ۱۲۳ و ۱۴۰۳، تست؟")Java:
String cleanText = TextSanitiser.sanitise("كتاب علي 123?", new SanitiserConfig()); // کتاب علی ۱۲۳؟