cedaro / grunt-wp-i18n

Internationalize WordPress themes and plugins with Grunt.
MIT License
160 stars 25 forks source link

Update all text domains in the addtextdomain task #27

Closed bradyvercher closed 9 years ago

bradyvercher commented 10 years ago

Per @GaryJones in #22:

updateDomains: true would replace ALL domains with the right textdomain. This helps when you don't know what all the existing domains are (perhaps PHP functions copied and pasted from multiple sources), but you know they should all be a single one for the project.

This would likely require building a list of all translation functions and the index of their text domain arguments. The list should be readily available since it's typically used in Poedit headers.

Currently the addtextdomain task just does a blind match/replace/insert without being aware of the argument's position in the method definition, so that would need to be updated. Adding this kind of awareness to the tool would likely be valuable upstream as well.

GaryJones commented 10 years ago

This would likely require building a list of all translation functions and the index of their text domain arguments. The list should be readily available since it's typically used in Poedit headers.

Pulled from my grunt-checktextdomain config:

'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d',
'esc_attr__:1,2d',
'esc_html__:1,2d',
'esc_attr_e:1,2d',
'esc_html_e:1,2d',
'esc_attr_x:1,2c,3d',
'esc_html_x:1,2c,3d'

Pulled from my makepot config:

__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;

The use of *d to indicate the position of the domain is not part of the gettext standard - it's something unique to grunt-checktextdomain, but it helps to clarify which number the text domain arg is for each function (the last one).

The *c is the position of the context description argument.

I spent some time in May going through to get this data, and came to the conclusion that most plugins and themes had been doing it wrong, since they had apparently just been blindly copying each other. The author of POEdit, @vslavik, kindly clarified my concerns.

bradyvercher commented 9 years ago

I've run this against several projects and it looks like it's working well. Any issues can be addressed in separate tickets.