Commit 1b9d07fb authored by Franco Fichtner's avatar Franco Fichtner

template: improve parsing for escaped stuff, lint pass

The lint message doesn't have a file name, because the context is never
passed.  It's good enough for now to find this manually.
parent 7f2364e4
# Copyright (c) 2015-2016 Franco Fichtner <franco@opnsense.org> # Copyright (c) 2015-2017 Franco Fichtner <franco@opnsense.org>
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
...@@ -93,7 +93,8 @@ ${TEMPLATE}: ...@@ -93,7 +93,8 @@ ${TEMPLATE}:
@cp ${.CURDIR}/Volt.pm ${PERL_DIR}/${PERL_NAME}/ @cp ${.CURDIR}/Volt.pm ${PERL_DIR}/${PERL_NAME}/
@: > ${TEMPLATE}.pot @: > ${TEMPLATE}.pot
.for ROOTDIR in ${PLUGINSDIRS} ${COREDIR} ${LANGDIR} .for ROOTDIR in ${PLUGINSDIRS} ${COREDIR} ${LANGDIR}
if [ -d ${ROOTDIR}/src ]; then \ @if [ -d ${ROOTDIR}/src ]; then \
echo ">>> Scanning ${ROOTDIR}"; \
${XGETTEXT_PL} -D ${ROOTDIR}/src -p ${.CURDIR} -o ${TEMPLATE}.pot; \ ${XGETTEXT_PL} -D ${ROOTDIR}/src -p ${.CURDIR} -o ${TEMPLATE}.pot; \
find ${ROOTDIR}/src -print0 | \ find ${ROOTDIR}/src -print0 | \
xargs -0 ${XGETTEXT} -j -o ${.CURDIR}/${TEMPLATE}.pot; \ xargs -0 ${XGETTEXT} -j -o ${.CURDIR}/${TEMPLATE}.pot; \
......
...@@ -16,16 +16,24 @@ sub extract { ...@@ -16,16 +16,24 @@ sub extract {
my $line = 1; my $line = 1;
# Volt Template: # Volt Template: collect single-quoted translations
$line = 1;
pos($_) = 0; pos($_) = 0;
while (m/\G(.*?(?<!\{)\{\{(?!\{).*?[:]?\s*?lang\._\('(.*?)'\)\s*?[,\]]?.*?\|?.*?\}\})/sg) { while (m/\G(.*?(?<!\{)\{\{(?!\{).*?[:]?\s*?lang\._\(\s*'((?:[^\\']|\\.)*?)'\)\s*?[,\]]?.*?\|?.*?\}\})/sg) {
my ( $vars, $str ) = ( '', $2 ); my ( $vars, $str ) = ( '', $2 );
# escaped single-qutes must be unescaped now
$str =~ s/\\'/'/g;
$line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext! $line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext!
$self->add_entry( $str, $line, $vars ); $self->add_entry( $str, $line, $vars );
} }
}
# Lint Pass: warn about double-quoted translations
$line = 1;
pos($_) = 0;
while (m/\G(.*?(?<!\{)\{\{(?!\{).*?[:]?\s*?lang\._\(\s*")/sg) {
$line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext!
say STDERR "???: $line: Ignored double-quoted string";
}
}
1; 1;
......
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