Skip to content

Add default translation extractor #56

@mvrhov

Description

@mvrhov

The JMSTransaltorBundle has a nice feature where you can specify default translation for a key.

In twig this is a filter named desc which follows the filter trans. AFAIR this works as following when in debug mode, the translation from filter is shown and when templates get compiled for production this filter gets removed, so there is no additional penalty. You must provide extracted translations if you don't want to look at the key.

e.g.

{{ "text.apples_remaining"|transchoice(count)
       |desc("{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples") }}

For the code part there are 2 annotations @ Ignore, which means that this particular string should not be extracted and another one named @ Desc. This one is placed before ->trans() or inisde ->trans(), or in case of forms one line before the e.g label or the like.

e.g.

->add('title', 'text', array(
    /** @Desc("Title:") */
    'label'              => 'post.form.title',
    'translation_domain' => 'FooBundle',
))

$errors[] = $this->translator
    ->trans(
        /** @Desc("We have changed the permalink because the post '{slug}' already exists.") */
        'post.form.permalink.error.exists', array('{slug}' => $slug), 'FooBundle');

Bonus points :) if it has the same name as the one in JMSTransaltorBundle as this would mean that just the annotation namespace needs to be updated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions