Open devnix opened 5 years ago
This is not implemented currently. To do it, we should edit this line: https://github.com/oscarotero/Gettext/blob/master/src/Extractors/Extractor.php#L17 For example, we could provide an option to define the base path used to calculate the relative path of all files, like this:
$translations = Translations::fromPhpCode($file, ['basepath' => __DIR__]);
I don't think to have time to do this, if you want to help with a pull request, I'll happily review it.
I would like to see if I can get some time for this. What would be the best default option? I personally would find the relative path the best option.
For backward compatibility, the default option should be absolute path. Relative path will be generated only if basepath
option is passed.
That's what I was figuring. Let's see if I can make a PR this weekend.
So, we are limited to passing the base path to calculate a relative one, right? There is this neat method from symfony/filesystem but I dont know If you are willing to include another dependency just for this method.
If we are not going to add that component as a dependency, we would be breaking any license if we just copy and paste that method?
This could be a good usage?
$translations->addFromJsCodeFile($file, [
'base_path' => '/var/www/html'
]);
This could be a good usage?
Yes, perfect.
...I dont know If you are willing to include another dependency just for this method.
No, this should be implemented without include any dependency
we would be breaking any license if we just copy and paste that method?
I think we can simplify this method, not only copy and paste as is. Anyway, the license is MIT so I think there's no problem, but I'd include a php comment referencing to the original method.
Any news on this one?
for ppl wanting this, this is the code we have running for a while now
$finder = new Symfony\Component\Finder\Finder();
$finder
->files()
->exclude('vendor')
->ignoreDotFiles(true)
->ignoreUnreadableDirs()
->in('.')
->sortByName()
->name('*.php');
foreach ($finder as $file) {
// dumps the relative path to the file
printf("%s\n", $file->getRelativePathname());
$phpScanner->scanFile((string)$file->getRelativePathname());
}
which gives us relative filenames
I was wondering if there is any possibility of generating a relative path when I'm generating a .pot file when scanning files. Por example, not having lines like
and getting something more like
if the pot file is being generated on /var/www/html/httpdocs/translations (just a fast example)