wireLangReplacements() function

Set global translation replacement values

This option enables you to replace text sent to translation calls like __('text') with your own replacement text. This is similar to the wireTranslateValues() function except that it applies regardless of whether or not a translation is available for the phrase. It overrides rather than serves as a fallback.

This function works whether ProcessWire multi-language support is installed or not, so it can also be useful for selectively replacing phrases in core or modules.

Note that this applies globally to all translations that match, regardless of language. As a result, you would typically surround this in an if() statement to make sure you are in the desired state before you apply the replacements.

The function affects behavior of future __(), _x() and _n() calls, as well as their object-oriented equivalents.

This function should ideally be called from a /site/init.php file (before PW has booted) to ensure that your replacements will be available to any translation calls. However, it can be called from anywhere you’d like, so long as it is before the translation calls that you are looking to replace.

Available since version 3.0.154.

Example

// The following example replaces the labels of all the Tabs in the 
// Page editor (and anywhere else labels used):

wireLangReplacements([
  'Content' => 'Data',
  'Children' => 'Family',
  'Settings' => 'Details',
  'Delete' => 'Trash',
  'View' => 'See',
]);

// If you wanted to be sure the above replacements applied only
// to the Page editor, then you would place it in /site/ready.php
// or /site/templates/admin.php and surround with an if() statement:

if($page->process == 'ProcessPageEdit') {
  wireLangReplacements([
    'Content' => 'Data', // and so on
  ]);
}

// To make the replacement apply only for a specific _x() context, specify the
// translated value in an array with text first and context second, like the
// following example that replaces 'URL' with 'Path' when the context call
// specifed 'relative-url' as context, i.e. _x('URL', 'relative-url');

wireLangReplacements([
  'URL' => [ 'Path', 'relative-url' ],
]);

Usage

$array = wireLangReplacements(array $values);

Arguments

NameType(s)Description
valuesarray

Return value

array string


Functions methods and properties

API reference based on ProcessWire core version 3.0.167

Twitter updates

  • ProcessWire 3.0.168 core updates — More
    26 October 2020
  • This week a 2nd new module for processing Stripe payments has been added to FormBuilder. Unlike our other Stripe Inputfield, this new one supports 3D Secure (SCA) payments. We’ll take a closer look at it in this post, plus a live demo— More
    16 October 2020
  • Quick weekly update covering this week's commits for the upcoming 3.0.167 ProcessWire core version— More
    18 September 2020

Latest news

  • ProcessWire Weekly #337
    In the 337th issue of ProcessWire Weekly we're going to introduce a couple of brand new third party modules, take a closer look at the latest core updates, and more. Read on!
    Weekly.pw / 24 October 2020
  • Stripe Payment Processor for FormBuilder
    This week a second new module for processing Stripe payments has been added to FormBuilder. We’ll take a closer look at it in this blog post, plus we’ve got a demo of it here too.
    Blog / 16 October 2020
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH