3

How to programmatically determine that a string in a template doesn't translated? I mean a case when a message doesn't enclosed by {% trans %} or trans().

Like here:

<h1>Hello, world</h1> - miss trans tag

Actually, I have really much amount of templates in my applications and I need to know which message and in which template I could missed a trans tag.

  • So you are looking for text that's static? Only in HTML files? – Cody May 31 '17 at 21:33
  • 1
    I think, yes. Files are named something like: index.html.twig, landing.html.twig. And without Twig's interpretation they are simple html code. it's example one of such files: https://pastebin.com/S05SJvzG – Mikhail Shchedrakov Jun 01 '17 at 07:43

1 Answers1

0

You could use a screen scraping/html parser library such as Beautiful Soup. Here's an SO article on how to use it with a local HTML file.

However, unless you're going to be using this quite often (or it's a massive project) I'd imagine it would be less work to just look through the files manually.

I suggested BS since it's Python and it might be closer to PHP for you but there's also JSoup or HTML Agility Pack. I looked around, but don't see any HTML linters that also check for potential localization...

Edit: I also found this Stack Overflow post with suggestions for PHP specifically.

Cody
  • 8,686
  • 18
  • 71
  • 126
  • So, I hoped to find solutions which was written on PHP. But your suggestions looks prospectively. I will try to use these parsers and then I will write about my experience. Thank you. – Mikhail Shchedrakov Jun 01 '17 at 18:59
  • @MikhailSchedrakov I've added a link to an SO post with more options for PHP. – Cody Jun 01 '17 at 19:35