From d0c0798f1ef43680ccc322caa84a5bb8d0890d6b Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 2 Aug 2008 23:41:37 +0200 Subject: Sync Locale::Po4a::Text with po4a 0.34. --- perl/Locale/Po4a/Text.pm | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'perl') diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm index eecd333..093b572 100644 --- a/perl/Locale/Po4a/Text.pm +++ b/perl/Locale/Po4a/Text.pm @@ -130,7 +130,16 @@ sub parse { my $wrapped_mode = 1; my $expect_header = 1; ($line,$ref)=$self->shiftline(); + my $file = $ref; + $file =~ s/:[0-9]+$//; while (defined($line)) { + $ref =~ m/^(.*):[0-9]+$/; + if ($1 ne $file) { + $file = $1; + do_paragraph($self,$paragraph,$wrapped_mode); + $paragraph=""; + } + chomp($line); $self->{ref}="$ref"; if ($debianchangelog and -- cgit v1.2.3 From b7cdbb930e3c984fba06e86030e37189e2fe214a Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Aug 2008 11:17:05 +0200 Subject: Fix not stripping final newline of some files Text parser is broken: It assumes it is parsing only a single file. po4a 0.34 partly fixed this by checking at beginning of each iteration of the loop if filename changed - but only then - not at the several places do_paragraph() is done multiple times in same iteration. This patch makes does the opposite: it ensures that all files contain a final newline. This breaks files that has no final newline (but those shouold be rare). --- perl/Locale/Po4a/Text.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'perl') diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm index 093b572..fad995a 100644 --- a/perl/Locale/Po4a/Text.pm +++ b/perl/Locale/Po4a/Text.pm @@ -140,6 +140,7 @@ sub parse { $paragraph=""; } + # TODO: preserve original line ends throughout the code instead chomp($line); $self->{ref}="$ref"; if ($debianchangelog and @@ -162,6 +163,8 @@ sub parse { $line =~ m/^%%?\s*$/) { # Found end of fortune do_paragraph($self,$paragraph,$wrapped_mode); + # FIXME: test if this is still needed when always adding + # newline in do_paragraph() $self->pushline("\n") unless ( $wrapped_mode == 0 or $paragraph eq ""); $paragraph=""; @@ -170,8 +173,6 @@ sub parse { } elsif ($line =~ /^\s*$/) { # Break paragraphs on lines containing only spaces do_paragraph($self,$paragraph,$wrapped_mode); - $self->pushline("\n") unless ( $wrapped_mode == 0 - or $paragraph eq ""); $paragraph=""; $wrapped_mode = 1; $self->pushline($line."\n"); @@ -277,10 +278,16 @@ TEST_BULLET: } # TODO: detect indented paragraphs - $self->pushline( $self->translate($paragraph, + my $transfinal = $self->translate($paragraph, $self->{ref}, "Plain text", - "wrap" => $wrap) ); + "wrap" => $wrap); + + # TODO: preserve original line ends throughout the code instead + chomp $transfinal; + $transfinal .= "\n"; + + $self->pushline( $transfinal ); } 1; -- cgit v1.2.3 From 3aefbdb28ba7d5445d31105a9da971be250057ec Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Aug 2008 17:45:34 +0200 Subject: Fix Locale::Po4a::Text reset flags on new file. --- perl/Locale/Po4a/Text.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perl') diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm index fad995a..f8dd497 100644 --- a/perl/Locale/Po4a/Text.pm +++ b/perl/Locale/Po4a/Text.pm @@ -138,6 +138,8 @@ sub parse { $file = $1; do_paragraph($self,$paragraph,$wrapped_mode); $paragraph=""; + $wrapped_mode = 1; + $expect_header = 1; } # TODO: preserve original line ends throughout the code instead -- cgit v1.2.3 From f5a105a9488fb922ffa59f683f7e15452692246e Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 4 Aug 2008 00:17:44 +0200 Subject: Much improved Markdown support. --- perl/Locale/Po4a/Text.pm | 53 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'perl') diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm index f8dd497..5236095 100644 --- a/perl/Locale/Po4a/Text.pm +++ b/perl/Locale/Po4a/Text.pm @@ -129,6 +129,7 @@ sub parse { my $paragraph=""; my $wrapped_mode = 1; my $expect_header = 1; + my $end_of_paragraph = 0; ($line,$ref)=$self->shiftline(); my $file = $ref; $file =~ s/:[0-9]+$//; @@ -178,37 +179,46 @@ sub parse { $paragraph=""; $wrapped_mode = 1; $self->pushline($line."\n"); - } elsif ( $line =~ /^=*$/ - or $line =~ /^_*$/ - or $line =~ /^-*$/) { + } elsif ( $line =~ /^=+$/ + or $line =~ /^_+$/ + or $line =~ /^-+$/) { $wrapped_mode = 0; $paragraph .= $line."\n"; do_paragraph($self,$paragraph,$wrapped_mode); $paragraph=""; $wrapped_mode = 1; + } elsif ($markdown and + ( $line =~ /^\s*\[\[\!\S+\s*$/ # macro begin + or $line =~ /^\s*"""\s*\]\]\s*$/)) { # """ textblock inside macro end + # Avoid translating Markdown lines containing only markup + do_paragraph($self,$paragraph,$wrapped_mode); + $paragraph=""; + $wrapped_mode = 1; + $self->pushline("$line\n"); } elsif ($markdown and ( $line =~ /^#/ # headline or $line =~ /^\s*\[\[\!\S[^\]]*\]\]\s*$/)) { # sole macro - # Found Markdown markup that should be preserved as a single line + # Preserve some Markdown markup as a single line do_paragraph($self,$paragraph,$wrapped_mode); $paragraph="$line\n"; $wrapped_mode = 0; + $end_of_paragraph = 1; + } elsif ($markdown and + ( $line =~ /^"""/)) { # """ textblock inside macro end + # Markdown markup needing separation _before_ this line do_paragraph($self,$paragraph,$wrapped_mode); + $paragraph="$line\n"; $wrapped_mode = 1; - $paragraph=""; - } elsif ($markdown and - ( $paragraph =~ m/^>/ # blockquote - or $paragraph =~ m/[<>]/ # maybe html - or $paragraph =~ m/^"""/ # textblock inside macro end - or $paragraph =~ m/"""$/)) { # textblock inside macro begin - # Found Markdown markup that might not survive wrapping - $wrapped_mode = 0; - $paragraph .= $line."\n"; } else { if ($line =~ /^\s/) { # A line starting by a space indicates a non-wrap # paragraph $wrapped_mode = 0; + } elsif ($markdown and + ( $line =~ /\S $/ # explicit newline + or $line =~ /"""$/)) { # """ textblock inside macro begin + # Markdown markup needing separation _after_ this line + $end_of_paragraph = 1; } if ($fortunes) { $line =~ s/%%(.*)$//; @@ -221,7 +231,22 @@ sub parse { # (more than 3) # are considered as verbatim paragraphs $wrapped_mode = 0 if ( $paragraph =~ m/^(\*|[0-9]+[.)] )/s - or $paragraph =~ m/[ \t][ \t][ \t]/s); + or $paragraph =~ m/[ \t][ \t][ \t]/s); + if ($markdown) { + # Some Markdown markup can (or might) not survive wrapping + $wrapped_mode = 0 if ( + $paragraph =~ /^>/ms # blockquote + or $paragraph =~ /^( {8}|\t)/ms # monospaced + or $paragraph =~ /[<>]/ms # maybe html + or $paragraph =~ /^\s*\[\[\!\S[^\]]+$/ms # macro begin + ); + } + if ($end_of_paragraph) { + do_paragraph($self,$paragraph,$wrapped_mode); + $paragraph=""; + $wrapped_mode = 1; + $end_of_paragraph = 0; + } ($line,$ref)=$self->shiftline(); } if (length $paragraph) { -- cgit v1.2.3 From 52d3706fd4d7ba3425dac767d75db549fb499dc7 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 4 Aug 2008 02:19:28 +0200 Subject: Extend make and po4a to support templates. --- make/rules.mk | 9 ++++++--- perl/Locale/Po4a/Text.pm | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'perl') diff --git a/make/rules.mk b/make/rules.mk index 973af61..9961061 100644 --- a/make/rules.mk +++ b/make/rules.mk @@ -1,3 +1,6 @@ +# use markdown template for po4a, or some custom one? +HTMLTEMPLATE = text + # 1:source 2:locales define SOURCE_template $(1): $$($(1)_MODULES) $(dummy_MODULES) @@ -48,7 +51,7 @@ export PERL5LIB = $(CURDIR)/perl # 1:moduledir 2:locale 3:mastermodule 4:source define POT_template -fileformat = $(if $(filter templates,$(3)),htmltemplate,text) +fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text) filetype = $(if $(filter templates,$(3)),tmpl,mdwn) ALL_POTFILES += $(podir)/$(3).pot $(3)_L10NFILES = $$(patsubst $(1)/%,%,$$(shell find $(1) -type f -name '*.$$(filetype)' | LANG=C sort)) @@ -65,7 +68,7 @@ $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(eval $(cal # 1:moduledir 2:locale 3:mastermodule 4:source 5:originmodule define INITPO_template -fileformat = $(if $(filter templates,$(3)),htmltemplate,text) +fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text) filetype = $(if $(filter templates,$(3)),tmpl,mdwn) ALL_POFILES += $(podir)/$(3).$(2).po LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES)) @@ -89,7 +92,7 @@ $(foreach source,$(SOURCES),$(foreach module,$(po-init-modules),$(foreach locale # 1:moduledir 2:locale 3:mastermodule 4:source define PO_template -fileformat = $(if $(filter templates,$(3)),htmltemplate,text) +fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text) filetype = $(if $(filter templates,$(3)),tmpl,mdwn) ALL_POFILES += $(podir)/$(3).$(2).po LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES)) diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm index 5236095..0cc2cc8 100644 --- a/perl/Locale/Po4a/Text.pm +++ b/perl/Locale/Po4a/Text.pm @@ -179,6 +179,12 @@ sub parse { $paragraph=""; $wrapped_mode = 1; $self->pushline($line."\n"); + } elsif ($line =~ /^-- $/) { + # Break paragraphs on email signature hint + do_paragraph($self,$paragraph,$wrapped_mode); + $paragraph=""; + $wrapped_mode = 1; + $self->pushline($line."\n"); } elsif ( $line =~ /^=+$/ or $line =~ /^_+$/ or $line =~ /^-+$/) { @@ -237,6 +243,7 @@ sub parse { $wrapped_mode = 0 if ( $paragraph =~ /^>/ms # blockquote or $paragraph =~ /^( {8}|\t)/ms # monospaced + or $paragraph =~ /^\$(\S+[{}]\S*\s*)+/ms # Xapian macro or $paragraph =~ /[<>]/ms # maybe html or $paragraph =~ /^\s*\[\[\!\S[^\]]+$/ms # macro begin ); -- cgit v1.2.3