azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.04k stars 152 forks source link

Locale override for getName() #184

Closed c960657 closed 4 years ago

c960657 commented 4 years ago

Sometimes you need multiple translations for the same holiday.

Pre v2.2.0 you could easily access all translations in $holiday->translations. With the introduction of locale fallback in #176, things got more complicated, especially with substitute holidays (introduced in #162), so accessing the translations property is difficult.

I suggest adding an optional $locale parameter to $holiday->getName().

This fixes #181.

This suggestion is a subset of what was proposed in #123. This PR does not include the default locale part, only the locale override.

c960657 commented 4 years ago

One further possible feature would be allowing the user override the “default fallback locale chain”, e.g. by passing an array of locales instead of just a string.

E.g. $holiday->getName('ca_ES') would look for translations in Catalan with fallback to English, while $holiday->getName(['ca_ES', 'es_ES', 'en']) would look for Catalan, then Spanish, and finally English.

c960657 commented 4 years ago

I have created a alternative PR that implements the suggestion in my latest comment: #195.

github-actions[bot] commented 4 years ago

This pull request has been open 30 days with no activity. Please remove the stale label or comment, or this will be closed in 5 days

stelgenhof commented 4 years ago

@c960657 I have reviewed and merged your other PR. I guess we can close this one, right?

c960657 commented 4 years ago

Yes, this PR is no longer relevant.