cedaro / grunt-wp-i18n

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

Add ability to switch textdomains #22

Closed nathanrice closed 10 years ago

nathanrice commented 10 years ago

I ran into this recently where a project was changing names (this can happen for many reasons, but I would imagine the most common is when doing an official fork).

So, I needed to change all the references to 'original-textdomain' to 'new-textdomain'. But as far as I could tell, if a string already has a textomain, it gets ignored, even if the textdomain it has doesn't match the one in package.json.

So, I had to do a manual search and replace to get all the strings switched to the new textdomain.

Is there any way to have this grunt tool do a replacement, either with a new task, or make it the default behavior of addtextdomain?

bradyvercher commented 10 years ago

The addtextdomain tool isn't very sophisticated, so it does have some limitations. As far as I'm aware, it will actually append the text domain if there's already an existing, different text domain, so it may not even work as well as a search/replace in this scenario.

The best bet may be to allow one or more old text domains to be specified as an option that should be updated. Something like:

addtextdomain: {
    options: {
        textdomain: 'newdomain',
        updateDomains: [ 'olddomain1', 'olddomain2' ]
    }
}
remkus commented 10 years ago

As far as I'm aware, it will actually append the text domain if there's already an existing, different text domain

That's what it does, yes.

GaryJones commented 10 years ago

Looks like https://github.com/stephenharris/grunt-checktextdomain has a feature than can correct (not just append) text domains.

bradyvercher commented 10 years ago

Aside from the stuff necessary for passing the parameters from Grunt to PHP, this is really all that was needed to get this working.

Anyone up for testing it out or have any feedback on its usefulness?

GaryJones commented 10 years ago

"grunt-wp-i18n": "git://github.com/blazersix/grunt-wp-i18n.git#develop",

^^^ in the package.json, and then cd into the project directory and run npm install will pull down the develop branch for testing.

Replace with:

"grunt-wp-i18n": "^0.4.6",

when finished.

I think the most obvious usefulness is when creating a new theme out of a starter theme.

The current updating works well. Updating textdomain 'foo' with textdomain 'foo' didn't cause any problems.

Developing it further I'd like to see:

bradyvercher commented 10 years ago

Thanks for the feedback, Gary, as well as the detailed instructions for testing. I should really get that incorporated in some documentation somewhere.

The updateDomains: true option sounds worthwhile, but also sounds like a decent amount of work. I'll open a separate issue for that.

bradyvercher commented 10 years ago

These changes were released in v0.4.7