Locale::MakePhrase::BackingStore - base-class of the backing store functionality.
This is a base-class, of storage-specific implementations for the Locale::MakePhrase module.
The backing-store may choose to implement seperate files for each language, or a single file for all languages. It may choose to implement database lookup... and so on.
This base class implements a generic implementation, which can be used as a starting point. You should also look at Locale::MakePhrase::BackingStore::<some module> for more examples.
Locale::MakePhrase implements the following backing stores:
Single file for all languages (see backing store: File)
Files stored within a directory (see backing store: Directory)
Generic database table (see backing store: Database)
PostgreSQL database table (see backing store: Database::PostgreSQL)
Alternatively, you could implement an application specific backing store by doing the following:
Make a package which derives from this class.
Implement the init() method, retrieving any options that may have been supplied to the constructor.
Overload the get_rules() method, returning a list-reference of Locale::MakePhrase::LanguageRule objects, from the translations available from your backing store.
For an implementation which uses a text file, this could mean that you would load the text file if it has changed, constructing the rule objects during the load, then return a list-reference of objects which match the request.
For a database implementation, you would need to query the database for translations which match the request, then construct rule objects from those translations.
The following methods are implemented:
Construct a backing store instance; arguments are passed to the init() method.
Allow sub-class to control construction. The sub-class must return itself, so as to make construction succeed.
Returns a list-reference of rule objects which have just been retrieved from the storage mechanism. The objects will have been based on the values of the $context (which is a stringified version of whatever get passed to context_translate or a value of undef), the $key (which is your application text string) and the language tags that Locale::MakePhrase determined for this instance.
context_translate
Since this is a base class, you need to supply a real implementation, although you can still use Locale::MakePhrase with this minimal implementation, so as to allow you to continue application development.
This is a helper routine for making a LanguageRule object. ie: you would use it like this, within your get_rules() method:
sub get_rules { ... my $rule_obj = $self->make_rule( key => $key, language => $lang, expression => $expression, priority => $priority, translation => $translation, ); ... }
Thus, it takes a hash or hash_ref with the options: key, language, expression, priority and translation
key
language
expression
priority
translation
To install Locale::MakePhrase, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::MakePhrase
CPAN shell
perl -MCPAN -e shell install Locale::MakePhrase
For more information on module installation, please visit the detailed CPAN module installation guide.