php gettext and poedit - What would be faster using constructor or without -


i store attributes , options in class attributes.

public static $ethnicity = array(0 => '-', 1 => 'asian', 2 => 'black / african descent', 3 => 'east indian', 4 => 'latino / hispanic', 5 => 'middle eastern', 6 => 'native american', 7 => 'pacific islander', 8 => 'white / caucasian', 9 => 'other'); 

why keep them in code , not db story. have problem poedit because can not read dynamic translations. have 2 options:

a) put array values 1 single dump file. file used poedit parser:

_('asian'), _('black / african descent'), ... 

in way can call translations in view in following way:

echo _(attributes::$ethnicity[3])); 

b) can use constructor , call gettext there.

class attributes { public function __construct() { $this->ethnicity = array(0 => _('-'), 1 => _('asian'), 2 => _('black / african descent'), 3 => _('east indian'), 4 => _('latino / hispanic'), 5 => _('middle eastern'), 6 => _('native american'), 7 => _('pacific islander'), 8 => _('white / caucasian'), 9 => _('other')); //... } } 

in way can call translations in view in following way:

$attr = new attributes; echo $attr->ethnicity[3]; 

now questions:

let's there 10 attributes , on average 40 options, 400 array pairs. using construct in way slow application @ way? because mean everytime call constructor, gettext called array values, if attribute value not displayed in view. if don't use constructor, gettext called single attributes values used.

i did ab test, surprised because there weren't difference. worried must missing sense calling constructor in way make slowing.

i stick solution b it's cleaner , after few months still know $attr->ethnicity[3]; does.

if still unsure, try stress test - try call constructor many times. humble opinion there no significant difference. if don't need call many times in live application. gettext designed fast.


Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -