Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 2955  / 3 Years ago, sat, july 3, 2021, 10:09:32

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?


More From » bash

 Answers
7

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 ;

[#31816] Saturday, July 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tubequ

Total Points: 11
Total Questions: 113
Total Answers: 115

Location: Equatorial Guinea
Member since Thu, Oct 7, 2021
3 Years ago
;