Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have the following directory structure:

webiste/
    locale/
        en/
             LC_MESSAGES/
                     translation.po
        de/
            LC_MESSAGES/
                     translation.po
        fr/
            LC_MESSAGES/
                     translation.po

I am using the find command to get to all the .po files and apply the msgfmt command to them.

So when I run this command:

find . -name \*.po

The output is

./locale/fr/LC_MESSAGES/translation.po
./locale/de/LC_MESSAGES/translation.po
./locale/en/LC_MESSAGES/translation.po

Just as expected but now I when I add this:

find . -name \*.po -exec msgfmt "{}" \;

It outputs nothing and it does not create the .mo files it is supposed to (If I do it to each file individually the msgfmt command works as expected).

This is weird since if I change the command to this:

find . -name *.po -exec echo "{}" \;

It outputs the names of the files correctly.

I've sort of solved it like this:

find . -name \*.po -exec msgfmt "{}" -o {}.mo \;

But it outputs a translation.po.mo

How can this be done?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

How about -execdir?

This differs from -exec in that it runs the command from the same directory that it finds the files (rather than the current working directory). Given that you're only going to find one translation.po file in your LC_MESSAGES directories, we can lock things right down and not have to fuss around trying to snap the extension off the end of the path.

find . -name \*.po -execdir msgfmt translation.po -o translation.mo \;
share|improve this answer
    
Awesome :) Works like a charm, I'll accept as soon as I can... –  Trufa Apr 10 '13 at 16:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.