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

NAME

DeltaX::Language - Perl module for reading language files

     _____
    /     \ _____    ______ ______ ___________
   /  \ /  \\__  \  /  ___//  ___// __ \_  __ \
  /    Y    \/ __ \_\___ \ \___ \\  ___/|  | \/
  \____|__  (____  /____  >____  >\___  >__|
          \/     \/     \/     \/     \/        project

SYNOPSIS

 use DeltaX::Language;

 my $lang_file = new DeltaX::Language('my_lang.EN');
 my $texts = $lang_file->read();
 my @conflicts = $lang_file->get_conflicts();

 print $texts->{'text_id'};

FUNCTIONS

new()

Constructor. The first argument is a filename (required), second (optional) field separator (default is a tabelator ('\t')), other arguments are in key => value form, they are directive definitions in "directive_name => sub reference" form (see "DIRECTIVES").

read()

This function reads given file and returns undef (in case of error) or reference to a hash in which keys are text id's and values a texts themselfs.

get_error()

This function returns error in textual form (only valid after read() call).

get_conflicts()

This function returns array with text id's which occured more than once (in result of read() function will be only the last one). Only valid after read() call.

TEXT FILE STRUCTURE

Text files have a simple structure: one line = one record, in key<separator>text form. Everything form # sign to end of line is a comment, except #!<directive> (see "DIRECTIVES"). Everything other (empty lines, ...) is ignored.

Example:

 # this is comment
 #
 id1_This is text
 id2_This is another text
 #!include other_file

 [character _ means separator, often tabelator ('\t')]

DIRECTIVES

Directives are special form of comments: #!directive [parameters]. DeltaX::Config knows two of them:

include

It includes given file. Filename of included file is the first and only argument. If it is not absolute path, path is got from actually readed filename.

separator

It sets given character as a new separator, it can be in escaped form (for example #!separator \t). You cannot set new line or space as a separator using this directive.

every other

By setting parameter to new() you can define other directives and use it in your files. Every definition must be sub reference. This sub will be called with all arguments for this directive.

 Program:

  sub myspec_func {
    my $arg = shift;

    # return reference to a hash or undef in case of error
  }

  my $conf = new DeltaX::Language('my_lang.EN',myspec=>\&myspec_func);

 Configuration file:

  #!myspec something