Skip to end of metadata
Go to start of metadata

 

Introduction

Bracket notation allows you to customize the localized strings in your custom code. This document explains the basic use of of bracket notation in custom applications and interfaces.

Bracket notation basics

Note:

For basic locale system use, read our Guide to Locales - Basic Usage documentation. 

Select a tab to view basic bracket notation usage for that type of code:

$locale->maketext('My text uses [asis,bracket notation].');
[% locale.maketext('My text uses [asis,bracket notation].') %]
LOCALE.maketext("My text uses [asis,bracket notation].");

These examples use the asis method to modify the way in which the locale system handles the text bracket notation.

Because the asis method instructs translators not to translate the specified text, these examples would render the following strings after translation:

LanguageRendered string
EnglishMy text uses bracket notation.
French Mon texte utilise bracket notation.

Arguments

Many bracket notation methods accept ordered arguments. For example, the following localized strings include three arguments with the is_defined method:

$locale->maketext('Error: [is_defined,_1,"_1" is an invalid,Specify a valid] value.', $value);
[% locale.maketext('Error: [is_defined,_1,"_1" is an invalid,Specify a valid] value.', $value) %]
LOCALE.maketext("Error: [is_defined,_1,"_1" is an invalid,Specify a valid] value.", $value);

The is_defined method will use the following arguments:

  • _1 — The first argument instructs the method to check whether the $value variable is defined. 
  • “_1” is an invalid — The second argument provides text that the method will display if the $value variable is defined.

  • Specify a valid — The third argument provides text that the method will display if the $value variable is not defined.

For example, these examples might render the following strings after translation:

LanguageRendered string
English
  • Error: “boop” is an invalid value.
  • Error: Specify a valid value.
French
  • Erreur: "boop" est une valeur non valide.
  • Erreur: Spécifiez une valeur valide.