I have a large language file with the following structure:
Click here|Cliquez ici
New|Nouveau
...
Then I have an application in English and French. The language file is loaded by CONF.pm into hash %t
, which is used like this throughout the application:
<input type="button" value="$t{'Click here'}">
<a href="new.pl">$t{'New'}</a>
...
So, depending on the user setting, the application is displayed in English or French. For this, the large language file must first be loaded by CONF.pm in order to fill %t
.
The problem is that most of our users are English, and we loose quite some memory by loading the language file every time. The language file is not "really" necessary for an English user, because the value of $t{'Click here'}
will always be Click here
.
You will agree that this is probably not the most intelligent language config design. Does Perl have a possibility to NOT load the languae file, when the user is English ? Just display the key of the hash, when the value is undefined ?
<input type="button" value="Click here">
<a href="new.pl">New</a>
I can't go change all the $t{'...'}
in the application files, there must be many thousands. Not loading the large language file for every single request would save me a good deal of memory.
I think that this can be done with tied hashes. So when the language is English then you could set the hash %t
to be a hash tied to Tie::Hash::Identity. In that case the value returned for the key would be the key itself. For French you would still import the whole mapping.