Emergence Documentation

Marking translatable strings

Every string that you want to be able to translate must be wrapped in a call to gettext() or its short alias _(). Any strings without translations available will be passed through unmodified, so it is safe to start wrapping your strings in these functions ahead of getting started on translations.


Within templates, you can use dwoo’s short function syntax for simple strings:

<h1>{_ Localization}</h1>
<p>{_ "Be sure to use single or double quotation marks for strings containing spaces"}</p>

If you want to apply any additional functions or modifiers to translating strings you’ll need to use parenthesis to ensure that they are recognized when you generate your .pot file:

    {_("**Markdown** offers an easy way to use _simple_ formatting within a translatable string")|markdown}

Use the capture function and sprintf together to embed complex or dynamic markup in translatable strings:

{capture assign=person}{personLink $Member} {if $data->Role}({$data->Role|escape}){/if}{/capture}
{capture assign=project}{projectLink $Project}{/capture}

<p>{sprintf(_("%s has been added to %s"), $person, $project)}</p>

PHP Scripts

Strings inside PHP route handlers, PHP classes, and PHP config scripts can be translated with the same functions:

return static::throwError(_('User not found'));

For more complex strigs, use sprintf:

return static::respond('confirm', [
    'question' => sprintf(
        _('Are you sure you want to remove %s from %s?')

Model validation error messages get run through gettext automatically and emergence’s string scanner will recognize lines matching the format 'errorMessage' => '*'

public static $validators = [
    'ProjectID' => [
        'validator' => 'number'
        ,'min' => 1
        ,'errorMessage' => 'Please select a project'
    ,'Headline' => [
        'errorMessage' => 'Please enter a headline for the buzz'

Next steps