aryehraber / statamic-captcha

Statamic Addon that protects your Statamic forms using a Captcha service.
MIT License
11 stars 8 forks source link

Add Localization #30

Closed fjahn closed 2 years ago

fjahn commented 2 years ago

Closes #28.

Since the error_message key is removed, this is a minor breaking change.

If users want to change the error message in the future, they need to publish the translation file by running php please vendor:publish --tag="captcha-translations". I added a section to the readme describing this process.

During development, I more or less adapted the way translations are handled in the Duplicator addon by Duncan McClean, since it seemed pretty reasonable to me. Let me know if there is a problem somewhere.

aryehraber commented 2 years ago

Hi @fjahn, this looks great, thanks so much!

The throwIfInvalid() method is a nice touch, I've been meaning to extract the throw call since there are numerous listeners (started off the addon with just 1).

I'd like to avoid breaking changes if possible so I may still look into falling back to the error_message config key if it exists (which will only be the case for upgrading users). I do prefer the translation file way of working going forward.

Will try and merge and release this weekend!

fjahn commented 2 years ago

You are welcome, thank you for the awesome addon!

I did not really think about the fact that a fallback to the config key would be very easy, so I am all for it as well!

fjahn commented 2 years ago

I just added my take of handling backwards compatibility with 087003af909a823679d7171373c73c10078e30c8:

If you have something different in mind, feel free to revert or drop the commit. I was thinking about adding a deprecation message somewhere, but I do not really know where to put that.

aryehraber commented 2 years ago

Hi @fjahn, thanks again for your PR!

Ended up making some minor changes because I was seeing 2 lang files being published after running the command:

$ php please vendor:publish --tag="captcha-translations"
Copied Directory [/Users/aryeh/Code/Packages/statamic-captcha/addon/resources/lang] To [/resources/lang/vendor/statamic-captcha]
Copied Directory [/Users/aryeh/Code/Packages/statamic-captcha/addon/resources/lang] To [/resources/lang/vendor/captcha]
Publishing complete.

I think this is because Statamic does some automagic stuff based on naming conventions, so I just simplified a few things.

Other than that I'm very happy with these changes, good stuff 👍