Comments (6)
@igas will raising an exception will be the right way to proceed here?
from faker.
I don't think so, we should fallback to defaults.
For example if I call Faker.Name.name
for locale set to :id
. And we don't have an Faker.Name.Id
it should call Faker.Name.En
.
I see it something like this:
- check if
:faker
app started. - If it is grab locale and check that we have module for this locale.
- If any of this false fall back to
En
It'll be a little bit more difficult when we will introduce sublocales like EnUk
, EnUs
, EnAu
and so on, in that case I think we will check for EnUk
for example if this MFA doesn't exist check for just En
.
It'll make usage much simpler from my point of view.
Any suggestions?
/cc @vforvova
from faker.
@igas fallback to defaults is good idea, but what if we have partial implementation of Faker for some language?
For example, we have Faker.Name.En
, Faker.Company.En
as default and Faker.Name.Ru
for Russian language. If we send name
to Faker.Name
with Russian as current language, we will get any Russian name. But if we send Faker.Company
with Russian language, we will get English company name. It feels confusing a bit... but I have no ideas how to resolve this issue.
from faker.
After a while I had some time to take another look to this issue.
I'm proposing a solution similar to the the one described above by @igas, which looks as follows:
Instead of repetitively defining each localized function over and over in each file, we could abstract that piece of code into a reusable construct, like a macro. That way, this:
def name, do: Module.concat(__MODULE__, Faker.mlocale)
can be replaced by this:
defmodule Faker.Color do
use Faker.Locale
localize :name
end
Faker.Locale
would simple collect all function names that need to be localized, and resolve the right module to call.
@vforvova your point is valid but I strongly feel that, that specific issue is really hard to solve; I see the following approaches here:
- The simple way would be to delegate the responsibility to the consumer, we just fallback if there's no localization for a specific module.
- The best way will be to have an extension mechanism, that way your example above will be solved by the consumer extending
Faker.Company
to Russian. If we decide to go this way, it might be better to open a dedicated issue for this IMHO.
I have a WIP branch here: https://github.com/saulecabrera/faker/blob/dynamic-calls/lib/faker/locale.ex
I would appreciate your thoughts on this.
from faker.
Hi @saulecabrera,
Great code out there, I got some inspiration from it and created #173. What do you think?
from faker.
@igas Sorry for the delay! I feel that your solution is a nice iteration to mine, specially because the amount of metaprogramming is less. I'm all in with this!
from faker.
Related Issues (20)
- New release? HOT 1
- Problems when instantiating Faker in iex, I followed the documentation guide but it didn't help me much, can someone help me, I'm using Phoenix Framework HOT 2
- Faker.Name.PtBr.first_name/0 is undefined HOT 2
- Avatar url is redirected HOT 1
- Virgin Islands extra split
- Faker.Phone.EnUs.phone() produces invalid phone numbers HOT 2
- Feature request: Timezone
- Utilities for non-deterministic data generation
- Compile issue with Elixir 1.13 HOT 5
- invalid bidirectional formatting character in string: \u202A HOT 2
- compile error on elixir latest 1.13.12 HOT 2
- Faker.Blockchain.Ethereum.address/0 may return invalid addresses HOT 1
- Option to make any generated data unique HOT 1
- Faker.Vehicle.vin() does not always generate valid VINs
- feature: increase API compatibility with FakerElixir
- Release new version HOT 2
- Dependency Dashboard
- Faker.Date.date_of_birth() is failing on 29/2 HOT 5
- Faker.Date.date_of_birth() generates invalid dates when called on a leap date HOT 2
- Compile warnings with Elixir 1.17 rc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faker.