On Wed, Jul 20, 2011 at 1:31 AM, Ekki Plicht (DF4OR) <[email protected]> wrote:

> Hi.
>
> The goal is to use TT for an order confirmation, to be sent by email.
>
> The template file itself is written in UTF-8, the variable strings
> (coming from the web) are converted from ISO-8859-1 to utf-8 with
> Locale::Recode. The conversion works fine, Umlauts (diacritical chars)
> like äöü and such are printed correctly.
>

Hum, that does not sound exactly right.  If your templates are UTF-8 then
tell TT about that with ENCODING => 'UTF-8' .   And for your variables use
Encode::decode to decode them as ISO-8869-1.  Process the template then when
sending the mal set the charset to UTF-8 and called Encode::encode_utf8()
when adding to the body.

You want to work with decoded characters inside of Perl and TT, in general.
 I suppose you could do everything in encoded UTF-8 octets, but  then your
character lengths might be off.


>
> The problem:
> I use these strings in formats to get a tabular layout, for example of
> the ordered products. At another place I convert the vars to String
> objects and use var.left(40).
>


And frankly I kind of think the text vs. html argument is a bit out dated,
so I'd just use HTML in the email and let the client format it correctly
into tables.  I suspect that would solve a lot of potential headaches.





> Now, whenever the string contains an Umlaut, the format comes up one
> short in length. If the string contains two Umlauts, it comes up short
> by two characters etc.
>
> Example: (Will only show properly in monospaced fonts)
> POS NUM ARTICLE TEXT567890123456789012345678901234567890 Price
> 010   1 A000001 Item for something                        5.30
> 020   1 B999998 Teil für irgendwas                       5.30
>
> The article text should be 40 chars long, left aligned, right space
> padded, so that the prices at the right line up nicely.
>
> The format for the item line above is
> [% FOREACH a IN o.artikel %]
> [% USE art = format("%0.3d % 3d %- 7s %- 40s %7.2f");
> art( loop.count*10, a.0, a.1, a.2, a.3 )
> +%]
> [% END %]
>
> Tried so far:
> - TT config option 'Encoding' => 'utf8'; no change
> - padding the article text in the Perl script to 40 chars, no change
>
> Environment is an all UTF-8 Locale (de_DE.utf-8), Ubuntu Server 10.04LTS.
> TT is version 2.22.
>
>
> Any ideas?
>
> TIA,
> Ekki
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
>



-- 
Bill Moseley
[email protected]
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to