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

NAME

DateTime::Format::Natural::Lang::Authoring - Authoring the language metadata

DESCRIPTION

Whenever a language is provided via the lang parameter to DateTime::Format::Natural's constructor new, parse_datetime will subsequently use the translation metadata found within, for example, DateTime::Format::Natural::Lang::EN, if we chosen the english language.

STRUCTURE

The layout of a translation class will be explained by examining the class providing the english metadata, DateTime::Format::Natural::Lang::EN:

The header should somehow resemble following piece of code:

 package DateTime::Format::Natural::Lang::EN;

 use strict;
 use warnings;
 use base qw(DateTime::Format::Natural::Lang::Base);

 our $VERSION = '0.6';

 our (%data_weekdays, %data_months, %main, %ago, %now, %daytime, %months,
      %number, %at, %this_in, %next, %last, %day, %setyearday);

Substitute EN with the appropriate language code. Use $VERSION = '0.1' if it's a initial release, otherwise replace it with your custom version number.

 {
     my $i = 1;

     %data_weekdays = map { $_ => $i++ } qw(Monday Tuesday Wednesday Thursday
                                            Friday Saturday Sunday);
     $i = 1;

     %data_months = map { $_ => $i++ } qw(January February March April
                                          May June July August September
                                          October November December);
 }

Replace %data_weekdays with the weekdays in your language chosen. The same with %data_months concerning months.

 %main = ('second'         => qr/^second$/i,
          'ago'            => qr/^ago$/i,
          'now'            => qr/^now$/i,
          'daytime'        => [qr/^(?:morning|afternoon|evening)$/i],
          'months'         => [qw(in this)],
          'at_intro'       => qr/^(\d{1,2})(?!\d|st|nd|rd|th)(\:\d{2})?(am|pm)?|(noon|midnight)$/i,
          'at_matches'     => [qw(day in month)],
          'number_intro'   => qr/^(\d{1,2})(?:st|nd|rd|th)? ?$/i,
          'number_matches' => [qw(day week month in)],
          'weekdays'       => qr/^(?:this|next|last)$/i,
          'this_in'        => qr/^(?:this|in)$/i,
          'next'           => qr/^next$/i,
          'last'           => qr/^last$/i,
          );

This is the hash with contains the regular expressions for the parse_datetime() routine in DateTime::Format::Natural.

 %ago = ('hour'  => qr/^hour(?:s)?$/i,
         'day'   => qr/^day(?:s)?$/i,
         'week'  => qr/^week(?:s)?$/i,
         'month' => qr/^month(?:s)?$/i,
         'year'  => qr/^year(?:s)?$/i,
        );

%ago contains the regular expressions for strings such as 1 hour ago, 10 weeks ago & 3 years ago.

 %now = ('day'    => qr/^day(?:s)?$/i,
         'week'   => qr/^week(?:s)?$/i,
         'month'  => qr/^month(?:s)?$/i,
         'year'   => qr/^year(?:s)?$/i,
         'before' => qr/^before$/i,
         'from'   => qr/^from$/i,
         );

%now contains the regular expressions for strings such as 1 day before now, 4 months from now & 3 years from now.

 %daytime = ('tokens'     => [ qr/\d/, qr/^in$/i, qr/^the$/i ],
             'morning'    => qr/^morning$/i,
             'afternoon'  => qr/^afternoon$/i,
             );

%daytime contains the regular expressions for strings such as 7 in the morning & 4 in the afternoon.

 %months = ('number' => qr/^(\d{1,2})(?:st|nd|rd|th)? ?$/i);

%months contains the regular expression for matching days within a month.

 %number = ('month'  => qr/month(?:s)/i,
            'hour'   => qr/hour(?:s)/i,
            'before' => qr/before/i,
            'after'  => qr/after/i,
           );

%number contains the regular expressions for strings such as 7 hours before & 1 month after.

 %at = ('noon'     => qr/noon/i,
        'midnight' => qr/midnight/i,
       );

%at contains the regular expressions for strings such as noon & midnight.

 %this_in = ('hour'   => qr/hour(?:s)/i,
             'week'   => qr/^week$/i,
             'number' => qr/^(\d{1,2})(?:st|nd|rd|th)?$/i,
            );

%this_in contains the regular expressions for strings such as in 1 hours & this week.

 %next = ('week'   => qr/^week$/i,
          'day'    => qr/^day$/i,
          'month'  => qr/^month$/i,
          'year'   => qr/^year$/i,
          'number' => qr/^(\d{1,2})(?:st|nd|rd|th)$/,
         );

%next contains the regular expressions for strings such as next week, next day, next month & next year.

 %last = ('week'   => qr/^week$/i,
          'day'    => qr/^day$/i,
          'month'  => qr/^month$/i,
          'year'   => qr/^year$/i,
          'number' => qr/^(\d{1,2})(?:st|nd|rd|th)$/,
          );

%last contains the regular expressions for strings such as last week, last day, last month & last year.

 %day = ('init'         => qr/^(?:today|yesterday|tomorrow)$/i,
         'yesterday'    => qr/yesterday/i,
         'tomorrow'     => qr/tomorrow/i,
         'noonmidnight' => qr/^noon|midnight$/i,
         );

%day contains the regular expressions for strings such as yesterday, tomorrow, noon & midnight.

 %setyearday = ('day' => qr/^day$/i,
                'ext' => qr/^(\d{1,3})(?:st|nd|rd|th)$/,
               );

%setyearday sets the year day.

 1;

Every package has to return a true value.

SEE ALSO

DateTime, Date::Calc, http://datetime.perl.org

AUTHOR

Steven Schubiger <schubiger@cpan.org>

LICENSE

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html