1

Cannot figure out how to convert java convert alpha-3 language code to alpha-2 to be able sent locale as string in the following format "sv_SE".

Language enum class(which is used in a lot of places of event based services):

public enum Language {
  ENG, 
  TUR,
  ...
}

Country enum class:

public enum CountryCode {
  AD, 
  AE,
  ...
}

Tried to get alpha-2 language code:

new Locale(Language.ENG.name(), CountryCode.AU.name()).getLanguage(); // still return alpha-3 language code

How alpha-3 language code can be converted to alpha-2 in elegant way without hardcoded mapping in code?

Viktor M.
  • 4,393
  • 9
  • 40
  • 71
  • Possible duplicate of [Convert language code three characters (ISO 639-2) to two-character code (ISO 639-1)](https://stackoverflow.com/questions/62982135/convert-language-code-three-characters-iso-639-2-to-two-character-code-iso-63). That was for Android, though - don't know if that makes a difference in this case. – andrewJames Sep 21 '20 at 14:03

0 Answers0