some of our devs (me included) don't always take it serious to put text in a localization file, result is a lot of hardcoded texts scattered around a lot of views. I'm wondering if any of you has an idea to automate the search for hardcoded texts in views? Has anyone a tool or an approach how to check for this? I was thinking if a nifty bash script would do the job, but I'm a bit lost where to start. Any help much appreciated.
Edit: Not 100% accurate but works best for me so I accepted Andi's answer.
I think you can get very far by just using grep:
cat $(find . | grep .html.erb) | grep -v '[=<>{}$/;]' | grep '\w \w'
This finds texts based on the idea that there are some characters which are not typical for texts
grep -v '[=<>{}$/;]'
and that there should be at least one space with a preceding word character and one where a word character follows
grep '\w \w'
This might not be a hundred percent accurate but is a fast and easy way to quickly check for hard coded text.
You could use a regular expression to find anything neither enclosed within angle brackets (catching most HTML tags and Ruby) nor inside style, script or title tags.
^(?!.*(<(style|script|title).*?<\/\1>|<.*?>)).*$
If you discover that any other tags are getting through, just add them to the list of exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With