Skip to content

Commit

Permalink
#1377 #1378 add phone number hack for Tamil language
Browse files Browse the repository at this point in the history
When users call `new Faker(new Locale("ta")).phone()`, we create phone number for India (though Tamil is used in multiple countries).
  • Loading branch information
asolntsev committed Oct 17, 2024
1 parent 61af169 commit 05afe64
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/net/datafaker/providers/base/PhoneNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ private static String countryCodeIso2(Locale locale) {
};
}

/**
* A hack to detect country when only a language is given.
* <p>
* It's not correct because most languages are used in multiple countries.
* If users need to generate random phone number, they should create locale with country,
* e.g. {@code new Locale("ta_IN")}, and not just {@code new Locale("ta")}.
* </p>
* <p>
* We keep this mapping here just for backward compatibility.
* </p>
*/
private static String detectCountryByLanguage(String language) {
return switch (language) {
case "en" -> "US"; // it has been used by default for English
Expand All @@ -93,6 +104,7 @@ private static String detectCountryByLanguage(String language) {
case "be" -> "BY"; // Belarus
case "ko" -> "KR"; // Korea
case "he" -> "IL"; // Israel
case "ta" -> "IN"; // Tamil language -> India (though, Tamil is used in multiple countries)
default -> language.toUpperCase(ROOT);
};
}
Expand Down

0 comments on commit 05afe64

Please sign in to comment.