1

I'd like to internationalize the strings of my view.yml, I can't find how to do this.

I have a solution that is bad, in my opinion:

metas:
  title: <?php echo sfContext::getInstance()->getI18n()->__('TITLE'); ?>

I'd like to find a way to do it without calling "sfConfig::getInstance()". Is it possible?

Gregoire
  • 3,735
  • 3
  • 25
  • 37

3 Answers3

2

Never ever use sfContext for I18n in Configuration-Files! In such a case use the setTitle function in the View (not the controller)

<?php $sf_response->setTitle(__('TITLE'));?>
Timo Haberkern
  • 4,409
  • 2
  • 27
  • 41
2

Since include_title() does not translate what it finds in view.yml, I made this very simple function in my custom helper:

function include_translated_title($context)
{
  $title = $context->getI18N()->__($context->getResponse()->getTitle());

  echo content_tag('title', $title)."\n";
}

Then I use it in my layout.php files:

<head>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_translated_title($sf_context) ?>

This way, I can use translation keys in my view.yml

greg0ire
  • 22,714
  • 16
  • 72
  • 101
0

You can do this in your action instead:

$this->getResponse()->setTitle(sfContext::getInstance()->getI18n()->__('TITLE'));

I dont think there's a way around using sfContext. You might be able to do something like this by getting rid of the default <?php include_title() ?> in your layout/view and the using the template i18n format to internationalise it:

<title><?php echo __('TITLE') ?></title>
Tom
  • 30,090
  • 27
  • 90
  • 124