Skip to content

Instantly share code, notes, and snippets.

@rockpunk
Last active March 28, 2020 01:32
Show Gist options
  • Save rockpunk/4fc315a8fff0b1d980ae95ad63230a14 to your computer and use it in GitHub Desktop.
Save rockpunk/4fc315a8fff0b1d980ae95ad63230a14 to your computer and use it in GitHub Desktop.
generate a proto enum from JVM locales
import java.util.Locale
import java.io._
val w = new BufferedWriter(new FileWriter(new File("/tmp/test.proto")))
w.write("enum Language {\n")
("unknown" +: Locale.getISOLanguages).zipWithIndex.foreach { x=>
w.write(f" ${x._1.toUpperCase} = ${x._2}; // ${Locale.forLanguageTag(x._1).getDisplayLanguage}\n") }
w.write("}\n");
w.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment