Commit f7b34e98 authored by Franco Fichtner's avatar Franco Fichtner

lang: properly extract our volt template strings

parent 8b018c4d
all:
_XGETTEXT!= which xgettext || echo true
XGETTEXT= ${_XGETTEXT} -L PHP --from-code=UTF-8 -F --strict --debug
_XGETTEXT_PL!= which xgettext.pl || echo true
XGETTEXT_PL= ${_XGETTEXT_PL} -P Locale::Maketext::Extract::Plugin::Volt \
-u -w -W
_MSGFMT!= which msgfmt || echo true
MSGFMT= ${_MSGFMT} --strict
_MSGMERGE!= which msgmerge || echo true
MSGMERGE= ${_MSGMERGE} -U -N --backup=off
PERL_DIR= /usr/local/lib/perl5/site_perl
PERL_NAME= Locale/Maketext/Extract/Plugin
PERL_CP!= cp -v ${.CURDIR}/Volt.pm ${PERL_DIR}/${PERL_NAME}/
LOCALEDIR= /usr/local/share/locale/%%LANG%%/LC_MESSAGES
# stable
......@@ -19,6 +24,12 @@ INSTALL=
MERGE=
PLIST=
PAGER?= less
all:
@cat ${.CURDIR}/README.md | ${PAGER}
.for LANG in ${LANGUAGES}
${LANG}DIR= ${LOCALEDIR:S/%%LANG%%/${LANG}/g}
install-${LANG}:
......@@ -38,6 +49,8 @@ MERGE+= merge-${LANG}
${TEMPLATE}:
@: > ${TEMPLATE}.pot
cd ${.CURDIR}/.. && \
${XGETTEXT_PL} -D src -p ${.CURDIR} -o ${TEMPLATE}.pot
cd ${.CURDIR}/.. && find src lang/dynamic/helpers | \
xargs ${XGETTEXT} -j -o ${.CURDIR}/${TEMPLATE}.pot
......
OPNsense language translation kit
=================================
The kit requires additional tools in order to properly extract strings
from the source code. You'll need to run this once locally:
# pkg install gettext-tools p5-Locale-Maketext-Lexicon python27
Regenerate dynamic strings that can't be found in the template
generation step (XML contents, etc.):
# make dynamic
Regenerate the translation template using:
# make template
Merge the latest template changes into the actual translations:
# make merge
The build system will automatically pick up all registered languages.
package Locale::Maketext::Extract::Plugin::Volt;
$Locale::Maketext::Extract::Plugin::Volt::VERSION = '1.00';
use strict;
use base qw(Locale::Maketext::Extract::Plugin::Base);
# ABSTRACT: Volt template parser
sub file_types {
return qw( volt );
}
sub extract {
my $self = shift;
local $_ = shift;
my $line = 1;
# Volt Template:
$line = 1;
pos($_) = 0;
while (m/\G(.*?(?<!\{)\{\{(?!\{)\s*lang\._\('(.*?)'\)\s*\}\})/sg) {
my ( $vars, $str ) = ( '', $2 );
$line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext!
$self->add_entry( $str, $line, $vars );
}
}
1;
__END__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment