Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically find I18N Violations

Is there anyway to automatically find I18N violations in a Grails project? For example,

<td valign="top" class="name"><label for="enabled">Enabled:</label></td>

should be flagged because it's not using <g:message> to get the label value.

It would be nice if codenarc had a rule for this, but I don't think it does.

like image 252
Brad Rhoads Avatar asked Apr 20 '11 17:04

Brad Rhoads


1 Answers

I have also looked for such a code quality test and have yet to find one.

Implementing this should be fairly trivial - if all text content in a GSP is required to be applied via tags, your GSP should consist entirely of element nodes and no text nodes.

This crux of the problem is predominantly an XML issue: how do you check a set of XML documents and flag those that contain text nodes?

Assuming you can import org.codehaus.groovy.grails.commons.GrailsResourceUtils in a codenarc rule you can use the VIEWS_DIR_PATH property to determine where all the GSP files live.

From there, the high level process you would need is:

  1. Build a collection of all the GSP files in the application
  2. For each file, load the content into an XML parser (Java has plenty) and check the node type for every node, flagging those files that contain text nodes

I appreciate that this is a very high level solution but conceptually it should work.

like image 129
Jon Cram Avatar answered Oct 15 '22 22:10

Jon Cram