From f7b34e983bc1181ab3f228cf9ebf2ae4ada0e212 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 27 Sep 2015 17:28:17 +0200 Subject: [PATCH] lang: properly extract our volt template strings --- lang/Makefile | 17 +++++++++++++++-- lang/README.md | 22 ++++++++++++++++++++++ lang/Volt.pm | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 lang/README.md create mode 100644 lang/Volt.pm diff --git a/lang/Makefile b/lang/Makefile index 66cd72339..9a6b53ee0 100644 --- a/lang/Makefile +++ b/lang/Makefile @@ -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 diff --git a/lang/README.md b/lang/README.md new file mode 100644 index 000000000..19eb20789 --- /dev/null +++ b/lang/README.md @@ -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. diff --git a/lang/Volt.pm b/lang/Volt.pm new file mode 100644 index 000000000..52b980656 --- /dev/null +++ b/lang/Volt.pm @@ -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(.*?(?add_entry( $str, $line, $vars ); + } +} + + +1; + +__END__