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

Missing translation in NativeArray should (optionaly) raise a warning #13007

Closed
dugwood opened this issue Aug 4, 2017 · 2 comments
Closed

Missing translation in NativeArray should (optionaly) raise a warning #13007

dugwood opened this issue Aug 4, 2017 · 2 comments
Assignees
Labels
enhancement Enhancement to the framework
Milestone

Comments

@dugwood
Copy link
Contributor

dugwood commented Aug 4, 2017

Expected and Actual Behavior

When using NativeArray (https://github.com/phalcon/cphalcon/blob/master/phalcon/translate/adapter/nativearray.zep) on a missing key, the key itself is returned if there's no translation for this key.

A warning should be raised to deal with such a situation, avoiding displaying keys on the production website. It's not a security issue, but that should help displaying what's intended.

Details

  • Phalcon version: since 2.x
  • PHP Version: not relevant
  • Operating System: not relevant
  • Installation type: compilation (Linux)
  • Zephir version (if any): not relevant
  • Server: not relevant

I can create a pull request for this, just tell me if you have a specific implementation to follow: throw an exception (I see that you have Phalcon\Translate\Exception), passing a function...
And option would be exceptionOnMissingKey or anything you'd prefer, defaulting to false of course.

@dugwood
Copy link
Contributor Author

dugwood commented Aug 4, 2017

An exception may be too difficult to deal with, it should be a function:
new NativeArray(['content' => [], 'onMissingKey' => $myfunction]

The function may return the key, overriding the code:
https://github.com/phalcon/cphalcon/blob/master/phalcon/translate/adapter/nativearray.zep#L63

Example of function to pass:

function missingKey($key) {
    trigger_error('Can\'t find translation key: '.$key);
    return $key; // or better, return nothing with «return '';»
}

@sergeyklay sergeyklay added the enhancement Enhancement to the framework label Aug 6, 2017
@sergeyklay sergeyklay added this to the 4.0.0 milestone Aug 6, 2017
@stale stale bot added the stale Stale issue - automatically closed label Apr 16, 2018
@sergeyklay sergeyklay reopened this May 2, 2018
@stale stale bot removed the stale Stale issue - automatically closed label May 2, 2018
@phalcon phalcon deleted a comment from stale bot Dec 23, 2018
@niden niden self-assigned this Dec 23, 2018
@niden niden mentioned this issue Jan 4, 2019
3 tasks
niden added a commit that referenced this issue Jan 5, 2019
* niden-T13007-nativearray-missing:
  [#13007] - Correction to the changelog
  [#13007] - Updated the CHANGELOG
  [#13007] - Added notFound in the nativearray translate adapter
@niden
Copy link
Member

niden commented Jan 5, 2019

This has been addressed

@niden niden closed this as completed Jan 5, 2019
niden added a commit that referenced this issue Jan 10, 2019
* [4.0.x] - PHPCS fix

* [4.0.x] -

* Revert "[4.0.x] -"

This reverts commit a828104.

* Revert "Revert "[4.0.x] -""

This reverts commit a438074.

* [4.0.x] - Code cleanup

* [4.0.x] - Added match to travis for issue branches

* [#13007] - Corrected implementation of not found and added test

* [#13007] - Corrected errors and exception
@niden niden added the 4.0 label Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to the framework
Projects
None yet
Development

No branches or pull requests

3 participants