Hi,

I needed to trace how Drupal inserts entries into the DB, into locale_source and locale_target tables.
I noticed not much documentation out there aside from http://api.drupal.org/api/group/locale-api-import/6

I needed to do manual parsing and inserting of PO file into the DB. This should be done outside of Drupal (command line on demand, and through automated scripts as well).
the functions that ultimately do the job are as follows:

...
locale_translate_import_form_submit()
  _locale_import_po() 
    _locale_import_read_po() (this is where insert into DB takes place)
      _locale_import_one_string() (to insert records into the DB)
    _locale_import_one_string (to get a report of what's been done, using static function variables)
...

Now, if I got it right in the description above, as for what happens when one imports a PO file into the DB via Drupal's import interface, then:

  • Guys, the functions naming sucks big time. What's the difference between _locale_import_one_string() and _locale_import_one_string_db()? The function names don't even describe what they're doing - they're just misleading! As far as I can tell, _locale_import_one_string() Both insert recordS into the DB and able to report about the records it handled in previous calls to it. the _one_ from the function name should be abolished and its name should be totally recreated to better describe its actions and purpose.
  • The usage of static function variables to retain the counters across calls to _locale_import_one_string() can lead to corruption - what happens if in the same request, some module or other code decides to run _locale_import_one_string()? that can make data inside the static variables useless.
  • http://api.drupal.org/api/group/locale-api-import/6 should be updated as well. As the only(?) source of documentation outside of the code, its also very inaccurate (as described above...).

Sorry for the tone! - I spent a few hours trying to figure out what's going on here... . As programmers, you must know this can be frustrating... .
Thanks!
Boaz.

Comments

boaz_r’s picture

I got confused on some functions. Correction to the above:

  • _locale_import_read_po() is the function which reads the PO file, parses it, but also inserts its content into the DB, by repeating calls to _locale_import_one_string(). Its documentation doc block says its "Parses Gettext Portable Object file into an array". Not accurate and one wouldn't find any array returned from it or the like. Rather, it also does the task of inserting the PO contents into the DB.
damien tournoud’s picture

Version: 6.8 » 7.x-dev

As in every opensource project, patches are welcome and encouraged. Bumping to the current development version, as the code there is mostly the same.

boaz_r’s picture

You're very much correct and I usually exert effrorts to do so.
Thing is I have to invest relatively big resources to learn the small details and the bigger picture in which the code lives. I hope I could do so some time soon.

Thanks,
Boaz.

plach’s picture

Component: language system » locale.module

Cleaning-up the "language system" issue queue as per http://cyrve.com/criticals.

gábor hojtsy’s picture

Status: Active » Closed (duplicate)

I agree these function names suck. They are also practically impossible to reuse. And their underscore prefix suggests they are "internal" functions. That is not an excuse for sucking. The plan is to fix this in Drupal 8 with #1189184: OOP & PSR-0-ify gettext .po file parsing and generation and #361597: CRUD API for locale source and locale target strings, so closing this down for being a duplicate.