-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Ja locale to Person #386
base: master
Are you sure you want to change the base?
Conversation
count = Enum.count(data) | ||
|
||
mapped_data = | ||
data |> Enum.with_index() |> Enum.into(%{}, fn {k, v} -> {v, k} end) |> Macro.escape() | ||
|
||
quote do | ||
@count Enum.count(unquote(data)) | ||
@mapped_data unquote(data) |> Enum.with_index() |> Enum.into(%{}, fn {k, v} -> {v, k} end) | ||
def unquote(name)() do | ||
unquote(mapped_data) | ||
|> Map.get(Faker.random_between(0, unquote(count - 1))) | ||
Map.get(@mapped_data, Faker.random_between(0, @count - 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the modification mentioned in the OP.
Previously count
and mapped_data
calculations are applied to AST outside of quote
, which did not allow non-literals (such as tuples) to be passed to data
.
Pushing it inside quote
makes them expanded at compilation of caller modules, so any expressions in data
are properly evaluated just like other module attributes or other "outside the def
" expressions,
I've added:
Hi! Thanks for maintaining Faker package!
I'm @ymtszw from Tokyo, Japan. This is (probably) the first attempt
to introduce Ja locale to Faker, starting with Person!
As noted in moduledoc, samples are borrowed from faker-ruby/faker,
which itself is loosely built upon population ranking of recent
family names in Japan, and "polularity" ranking of given names
for recent newborns.
One thing to note: in Japanese, names can be read various ways
even they share the same "kanji" notations (heteronyms).
To disambiguate, it is common to put phonetic notations in "kana"
(either in "hiragana" or "katakana") alongsite with kanji notations
in legal documents or web applications.
This patch includes the feature for that.
name/0
and other commonfunctions produces only kanji notations, but
*_with_kana
variantsproduces tuples accompanied by hiragana and katakana notations.
To support this feature, I had slightly refactored
sampler/2
macro,allowing sample list to host non-literals.
Hope this is acceptable. Thanks in advance!