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

Comments

Projects
3 participants
@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

This comment has been minimized.

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 this to the 4.0.0 milestone Aug 6, 2017

@stale stale bot added the stale label Apr 16, 2018

@sergeyklay sergeyklay closed this Apr 16, 2018

@sergeyklay sergeyklay reopened this May 2, 2018

@stale stale bot removed the stale label May 2, 2018

@phalcon phalcon deleted a comment from stale bot Dec 23, 2018

@niden niden added this to To do in 4.0 Release via automation Dec 23, 2018

@niden niden self-assigned this Dec 23, 2018

niden added a commit to niden/cphalcon that referenced this issue Jan 4, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 4, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 4, 2019

@niden niden referenced this issue Jan 4, 2019

Merged

T13007 nativearray missing #13730

3 of 3 tasks complete

@niden niden moved this from To do to In progress in 4.0 Release Jan 4, 2019

niden added a commit that referenced this issue Jan 5, 2019

Merge branch 'niden-T13007-nativearray-missing' into 4.0.x
* niden-T13007-nativearray-missing:
  [#13007] - Correction to the changelog
  [#13007] - Updated the CHANGELOG
  [#13007] - Added notFound in the nativearray translate adapter

@niden niden moved this from In progress to Done in 4.0 Release Jan 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 5, 2019

[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
* upstream/4.0.x:
  [phalcon#13007] - Correction to the changelog
  [phalcon#13007] - Updated the CHANGELOG
  [phalcon#13007] - Added notFound in the nativearray translate adapter
@niden

This comment has been minimized.

Copy link
Member

niden commented Jan 5, 2019

This has been addressed

@niden niden closed this Jan 5, 2019

niden added a commit to niden/cphalcon that referenced this issue Jan 9, 2019

@niden niden referenced this issue Jan 9, 2019

Merged

T13007 nativearray missing patch #13748

3 of 3 tasks complete

niden added a commit to niden/cphalcon that referenced this issue Jan 9, 2019

niden added a commit that referenced this issue Jan 10, 2019

T13007 nativearray missing patch (#13748)
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment