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

Load custom dict with locale set on non supported one #2

Closed
aletundo opened this issue May 27, 2017 · 4 comments
Closed

Load custom dict with locale set on non supported one #2

aletundo opened this issue May 27, 2017 · 4 comments

Comments

@aletundo
Copy link

aletundo commented May 27, 2017

Hi @arandilopez ! First of all I really appreciated your package.

I'm trying to use a custom dictionary file loading it as following:
'name' => 'required|string|max:100|profane:en,' . resource_path('lang/it/profane.php')

My locale is set on it language which is not supported out of the box. I'm stuck on this exception:

ErrorException(code: 0): include(it): failed to open stream: No such file or directory at /var/www/myproject/vendor/arandilopez/laravel-profane/src/ProfaneValidator.php:85

I debugged your code a little bit. I noticed that the variable $dictionary used in line ProfaneValidator.php:85 contains the locale value. So it expects a path but it is the locale string.

As ultimate test I tried to change $dict = include($dictionary); on line 85 with $dict = include(resource_path('path/to/my/dict.php'); at it worked.

Thank you!

@arandilopez
Copy link
Owner

Hi @aletundo. Thanks for this issue.. I will try replicate it. Would you lend me your it dictionary to test it? You can also help me to include that dict to the base, like en and es as well

Regards!

@aletundo
Copy link
Author

Would you lend me your it dictionary to test it?

Yes, for sure!
it_dict.txt

It was a merge of the dictionaries from banbuilder and Laravel5-Profanity-Filter.

You can also help me to include that dict to the base, like en and es as well.

Okay! I may make a pull a request.. I have just to give look at your unit tests.

@arandilopez
Copy link
Owner

@aletundo Well, the error is because I don't have a it.php in the dicts directory... Just a validation more to wont try to load a locale missing file when you do 'locale' => 'it'. But the file path you passed will be loaded like here:

<?php
// ....

    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|profane:en,es,'.resource_path('lang/it/dict.php')
        ]);

        // In case it passes
        return response()->json(['name' => $request->input('name')]);
    }

You can send a pull request to add that it.php dictionary you have.. I don't know Italian but I trust in you 😄

Regards!

@aletundo
Copy link
Author

@arandilopez I got the point! It works now!

I'm going to make a pull request asap.

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

No branches or pull requests

2 participants