# take the "base" template and return a version specialized to a specific language
sub translate_template {
    my $self = shift;
    my ( $lang, $class, $template ) = @_;

    my ( $langlong, $langshort ) = ( $lang =~ m/(([^-]+)(?:-.+)?)/ );

    my $replaces = {
        'langshort' => $langshort,
        'langlong'  => $langlong,
        'langdir'   => 'ltr',
    };

    # @TODO figure out how to parameterize this
    if ( $langshort eq 'ar' ) { $replaces->{'langdir'} = 'rtl'; }

    foreach my $replace ( keys %$replaces ) {
        $template =~ s/!!\$$replace/$replaces->{$replace}/g;
    }

    no strict 'refs';
    my $langfile = ${ $self->{'namespaces'}{$lang} . '::' . 'langfile' }->{$class};
    croak("Unknown class $class for language $lang\n") if !defined($langfile);
    use strict 'refs';

    $template =~ s[<!-- S=(.+?) -->.+?<!-- /S -->][$langfile->{$1}]g;

    return $template;
}