Skip to content

Instantly share code, notes, and snippets.

@KatrinaHoffert
Created July 14, 2015 17:48
Show Gist options
  • Save KatrinaHoffert/d336f800ae9dd574fd34 to your computer and use it in GitHub Desktop.
Save KatrinaHoffert/d336f800ae9dd574fd34 to your computer and use it in GitHub Desktop.
object Language {
def langs: Try[Seq[Language]] = {
Try { val m = for {
l<- current.configuration.getConfig("langs")
a <- l.getConfig("mapping")
} yield a
m.get.keys.map { c=>Language(c, m.get.getString(c).get)}.toList.sortBy(_.c)}
}}
object Language {
/**
* Gets a list of all languages supported from the configuration file. The "langs.mapping" field
* is a JSON object with keys as 2 character country codes and the values as full, native language
* names.
*/
def getSupportedLanguages: Try[Seq[Language]] = {
Try {
val languageMappings = for {
langs <- current.configuration.getConfig("langs")
mapping <- langs.getConfig("mapping")
} yield mapping
val countryCodes = languageMappings.get.keys
countryCodes.map { code =>
Language(code, languageMappings.get.getString(code).get)
}.toList.sortBy(_.code)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment