cedaro / grunt-wp-i18n

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

Send modified files to build path only #71

Closed nickyoung87 closed 6 years ago

nickyoung87 commented 6 years ago

Is there not a way to avoid overwriting the main files?

I have a Lite/Pro plugin setup where the Lite "core" files are contained within the Pro plugin. There is some other grunt magic that syncs any of my core files to the Pro plugin automatically. This is an issue we are trying to resolve because it also sends over the incorrect text-domain since they use different text-domains.

My thought was to simplify this by removing the text-domain from both plugins and just having it added to the final build. So it would just look like __( 'Some string' ) and then in the build file it would get translated to __( 'Some string', 'some-domain' ).

I have tried a couple things but the most recent was setting the src path and the dest differently, but it still seems to not work how I would want it to. Example:

addtextdomain: {
            options: {
                textdomain: 'my-domain',    // Project text domain.
                updateDomains: []  // List of text domains to replace.
            },
            target: {
                files: [
                    { src: 'includes/**/*.php', dest: 'build/includes/**/*.php' },
                ]
            }
        },

This still overwrites the files in the main folder and doesn't just add them as "converted" into my build folder.

So I guess my question is if this is even possible at all with this module or if I need to figure out another way around it? And if it's not possible, is it something that might be added in the future? I really love this module and would love to use it on all of my projects if this is possible.

bradyvercher commented 6 years ago

Hi @nickyoung87, the addtextdomain task updates files in place, so it does overwrite them. Instead of running it against the source, you should update the file paths to run it against your build directory after you've copied all the files over to it:

addtextdomain: {
    options: {
        textdomain: 'my-domain',    // Project text domain.
        updateDomains: []  // List of text domains to replace.
    },
    target: {
        files: [
            { src: 'build/includes/**/*.php' }
        ]
    }
}
nickyoung87 commented 6 years ago

@bradyvercher Wow, such a simple solution. I can't believe I didn't think of that. I will give that a shot.

Thanks so much for the input!

EDIT: Tested it and it worked perfectly.