I am writing an API (using Java) that takes locale as a parameter. We want the clients to be able to specify en-US or en_US as they both seem to be widely used across all languages. I did go through these links How to get locale from string representation in Javaen_US or en-US, which one should you useJava Locale documentationJava documentation (source 3 from above) states Well-formed variant values have the form SUBTAG (('_'|'-') SUBTAG)* where SUBTAG = [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}. (Note: BCP 47 only uses hyphen ('-') as a delimiter, this is more lenient). The way I understood this is both _ and - are supported, but their code supports only -. see my sample unit test below which fails, but passes if i use en-US.@Testpublic void testLocale() {    Locale locale = Locale.forLanguageTag(en_US);    assertThat(locale.getLanguage(), equalTo(en));}Are there ways to parse a locale from both forms of string en_US and en-US? What is the recommended approach here ?
Parse both en_US and en-US as locale in Java
java;java8;localization
Replace every occurence of _ by - in the locale string when you receive the parameter and let the logic expect only -.