Problem/Motivation

potx holds its extraction state in 16 global arrays, shared by about 70 global functions in potx.inc and its include files. Every caller resets that state by hand: the tests reset $_potx_store, $_potx_strings and $_potx_install, and l10n_server unsets every $_potx_* global around each release it parses. Schema storage is configured through function names in $_potx_callbacks, reporting through a static mode of potx_status(), and the extract form prints the download and ends with exit.

Proposed resolution

  • A Potx service starts an ExtractionRun, which owns the state of one extraction: strings, diagnostics, config schema and YAML translation patterns. No global state is left behind.
  • One internal extractor service per file type: PHP, JavaScript, Twig, YAML and .info. PHP extraction uses token_get_all(), with a token stream per file and one recognizer class per construct. Twig templates are lexed with potx's own environment, independent of the site's extensions.
  • An ApiVersion enum with Drupal5, Drupal6, Drupal7 and Modern (Drupal 8 and later) selects the recognizers.
  • Config schema and shipped configuration get their own classes; the six schema callbacks become a SchemaStorageInterface that l10n_server can implement.
  • Value objects for strings, occurrences and diagnostics; callers present the diagnostics (Messenger, Drush, arrays).
  • A template builder and writer produce one template. The form returns a streamed download, and services are injected into the form and the Drush command (Drush 13 or later).
  • Removed as outdated: the CVS $Id$ versions (the header should list the paths of the source files only), the multiple and core builds, installer strings as a separate kind, and the fallback t().
  • potx.inc becomes a compatibility layer over the services, deprecated for removal in 3.0.0.

Remaining tasks

Do it. First Remove the outdated output; in testDrupal5() to testDrupal7(), installer strings become ordinary strings. After that generated test templates should be byte-identical at every step.

LLM disclosure

LLM was used to create the high level plan and do implementation for this issue. With human review. Attached full plan.

CommentFileSizeAuthor
Potx3Architecture.pdf5.67 MBgábor hojtsy

Issue fork potx-3630359

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gábor hojtsy created an issue. See original summary.

  • gábor hojtsy committed d92fb16a on 3.x
    task: #3630359 Replace the global state variables and functions of potx...
gábor hojtsy’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

gábor hojtsy’s picture

Version: 2.x-dev » 3.x-dev