The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Locale::MakePhrase::BackingStore - base-class of the backing store functionality.

DESCRIPTION

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:

  1. Make a package which derives from this class.

  2. Implement the init() method, retrieving any options that may have been supplied to the constructor.

  3. 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.

API

The following methods are implemented:

new()

Construct a backing store instance; arguments are passed to the init() method.

$self init([...])

Allow sub-class to control construction. The sub-class must return itself, so as to make construction succeed.

\@rule_objs get_rules($context,$key,\@languages)

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.

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.

$rule_obj make_rule()

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