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

Use fallback from DEFAULT_LANGUAGE to 'en' #183

Merged
merged 1 commit into from
Nov 10, 2019

Conversation

c960657
Copy link
Contributor

@c960657 c960657 commented Oct 29, 2019

With the changes in #176, most translations for en_US have been replaces with a generic en translation.

The fallback to the parent locale works fine for providers created with en_US as display locale. But for providers with other locales (such as it_IT), the fallback to DEFAULT_LANGUAGE (if no Italian translation exists) only looks for a en_US and not the parent locale.

In other words, the lookup priority should be this:
it_ITiten_USenshortName

But currently it is only this:
it_ITiten_USshortName

@@ -181,7 +181,11 @@ protected function getLocales(): array
while (\array_pop($parts) && $parts) {
$locales[] = \implode('_', $parts);
}
$locales[] = self::DEFAULT_LOCALE;

// DEFAULT_LOCALE is en_US
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mean the fallback language? Any reason this is hardcoded to 'en'/'en-US'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en_US has always been used as fallback language (Holiday:: DEFAULT_LOCALE). The only change here is that it will now fall back to en, if there is no specific translation for en_US.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 'en_US' has always been the default fallback, but I thought even the fallback locale was configurable in one of your PR's (Or am I mistaken?)

Copy link
Contributor Author

@c960657 c960657 Nov 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't blame you for being a bit confused about my various PR's. I am a confused myself 🤪. Some of them overlap or extend each other. I'll try to clarify my intentions. For now, I think this PR is the most important one, because it fixed a regression introduced in v2.2.0 (by me 😞).

In #123, I proposed a configurable default locale as an alternative to providing the locale when creating the provider. However — as noted in my last comment in that PR) — I confused the concepts of default locale (the locale to use if no locale is provided explicitly for Yasumi::create()) versus fallback locale (the locale to use as fallback if a given holiday does not have a translation in the requested locale), so I have closed that PR for now. Part of it is split out into a separate PR, #184.

By the above definition, the DEFAULT_LOCALE constant is a fallback locale. It is hardcoded to English, because most holidays have an English translation (in fact, I think it would be cool to ensure an en translation for all holidays — but let's discuss that in a separate PR).

I think it is reasonable to hardcode en or en_US as fallback locale. This is a final resort before returning shortName.

I guess there is a case for making the fallback locale configurable or even providing multiple fallback locales. For example, when using a Catalan locale, you may prefer falling back to Spanish before resorting to English. This could be incorporated into #184, so that getName() is extended to accept not only a locale but an array of locales.

TL;DR
I suggest merging this PR, then consider #184. Eventually I will make a new proposal about a default locale (a new version of #123).

I hope this makes sense 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! I understand now. Guess that's why we have reviews :)

When I started this library I hardcoded the fallback locale however with the intention of making it configurable one day. I opted not doing it immediately but wanted to focus on the core first. Making improvements step by step...

@stelgenhof stelgenhof merged commit ce7b32d into azuyalabs:develop Nov 10, 2019
@c960657 c960657 changed the title Use fallback from DEAULT_LANGUAGE to 'en' Use fallback from DEFAULT_LANGUAGE to 'en' Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants