-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Hello
I have the following po file contents, resulting from a scan for php files:
msgid ""
msgstr ""
"X-Domain: messages\n"
#: /var/www/html/the_site/_teste.php:41
msgid "dah"
msgstr ""
I have the following code to scan for files:
/*considering the following folder structure:
vendor
/my_plugins
/module1
/module2
*/
$LOCALES = ["en" => "en_GB","pt" => "pt_PT"];
$folders= new DirectoryIterator("vendor/my_plugins");
foreach($folders as $folder) {
$path = $folder->getFilename();
$DOMAIN = "module1"; //in my actual code, domain takes several different names depending on the folder the iterator is working on
$destination_folder = $folder->getPathname()."/locale/"; //will save in vendor/my_plugins/module1/locale
foreach($LOCALES as $code => $locale) {
if (!file_exists($destination_folder) || !file_exists($destination_folder.$locale)) {
//folder creation
mkdir($destination_folder.$locale,0777,true);
}
}
foreach(LOCALES as $codigo => $locale) {
$phpScanner = new PhpScanner(
Translations::create($DOMAIN)
);
$phpScanner->setDefaultDomain($DOMAIN);
//resulting PO file matches $DOMAIN
$phpScanner->scanFile("some_file.php"); //this also works
//done scanning, let's go to generate files
$FILE = $destination_folder.$locale."/".$DOMAIN.".po";
$po_generator = new PoGenerator();
$mo_generator = new MoGenerator();
foreach ($phpScanner->getTranslations() as $domain => $translations) {
//line below raises: Fatal error: Uncaught Error: Call to undefined method Gettext\Translations::setHeader() in
$translations->setHeader("Content-Type", "text/plain; charset=UTF-8");
//seems to work, but po file does not seem to have the "language" header
$translations->setLanguage($locale); //should be pt_PT or pt_PT.utf8 ( the latter is installed in my system )
$po_generator->generateFile($translations, $FILE);
}
}
What is the proper way to set headers in the file, using PHP-Scanner? Should I load it again with Loader and the set the headers it, and finally generate the mo file?
Metadata
Metadata
Assignees
Labels
No labels