Author image Mathew Robertson
and 1 contributors


Locale::MakePhrase::Print - Overload of print to automate translations


Using this module, it will override print statements so that your application automatically gets translated into the target language.


Your application will have previously instantiated a Locale::MakePhrase object in some other module. Now you need to use that instantiation within a particular module; from here:

  use Locale::MakePhrase::Print;
  print "Some text to be translated.";

When print is called, the text is automatically fed into the translation engine.


The purpose of this module, is to de-couple the use of the translation engine, from the API of the translation engine. This saves you from littering your application code with translation-specific function calls. The main benefits are:

  • makes the code easier to read

  • allows you to easily change to a different translation engine

  • decouples translation from application design


To use this module, you simply need to use it at the top of your own module. You can optionally specify a specific filehandle to print to (rather than STDOUT), eg:

  use Locale::MakePhrase::Print;
  print "Some text";


  open(FH,">some_output_file.txt") or die;
  use Locale::MakePhrase::Print \*FH;
  print "Some text";

Will print Some text to STDOUT or the specified filehandle.

To stop overriding print:

  no Locale::MakePhrase::Print;

println "..." [, ...]

This function is explicatly exported so that users can avoid having to specify the newline character in the translation key.

Note: when no Locale::MakePhrase::Print is in effect, println simply prints out the un-translated string, including a the newline.


This module overrides print only for the STDOUT filehandle; this also applies to exported the println function. ie: specifying a filehandle to print will result in no translation occurring, or some weired error if used with println.

Thus to specifically avoid using the overridden print function, explicatly specify the filehandle as in:

  print STDOUT "Some un-translated text.";