jama5262 / jiffy

Jiffy is a Flutter (Android, IOS and Web) date time package for parsing, manipulating, querying and formatting dates
https://pub.dev/packages/jiffy
MIT License
588 stars 126 forks source link

Bring back some way to obtain a list of supported locale codes by Jiffy #237

Closed deezee30 closed 1 year ago

deezee30 commented 1 year ago

Is your feature request related to a problem? Please describe.

Since 6.0.0, there is currently no way (as far as I know) to obtain which locales are supported by Jiffy. Prior to 6.0.0, I've regularly used Jiffy.getAllAvailableLocales() to find and match the closest locale to the one currently chosen by the user. Some locale codes include or lack a region associated with the language. In a hypothetical scenario these regions (as well as the language) can be custom ones or not included in the locale code standards. Additionally, Jiffy does not support all languages and corresponding regions codes. My solution was to scan through available locales and match, in priority, a user's selected locale exactly to one supported by Jiffy. If not found, then match a language without the region. If not found, then match a language with a different region. If still not found, match a default locale that is definitely supported by both. It worked very well. Now, there is no functionality to do this anymore. In addition, Jiffy uses en_US as a default locale if it wasn't found through setLocale or other means which may not be desirable if it cannot be configured or at least checked for compatibility prior to calling setLocale.

Describe the solution you'd like

Possible simple solutions:

Describe alternatives you've considered

Currently, I have to resort to making my own list of supported Jiffy locales separately to which locales my app fundamentally supports, based on available_locales.dart and update it manually between Jiffy versions, which is not ideal.

Additional context

Not required.

jama5262 commented 1 year ago

@deezee30 Hmmm, I would advise against relying solely on Jiffy's locales. In terms of design, it is better to maintain your own list of locales that you can provide to your users. This approach gives you complete control and avoids excessive dependence on Jiffy.

By managing your own locales, you can customize the options to fit your specific needs, ensuring a more tailored and controlled experience for your users.

So in short, having your own list of supported locales is the best approach in my opinion

What do you think?

deezee30 commented 1 year ago

@jama5262 Completely agree with you. And that's what we are currently doing.

However, our own supported locales differ to Jiffy's. But when a user switches a locale within the app, we would like to configure Jiffy to change its locale too to keep it consistent. The issue lies in the fact that the chosen locale may not be supported by Jiffy. That's why we try to match the next closest locale based on what Jiffy does support.

Sorry for not being clear enough the first time.

jama5262 commented 1 year ago

Hmm, ok 👍 , I will add getAllAvailableLocales() function back to Jiffy, will update when it's fully released, won't be long

deezee30 commented 1 year ago

Thanks for all your great work :)

jama5262 commented 1 year ago

This feature is now available and published in release https://github.com/jama5262/jiffy/releases/tag/v6.2.0