mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
lang: properly extract our volt template strings
This commit is contained in:
parent
8b018c4dc4
commit
f7b34e983b
@ -1,12 +1,17 @@
|
||||
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
|
||||
|
||||
|
||||
22
lang/README.md
Normal file
22
lang/README.md
Normal file
@ -0,0 +1,22 @@
|
||||
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.
|
||||
32
lang/Volt.pm
Normal file
32
lang/Volt.pm
Normal file
@ -0,0 +1,32 @@
|
||||
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__
|
||||
Loading…
x
Reference in New Issue
Block a user