-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Enhancement] Add an easier way to use i18n view helpers. #2865
Comments
@coolmic for both your problems there are good alternatives. First, usually you have translations for all your locales. It is a good practice to write all message "to-be-translated" as English sentences, but you translate these at all times, nevertheless of the default locale. There is no need to check if the language is English and then omit the translation. Translators also give usually the key back as translation when it does not exist. So if you want to translate 'hello', you have a French translation 'hello' => 'bonjour'. If the locale is English, you see "hello". If the locale is French, you see "bonjour". The second problem: it is in most cases easier to translate the labels directly in the form class itself. Your form looks something like this: <?php
namespace MyModule\Form;
use Zend\Form\Form;
use Zend\I18n\Translate\Translator;
class MyForm extends Form
{
public function __construct(Translator $translator)
{
$this->add(array(
'name' => 'name',
'options' => array(
'label' => $translator->translate('Name:')
),
);
}
} Every label is translated inside the form, so you can make your form view very simple: <dl class="zend_form">
<dt><?php echo $this->formLabel($form->get('name')) ?></dt>
<dd><?php echo $this->formInput($form->get('name')) ?></dd>
<?php echo $this->formElementErrors($form->get('name')) ?>
</dl> If you match two forms you get form two different modules (and thus, two different text domains), you have no trouble in doing so. |
Yeah, the first one is not really an issue, I just want to avoid to instanciate the translator object, but it's probably an unnecessary optimization. For the second one, the translation will be done 2 times, Well, the main purpose of this ticket is to have feedbacks about the TranslatorProxy. |
Is this still an issue? |
I think the issue is reopened accidentally |
Ok, I will close, it can be reopened if it is deemed still an issue. |
I had spoken with dastrid, he reject the proxy, but liked the text domain stack. https://github.com/DASPRiD/zf2/commit/c48c1cfc096a3e9f3323318e5e6c86d2132c8e0c |
@DASPRiD is that a WIP PR you're working on? |
@ralphschindler Yes it is. I'll try to get it ready for 2.2 |
ping @DASPRiD any update for https://github.com/DASPRiD/zf2/commit/c48c1cfc096a3e9f3323318e5e6c86d2132c8e0c ? |
hi, sorry for my bad English.
I have 2 issues.
If I use the translate helper :
and the translator is not set, it will throw an exception.
I am trying to make a reusable modules.
When I make French websites, I need the translator
But if I want to make English websites, I don't need it.
I guess the exception here is unnecessary.
The second issue, is the use of TextDomain.
I use one textDomain per modules, each module embed translation files.
If I want to generate a Form for example, I need to write
And if I use partials, the textdomain may be overwritten by another script.
I come with an idea : Why don't use another helper as Proxy.
On each scripts, we use pushTranslatorTextDomain and popTranslatorTextDomain to ensure there will not have any conflict if we use partial.
What do you think about that? I don't know if it can be PR.
The text was updated successfully, but these errors were encountered: