I just joined this party but I think I’ve got the jist of what you’re trying to do.
I don’t think you need to consider performance at this stage, if the file is in use it will probably be in (file system) cache anyway, and looking into this now would probably be considered premature optimizations. I’m quite confident this file can grow quite a bit without much performance issues.
[php]<?php
// Load translation cache
$lang = array(
‘entry1’ => “this would be the translation for entry1”,
‘entry2’ => “this would be the translation for entry2”,
);
// Remove from translation cache
unset($lang[‘entry1’]);
// Add to translation cache
// Warning: This will replace the content of $lang[‘new_key’] if it exists
$lang[‘new_key’] = ‘New value’;
// On the flip side this could be used to update language keys as well
$lang[‘entry2’] = ‘Updated translation for entry2’;
// Update cache file
// Save this string instead of echoing it
echo '<?php
$lang = ’ . var_export($lang, true) . ‘;’;
/*
Output
ps: you don’t need to have ? > at the end of files
<?php
$lang = array (
'entry2' => 'Updated translation for entry2',
'new_key' => 'New value',
);
*/[/php]
If you do it like this you will have to use the method above to update/save the file every time you make changes to the array.