My Users controller sends out an email with a login & password when an
admin enables a member, who can specify a language of choice for
communications. Thus, I'd like to be able to switch the locale,
regardless of whatever the admin is using, just for this email.
Actually, there are several places I'd like to do this, but let's take
the password msg as an example.

The way it works is the MembersController::admin_[add||edit]() will
call Users::add() through a requestAction, passing the params that are
required. In case you're wondering, I need to do it this way because I
have several types of "members", all of which need their own
models/controllers, so roles for one model are out. All of these
"members" require an entry in the users table in order to log in.

I'm using a SwiftMailer component, modified from the one posted at the
bakery to work with the 1.2.x branch. It renders the views pretty much
the same as the built-in EmailComponent:
-- snip --
$old_layout = $this->controller->layout;
$this->controller->layout = '';
ob_start();
echo $this->controller->render(null, null, $view);
$plain_msg = strip_tags(ob_get_clean());
$this->controller->layout = $old_layout;
-- snip --

After studying the L10N & i18n classes, it seems that all i need to do
is the following in the controller:
-- snip --
Configure::write('Config.language', $this->params['language']);
$this->SwiftMailer->applyView($view);
$this->SwiftMailer->send();

/* $this->lang is set in AppController, btw
 */
Configure::write('Config.language', $this->lang);
-- snip --

Contents of the view:
<?= sprintf(__('body_new_member_welcome', true), $email, $password) ?>

To make a long story short, this ain't working for me. I also tried
setting $language & $old_language in the controller and wrapping the
sprintf() with:

Configure::write('Config.language', $language);
...
Configure::write('Config.language', $old_language);

I knew it wouldn't work, but hey.

I also tried this in the users controller:

function beforeFilter()
{
        parent::beforeFilter();
        
        if ($this->params['action'] == 'add')
        {
                Configure::write('Config.language', $this->params['language']);
        }
}

function afterFilter()
{
        if ($this->params['action'] == 'add')
        {
                Configure::write('Config.language', $this->lang);
        }

        /* OT QUESTION: should I put the following before, or after, my own 
logic?
         */
        parent::afterFilter();
}

which I figured would *have* to work, but no dice. Old-timers will be
happy to know that I tried this after asking in this mail if it would
work and then realising that I could damn well just go try it for
myself

So, does anyone have any insight into this? This is one of the last
hurdles to getting this site completely multilingual. I guess the next
thing I could try is passing the language to the SwiftMailer
component, though I'm doubtful that would make any difference,
considering what hasn't worked so far. Also, I'd prefer to keep that
component language-agnostic, as all it needs to know is which view(s)
to use.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to