Cphalcon: Missing translation in NativeArray should (optionaly) raise a warning

Created on 4 Aug 2017  路  2Comments  路  Source: phalcon/cphalcon

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.

enhancement

Most helpful comment

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 '';禄
}

All 2 comments

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 '';禄
}

This has been addressed

Was this page helpful?
0 / 5 - 0 ratings