Help needed for i18n in forms

0 views
Skip to first unread message

pedromig...@gmail.com

unread,
Feb 9, 2007, 8:22:13 AM2/9/07
to Akelos Framework
Hello!

I'm quite interested in Akelos framework, mainly because its native
multilingual capabilities (I'm from Portugal, btw!). I'm quite new to
the "Rails" way of doing things, but I'm reading the Ruby on Rails
"bible" right now. :)

However, I'm having some trouble displaying fields for various locales
in a single form... what is the recomended way?

Let's say that I have an attribute defined as

title = array('es'=>'...', 'en' => '...')

in the model, corresponding to 'es_title' and 'en_title' columns in
the database.

How can I show two text fields for the title, to be able to edit both
locales in the same form? And how about saving the data back to the
db? Could you provide a simple example?

Thanks for your help,

Pedro

salavert

unread,
Feb 9, 2007, 5:51:09 PM2/9/07
to Akelos Framework
Hi Pedro, i'll try to explain you my way to do this task.
First we need a table called 'people' (by example) with 'es_title' and
'en_title' columns.

Now we define PageController like this:
<?php

class PageController extends ApplicationController
{
var $models = 'page';

function add()
{
if (!empty($this->params['page'])) {
$this->Page->setAttributes($this->params['page']);

if ($this->Request->isPost() && $this->Page->save()){
$this->redirectTo(array('action' => 'show', 'id' => $this-
>Page->getId()));
}
}
}

function show()
{

}

}
?>


And now we have to create two templates at /views/page/ named..

add.tpl
<?

echo $form_tag_helper->start_form_tag(array('action'=>'add'),
array('id'=>'add_page'));

echo $active_record_helper->error_messages_for('page'); //Display
errors
$page_fields = $form_helper->fields_for('page', $Page);
?>
<dl>
<dt>_{English description:}</dt>
<dd><?=$page_fields->text_area('en_title');?></dd>

<dt>_{Spanish description:}</dt>
<dd><?=$page_fields->text_area('es_title');?></dd>
</dl>
<div id="operations">
<input type="submit" value="_{Submit}" />
</div>

<?= $form_tag_helper->end_form_tag() ?>
/**
* If you wish to use the same form template for edit you've to create
a new partial template name _form.tpl and
* call render it using <?= $controller->renderPartial('form') ?>
*
* <form action="add or edit">
* <?= $controller->renderPartial('form') ?> //All form fields
here
* <input type="submit">
* </form>
*/


And now the other partial, show.tpl:
<?= $page->get('title'); ?>
/**
* get('title') will output es_description or en_description value at
database, depending on your current locale.
* You can change your current locale by writing localhost/es or
localhost/en.
* Remember to define them at config/config.php
*/


Now go to localhost/page/add and previus form will appear, when you
submit this form and goes to add() action, $this->params['page'] will
have
$this->params['page']['es_title'] and $this->params['page']
['en_title'] with data filled at form.

Having var $models = 'page' defined at PageController now we've an
object declared into this action called $this->Page,
now we assign params values with $this->Page->setAttributes($this-
>params['page']).
If everything is ok you should be redirected to localhost/page/show/1
and see your locale title

I hope you find this useful.

Salavert.

pedromig...@gmail.com

unread,
Feb 15, 2007, 11:09:25 AM2/15/07
to Akelos Framework
> I hope you find this useful.

I sure did. Thanks for the help! :)

Btw, is anyone thinking about building something like Rails plugin
"act_as_attachment"? It would be quite useful... I will look more into
it when I have some more time.

Best regards,

Pedro

bermi

unread,
Feb 19, 2007, 2:51:41 PM2/19/07
to Akelos Framework
Act as attachment would be a very cool addition to Akelos but it wont
be added until 0.9 unless someone needs to have this functionality and
contributes it to Akelos.

We have a cool PHP File Uploader like Gmail (it's actually a clone)
file uploader. This comes in the form of a prototype.js add-on and a
file_uploader_helper.php, it would be great to integrate it with the
acts_as_attachment in order to give Akelos an elegant solution for
file uploading.

Although not documented yet perhaps Salavert want's to publish a
tutorial for the file uploader too ;)

Good job on this Salavert!!! Keep on contributing!!

Reply all
Reply to author
Forward
0 new messages