Is there an elegant way to convert ISO 639-2 (3 letter) language codes to Java Locales?

前端 未结 3 1199
轻奢々
轻奢々 2021-01-04 02:55

E.g. eng, spa, ita, ger

I could iterate all locales and compare the codes, but I wonder whether there is a more elegant & performant way to achieve this....

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 03:24

    You can use constructor Locale(String language), where language is the 2 letter ISO-639-1 code. I think the easiest way to convert ISO-639-2 to ISO-639-1 would be to create HashMap constant.

提交回复
热议问题