ProcessWire
Recipes_

Set language-specific input field labels via API

Problem

You have a multi-language setup and want to set language-specific labels, bypassing admin interface

Solution

If you want to activate all languages, use this after your page-creation API script. In this real-life scenario I had to import product pages, hence the template-selector below.

// Assign API variables to make things a little easier
$fields = wire("fields");
$languages = wire("languages");

// Example languages
$en = $languages->get('en');
$us = $languages->get('us');
$fr = $languages->get('fr');

// Example multi-language field
$field = $fields->get("prod_max_power_consumption");
$field->set("label$en", "Max. Power Consumption");
$field->set("label$us", "Max. Power Consumption");
$field->set("label$fr", "Max. consommation de courant");

$field->save();

Resources