DateTime::Format::Natural::Lang::Authoring - Authoring the translation metadata
Whenever a language is provided via the lang parameter to DateTime::Format::Natural's parse_datetime, parse_datetime will subsequently use the translation metadata found within, for example, DateTime::Format::Natural::Lang::EN, if we chosen the english language.
lang
DateTime::Format::Natural's
parse_datetime
DateTime::Format::Natural::Lang::EN
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.5'; our (%data_weekdays, %data_months);
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.
EN
$VERSION = '0.1'
{ 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.
%data_weekdays
%data_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.
parse_datetime()
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.
%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.
%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.
%daytime
%months = ('number' => qr/^(\d{1,2})(?:st|nd|rd|th)? ?$/i);
%months contains the regular expression for matching days within a month.
%months
%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.
%number
%at = ('noon' => qr/noon/i, 'midnight' => qr/midnight/i, );
%at contains the regular expressions for strings such as noon & midnight.
%at
%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.
%this_in
%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.
%next
%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.
%last
%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.
%day
%setyearday = ('day' => qr/^day$/i, 'ext' => qr/^(\d{1,3})(?:st|nd|rd|th)$/, );
%setyearday sets the year day.
%setyearday
1;
Every package has to return a true value.
DateTime, Date::Calc, http://datetime.perl.org/
Steven Schubiger <schubiger@cpan.org>
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
To install DateTime::Format::Natural, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTime::Format::Natural
CPAN shell
perl -MCPAN -e shell install DateTime::Format::Natural
For more information on module installation, please visit the detailed CPAN module installation guide.