Support BOM in UTF-8 templates

Remove the BOM, if detected, before processing template files.
Change files to UTF-8+BOM where possible

Now that templates can include a BOM, continue the work started with
commit 2f835881ce24a2b75d8fe4e6b5045d221ab86a6a.