You can always use the exec
or system
functions.
But if you don't want to do that...
The commands map to some php class and method so you should be able to simulate the code.
For example the i18n:collect-phrases
maps to \Magento\Setup\Console\Command\I18nCollectPhrasesCommand::execute
.
Try to replicate in your code the behavior from that method. Do the same for i18n:pack
. This one maps to Magento\Setup\Console\Command\I18nPackCommand::execute
.
If you want to do it in your own class, try adding this code to your method:
Add this at the top of the file
use Magento\Setup\Module\I18n\ServiceLocator;
then in your method add this:
$directory = 'Add here directory of file to parse. leave empty for all'
$generator = ServiceLocator::getDictionaryGenerator();
$generator->generate(
$directory,
"app/default.csv",
1 //if you specified a certain directory to parse set this to 1.
);
I haven't tested the code, so you might need to debug things.