feat: add Ja locale to Person#386
Open
ymtszw wants to merge 11 commits into
Open
Conversation
ymtszw
commented
Nov 1, 2020
Comment on lines
-147
to
+151
| 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)) |
Author
There was a problem hiding this comment.
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,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/0and other commonfunctions produces only kanji notations, but
*_with_kanavariantsproduces tuples accompanied by hiragana and katakana notations.
To support this feature, I had slightly refactored
sampler/2macro,allowing sample list to host non-literals.
Hope this is acceptable. Thanks in advance!