Locale identifier discrepancy
MattNewberry opened this issue · 2 comments
In referencing the file names in the localization folder (and the example in the README), locales referenced with a dash (e.g: "en-US").
However, explicitly allocating with that locale identifier produces empty data. For example:
(lldb) po Faker(locale: "en-US").name.firstName()
""
Correct results, though, are found when using a locale identifier with an underscore. For example:
(lldb) po NSLocale.currentLocale().localeIdentifier
"en_US"
(lldb) po Faker(locale: NSLocale.currentLocale().localeIdentifier).name.firstName()
"Gretchen"
Using the locale in the README, here are the results:
(lldb) po Faker(locale: "nb-NO").name.firstName()
"Emilie"
(lldb) po Faker(locale: "nb_NO").name.firstName()
"Hershel"
(lldb) po Faker(locale: "en-US").name.firstName()
""
(lldb) po Faker(locale: "en_US").name.firstName()
"Maryjane"
I'd recommend consolidating these somehow, including a note in the README if you see fit.
Subtags, in turn, are a sequence of alphanumeric characters (letters and digits), distinguished and separated from other subtags in a tag by a hyphen ("-", [Unicode] U+002D).
Hyphen should be preferred based on the BCP-47 notation. Any updates on this?
As you can see in https://github.com/vadymmarkov/Fakery/tree/master/Resources/Locales hyphen is used in locale names. As for US locale the problem was that data you were trying to access, for example Faker(locale: "en-US").name.firstName()
, didn't exist in "en-US.json" file. This PR #83 however makes a change, and from now on when you use one of the available generators and the corresponding key is not found in a JSON file for the currently selected locale Fakery will also check if it exists in "en.json" file.