Skip to content
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

QUESTION : cascading locality fallbacks #265

Closed
Moosh-be opened this issue Jan 23, 2022 · 4 comments
Closed

QUESTION : cascading locality fallbacks #265

Moosh-be opened this issue Jan 23, 2022 · 4 comments
Labels
c: feature Request for new feature good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent

Comments

@Moosh-be
Copy link
Contributor

QUESTION : cascading locality fallbacks
Was # 977 in marak repo.

Moosh-be opened this issue on 25 Aug
In most of case the "sub locales" are not fully different of basic locale.
Most of content of fr is valid for fr_BE
How to double /cascade the fallback ?
fr_BE --> fr --> en

Marak commented on 25 Aug
Seems like we will want to add this.
I've made note and will attempt to include this functionality in the next major release version.

Moosh-be commented on 25 Aug
If it's not done I want share an idea.
as the lib is builded, perhaps it's better for performance to generate a merged big file including the "heritage"
(but perhaps it's a bad idea ;-)

I see also some confusion between language and country.

Marak commented on 25 Aug
When I look at shape of https://github.com/ladjs/i18n-locales data, it seems like hierarchy of locality is simple meta-programming problem, so it should be easy to implement better fallback features assuming modularity abstraction pattern of faker.js is already solved at higher level ( I am doing now ).

Same answer when build-time. Actual problem here is complex dependency graph issue, but since i18n list is finite size set we will cheat and make it simple solution.

FYI, this cascade fallback is very smart idea @Moosh-be. I am glad you make this report.

Marak commented on 26 Aug
I was just thinking that we can probably implement a quick version of this with the current version and structure of faker.js. Incremental locale builds are currently manual only so we could just ignore the build aspect of this for now.

It would just be a matter of starting at the base locality and attempting to traverse up the locality name as string using metaprogramming technique and checking for existence of key in faker definitions.

I don't have any plans to implement this right now but I'd imagine it could be done with a small PR.

Moosh-be commented on 26 Aug
FYI : Personally, I am an old school developer (js in 1998 :-) when jquery arrived I had already quit. I will not dare to embark on such a development. I contribute because faker.js is integrated with POSTMAN and because I want my fellow developers to use it
I'have the good level to test, to translate, to document but not to help on the core

@Moosh-be Moosh-be added the s: pending triage Pending Triage label Jan 23, 2022
@Shinigami92
Copy link
Member

TL;DR 😅

We should just implement a simple localeFallback?: UsableLocale | UsableLocale[]

localeFallback?: UsableLocale;

And then just use it in order the values are provided in a cascade

@Shinigami92 Shinigami92 added c: feature Request for new feature good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent labels Jan 23, 2022
@github-actions
Copy link
Contributor

Hello @Moosh-be. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!

@github-actions github-actions bot removed the s: pending triage Pending Triage label Jan 23, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Jan 23, 2022

I'm not sure whether we should keep the notion of locale and fallbackLocale.
Instead we should just merge them into one: localeOrder: UsableLocale[] (string[]).

The central change will be here: https://github.com/faker-js/faker/blob/main/src/index.ts#L408-L420

I have a POC here:
ST-DDT/faker@main...feature/locales/multi-fallback

Note, that this requires some changes to the logic how certain fields are checked.
E.g. The checks whether a specific subgroup exists has to be replaced with a format pattern (Not yet implemented).
So this might be a major/breaking change.

@Moosh-be Do you want to take over/start your own implementation?

@ST-DDT
Copy link
Member

ST-DDT commented Apr 30, 2022

Superseded by #823
Will probably by implemented by #858

@ST-DDT ST-DDT closed this as completed Apr 30, 2022
@ST-DDT ST-DDT moved this to Done in Faker Roadmap Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature good first issue Good for newcomers help wanted Extra attention is needed p: 1-normal Nothing urgent
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants