1 (edited by fburbano Yesterday 08:49:58 pm)

Topic: Get Translation Tool

Hi, I don't know if this post should be placed here, but if someone find this useful (PHP PO File extractor) to build a .pot / .po for your custom FrontAccounting module.

1) Put the extractor in your FA tree fa-pot.php at the FrontAccounting root (same folder that has index.php).
Example path when using XAMPP: C:\xampp\htdocs\frontaccounting\fa-pot.php

2) Run it against your custom module
You pass the module folder as the argument and redirect output to a .pot file.

Windows (XAMPP)
Open CMD
cd C:\xampp\htdocs\frontaccounting
C:\xampp\php\php.exe fa-pot.php modules\YourModule > modules\YourModule\lang\new_language_template\LC_MESSAGES\yourmodule.pot  Note:This will create the clean PO file without translations

Linux / macOS
open console
cd /var/www/html/frontaccounting
php fa-pot.php modules/YourModule > modules/YourModule/lang/new_language_template/LC_MESSAGES/yourmodule.pot  Note:This will create the clean PO file without translations

Make sure the lang/new_language_template/LC_MESSAGES folders exists inside your module (create it if not).

3) What the script actually extracts
By default it scans files with extensions:
.php .inc .tpl .phtml .db  and pulls strings from these gettext calls:
_("msg") / gettext("msg")
ngettext("singular","plural", $n)
pgettext("context","msg") / _p("context","msg")
Only literal strings are captured (that’s how gettext tools work).
If you have code like _("Hello ".$name), rewrite it to:
sprintf(_("Hello %s"), $name)
so the constant part is extractable.

4) Customizing (if your code uses other wrappers or file types)
Open fa-pot.php and edit:
Recognized functions (near the top, $KEYS):
'_'        => ['type'=>'simple','args'=>[1]],
'gettext'  => ['type'=>'simple','args'=>[1]],
'ngettext' => ['type'=>'plural','args'=>[1,2]],
'pgettext' => ['type'=>'context','args'=>[1,2]],
'_p'       => ['type'=>'context','args'=>[1,2]],
// add your own, e.g.
// 'N_' => ['type'=>'simple','args'=>[1]],

Scanned extensions ($EXTS):
$EXTS = ['php','inc','tpl','phtml', 'db']; // add 'module' or others if you need

5) Create a locale .po from the .pot
If you have GNU gettext tools, this is easiest:
# Example for Spanish (Spain)
msginit --no-translator \
  --input=modules/YourModule/lang/new_language_template/LC_MESSAGES/yourmodule.pot \
  --locale=es_ES.UTF-8 \
  --output-file=modules/YourModule/lang/new_language_template/LC_MESSAGES/es_ES.po
No gettext tools? Just copy the .pot to .po and edit the header:
# in modules/YourModule/lang/new_language_template/LC_MESSAGES/es_ES.po
"Language: es_ES\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
Common plural forms:
Spanish/English: nplurals=2; plural=(n != 1);
French: nplurals=2; plural=(n > 1);
Portuguese (pt_BR): nplurals=2; plural=(n > 1);
Keep files UTF-8 (no BOM).

6) Where to keep the files in a FA module
A simple, module-local layout works fine:
modules/YourModule/
lang/
    yourmodule.pot
    es_ES.po
    fr_FR.po
FrontAccounting typically uses its own PO loader (not PHP’s gettext() extension), so you don’t need .mo unless your code explicitly uses native gettext. If you do, compile with:
msgfmt -o modules/YourModule/lang/es_ES.mo modules/YourModule/lang/es_ES.po

7) Quick sanity check
Open the generated .pot — you should see blocks like:
#: modules/YourModule/somefile.php:42
msgid "Customer"
msgstr ""
If it’s empty:
Your strings might be dynamic/concatenated.
File extensions not in $EXTS.
Wrapper names not listed in $KEYS.
Wrong path passed to the script.

8) Tiny example
Source:
echo _("Customer");
echo sprintf(_("Open %s invoice"), $ref);
echo ngettext("%d item","%d items", $n);
echo pgettext("button","Save");
Extracted (snippet):
msgid "Customer"
msgstr ""
msgid "Open %s invoice"
msgstr ""
msgid "%d item"
msgid_plural "%d items"
msgstr[0] ""
msgstr[1] ""
msgctxt "button"
msgid "Save"
msgstr ""

9) Typical errors & fixes
Path not found: modules/YourModule
→ Check the path you pass to the script; use quotes if there are spaces.
'php' is not recognized on Windows
→ Use full path to php.exe: C:\xampp\php\php.exe.
Empty POT or missing lines
→ Strings are not literal or wrappers/EXTS not configured.
Encoding/accents look broken
→ Ensure source files and PO are UTF-8 and header has charset=UTF-8.

I would love if someone do this more "user friendly" so an average person can translate the system and modules to any language

Post's attachments

fa-pot.zip 2.6 kb, 1 downloads since 2025-10-02 

You don't have the permssions to download the attachments of this post.