Localized plugin and CakePHP3.x
dereuromark opened this issue · 29 comments
So @markstory and I discussed the future of this plugin regarding the next major version of the framework.
So basically:
- Remove the hardcoded localized validation from the core.
- Provide app/plugin hooks to allow this plugin to take over.
Validation::phone($number, 'Localized.De')
We have 3 methods defined by the interface:
- phone()
- postal()
- personId()
That need to work this way, for sure.
Any comments regarding this approach?
What about follow the same standard used on the core classes? Probably something like Validation::config(DeValidation::consume())
@jrbasso Where would a developer do that? Would you be able to wire up multiple locales?
Personally I think we should just use the providers system in 3.0 validators instead of the static class.
Is something common to switch between locales? I know for big countries like US and BR they usually specify one language/locale and that's it, but I can see it maybe being an issue for EU.
One option would be call the Validation::config()
every time you switch the context, or make the config receive multiple locale configs and simplify the usage, something like:
Validation::config('de', DeValidation::consume());
Validation::config('us', UsValidation::consume());
// Or shortly Validation::config(['de' => DeValidation::consume(), 'us' => UsValidation::consume()])
// Using it
Validation::phone($number, 'de');
@lorenzo Are we more clear now how we can best hook this plugin into 3.x? To have an easy to use API for validation here?
@dereuromark not yet, I will have a proposal once the validation stuff is re-worked
@lorenzo Any news on this?
I think we should probably try to integrate/leverage existing and quite extensive validation libraries in 3.x.:
@dereuromark Integrating those variables is probably a good idea. The tools to migrate this plugin are already there. We just need to create Validation providers with country-specific rules. I don't have the time to do it myself, though... Would you like to lead the task?
I started the new master branch for 3.x.
The question would now be how to best implement those libraries.
@dereuromark Could the developer provide the format they wanted? Sniffing from locales seems a little too magical.
I think so, providing some inversion of control we should be able to allow them to configure it way more freely than in the past.
Hey ,
How about not require on cake , but only on the necessary package in the require ? It looks it needs validation and only intl . Or am I wrong in understanding it ?
Thank you
@harikt That's true for now but this plugin also aims to provide translations for the core messages
Are we fine with making a first 3.0.0 plugin release now?
We can enhance it with the mentioned vendor packages mentioned here on top in a future version maybe?
//cc @antograssiot
@dereuromark ok for me
@dereuromark I would like to update the global namespace to Cake\Localized
before.
Any thoughts ?
i can handle it tonight or tomorrow
Do we do that for any other core plugin? If not, I would not do it here either.
@dereuromark I thought we does but it seems that only Chronos has it.
Not everywhere. For instance, ElasticSearch has it ; Migrations does not have it.
Hi,
both are ok. There should be made a consolidation from both. The name should be something like ro_ro not ro_rom, not ro_ron.
Regards,
@MihaiTL thanks for your answer ! we'll keep the https://github.com/cakephp/localized/blob/master/src/Locale/ro_ron/cake.po file because it contains accents. I'll open a PR
I'm 👍 for changing the global namespace to Cake\Localized
.
Maybe we could prefix all CakePHP core plugins with Cake\
to avoid interferences with users plugins
doh! I forgot about this. @dereuromark @HavokInspiration what's your opinion on the namespace update to Cake\Localized
before we ship it ?
That makes sense to me to prefix the plugins.
But we should probably do it for every plugins. I'm just afraid for the migrations plugin since migrations classes are subclasses from the plugin. But that concern can be discussed in the migrations repo.
Sounds like we can release now!
yeah go ahead @dereuromark if you find time for it.
Hey guys, sorry to ask this here but I prefer it than creating a new issue for just a question related to localization.
In the readme file you say that I should copy the cake.po
file to its location, but I also have the main cake.po
file there (the one extracted using i18n extract).
Should I merge them? How? Manually?
Ok thanks to lorenzo I've seen that it is a replacement, so I only need to replace it.