3

CiviStrings is a cli tool that scans an extension for translatable strings and generates a .pot file. According to the readme,

It scans PHP, Smarty, JS, and partial HTML files for references to the ts() function -- and generates a list of strings using gettext's POT file format.

I'd like to know which directories it scans in an extension. I know it will scan files in the /ang directory, but what if I place an html file somewhere else, like /foo/bar.html - will that file also get scanned?

3

The civistrings command doesn't have a prescribed list of directories. It takes a list of paths (files or directories) as an input. For example, here's an excerpt of running it against the api4 extension:

[nix-shell:~/bknix/build/dmaster/sites/all/modules/civicrm/ext/api4]$ civistrings $PWD
#: CRM/Api4/Upgrader/Base.php
msgid "Upgrade %1 to revision %2"
msgstr ""

#: Civi/Api4/Service/Spec/Provider/CustomValueSpecProvider.php tests/phpunit/Action/CustomValueTest.php
msgid "Custom Table Unique ID"
msgstr ""

#: Civi/Api4/Service/Spec/Provider/CustomValueSpecProvider.php tests/phpunit/Action/CustomValueTest.php
msgid "Entity ID"
msgstr ""

#: ang/api4/Explorer.html
msgid "CiviCRM API v4"
msgstr ""

At time of writing, the scanner will look for ts() expressions in any files which match the following:

  • File-name ending with .js (parsed as Javascript code)
  • File-name ending with .html (parsed as HTML with embedded Javascript)
  • File-name ending with .setting.php (parsed as a Civi settings file)
  • File-name ending with .tpl or .hlp (parsed as a Smarty file)
  • File-name ending with .php or file-content starting with a PHP signifier in the first line (parsed as PHP code)

This arrangement allows you to keep-it-simple in the typical case of a single extension (i.e. "just scan the entire extension and put all strings in one file"). This also allows you to deal with more complicated arrangements (e.g. civicrm-core is large and includes several components split among various subfolders). civistrings is focused on the technical mechanics of scanning for ts() -- and tries to be agnostic about the directory-structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.