String Translation

String Translation lets you override gettext strings emitted by themes and plugins from inside WordPress - no editing .po/.mo files, no rebuilding, no lost changes after updates. PerfLocale scans PHP source for __(), _e(), _x(), _n(), and every other WordPress i18n function, stores what it finds, and serves your translations through the standard gettext filter.

What it handles

  • __(), _e(), esc_html__(), esc_attr__(), esc_html_e(), esc_attr_e() - simple strings
  • _x(), _ex(), esc_html_x(), esc_attr_x() - context-disambiguated strings
  • _n(), _nx(), _n_noop(), _nx_noop() - plural forms

Scanning

The scanner runs from PerfLocale → Strings → Scan for Strings (top-right button). It walks wp-content/, reads every PHP file, and inserts newly-found strings into the perflocale_strings table. Existing strings are preserved; only new ones are added. Files larger than 2 MB are skipped to avoid memory spikes; vendor/, node_modules/, .git/, and test directories are excluded by default (filter perflocale/strings/scanner/excluded_paths).

You can also run the scanner from the command line:

wp perflocale strings scan

Domains and contexts

Every string has a text domain (usually a theme or plugin slug) and an optional context. Filter the Strings page by domain (e.g. only translate woocommerce strings) and combine with context when the same word has different meanings (e.g. Post as a noun vs. a verb).

Translating a string

Click any row on the Strings page. The editor opens with the original on the left and one editable field per active language on the right. Save - the translation takes effect immediately on frontend pages. Machine translation is available via the MT button if you’ve configured a provider.

Storage modes: database vs files

PerfLocale supports two storage backends for string translations, selectable at Settings → Performance:

  • Database (default) - translations live in perflocale_string_translations with a 3-layer cache in front. Simple; every edit is instantly live; portable across hosts via the Export feature.
  • Files - generates .l10n.php translation files (the format WP 6.5+ prefers) in wp-content/uploads/perflocale/translations/. Same speed as a native language pack; zero DB reads for gettext lookups; regenerated automatically when you edit a string.

Import / export

Export your string translations as standard .po or .mo files (or the XLIFF industry format) from Settings → Export & Import. See Export & Import.

← Back to Docs