<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog Symfony2 - Lexik Montpellier &#187; I18N</title>
	<atom:link href="http://www.lexik.fr/blog/symfony/tag/i18n/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lexik.fr/blog/symfony</link>
	<description>Blog sur le développement Web PHP avec Symfony 2</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:00:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>LexikTranslationBundle, pour éditer vos traductions avec Symfony2</title>
		<link>http://www.lexik.fr/blog/symfony/symfony2/lexiktranslationbundle-pour-editer-vos-traductions-avec-symfony2-1753</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony2/lexiktranslationbundle-pour-editer-vos-traductions-avec-symfony2-1753#comments</comments>
		<pubDate>Fri, 28 Oct 2011 08:23:09 +0000</pubDate>
		<dc:creator>cedric</dc:creator>
				<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1753</guid>
		<description><![CDATA[Bonjour à tous, voici le premier bundle Symfony2 made in Lexik, j&#8217;ai nommé LexikTranslationBundle. Le but de ce bundle est simple, pouvoir gérer le contenu des fichiers de traduction (xliff, yml, php) via la base de données afin de faciliter &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony2/lexiktranslationbundle-pour-editer-vos-traductions-avec-symfony2-1753">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Bonjour à tous, voici le premier bundle Symfony2 made in Lexik, j&#8217;ai nommé <a title="github LexikTranslationBundle" href="https://github.com/lexik/LexikTranslationBundle">LexikTranslationBundle</a>. Le but de ce bundle est simple, pouvoir gérer le contenu des fichiers de traduction (xliff, yml, php) via la base de données afin de faciliter l&#8217;édition les traductions sans avoir à mettre le nez dans le code source du projet.<span id="more-1753"></span></p>
<h2>Pourquoi utiliser la base de données ?</h2>
<p>En effet, pourquoi utiliser la base de données au lieu d&#8217;éditer directement les fichiers de traduction ? Lorsque votre site sera en production des modifications pourront être faites grâce à l&#8217;interface d&#8217;édition, cependant les développeurs seront potentiellement amenés à ajouter de nouvelles traductions dans les fichiers. Donc si on édite directement les fichiers de traduction un problème risque de se présenter: lors des mises en ligne, comment ajouter les nouvelles traductions sans perdre les modifications faites depuis l&#8217;interface d&#8217;édition ? (sans compter le fait que Apache devra avoir les droits en écriture sur les fichiers).<br />
C&#8217;est pour cela que nous avons choisi de charger les traductions en base de données. De cette façon l&#8217;administrateur du site peut modifier les traductions à son gré et les développeurs peuvent à tout moment ajouter de nouvelles entées dans les fichiers. </p>
<h2>Fonctionnement</h2>
<p>Le bundle redéfinit le service de traduction de Symfony (translator) et fournit un loader pour charger les traductions depuis la base de données.<br />
Les traductions présentes en base de données sont chargées en dernier, elles prennent donc le dessus sur les traductions des fichiers xliff, yml ou php. Le bundle fournit aussi une interface d&#8217;édition et d&#8217;ajout de traductions avec une intégration de <a title="jqGrid" href="http://www.trirand.com/blog/" target="_blank">jqGrid 4.2.0</a>.<br />
L&#8217;ajout de traduction dans la base de données se fait soit par l&#8217;interface, soit en ligne de commande avec une tâche qui va importer vos fichiers de traduction dans la base de données.</p>
<h2>Utilisation</h2>
<p>Lors de votre développement créez vos fichiers de traductions au moins pour une langue (la langue par défaut du site par exemple). Ensuite lancez la tâche d&#8217;import pour ajouter les nouvelles traductions en base de données. Une fois importées les traductions sont éditables dans l&#8217;interface, vous pouvez donc modifier les traductions pour toutes les langues gérées par le bundle.<br />
Une traduction n&#8217;est éditable que si elle est présente dans la base de données, donc si vous ajoutez de nouvelles entées dans vos fichiers de traduction il faudra relancer la tache d&#8217;import.</p>
<p><em>Note: lors de la modification d&#8217;une traduction via l&#8217;interface il sera nécessaire de cliquer sur le bouton &laquo;&nbsp;invalidate cache&nbsp;&raquo; afin de prendre en compte le changement de la traduction (surtout en environnement de production).</em></p>
<h2>Installation et configuration</h2>
<p>L&#8217;installation se fait comme pour tous les autres bundle Symfony2 à l&#8217;aide des fichiers <code>deps</code> et <code>deps.lock</code>.<br />
Au niveau de la configuration il vous faudra au minimum définir la langue par défaut (fallback_locale) et les langues que le bundle doit gérer (managed_locales), comme ci-dessous :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1753code2'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17532"><td class="code" id="p1753code2"><pre class="yml" style="font-family:monospace;"># app/config/config.yml
lexik_translation:
    fallback_locale:  fr
    managed_locales:  [fr, en]</pre></td></tr></table></div>

<p>Il est aussi possible de configurer certaines classes utilisées par le bundle dans le cas où vous souhaitez redéfinir des éléments (entité et/ou service).</p>
<p>Pour plus de détail sur cette partie je vous invite à lire <a title="Doc LexikTranslationBundle" href="https://github.com/lexik/LexikTranslationBundle/blob/master/Resources/doc/index.md">la doc sur le dépot Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony2/lexiktranslationbundle-pour-editer-vos-traductions-avec-symfony2-1753/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formulaires i18n et ajout de langues automatisé</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/formulaires-i18n-et-ajout-de-langues-automatise-691</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/formulaires-i18n-et-ajout-de-langues-automatise-691#comments</comments>
		<pubDate>Fri, 12 Jun 2009 14:39:51 +0000</pubDate>
		<dc:creator>Nikaw</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[automatisation]]></category>
		<category><![CDATA[embedForm]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[I18N]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=691</guid>
		<description><![CDATA[Ce post à pour but de faciliter les embedI18n pour les formulaires ayant des champs en i18n. Il s&#8217;agit normalement de ceci dans votre formulaire principal (donc objectForm.class.php, et non objectTranslationForm.class.php) : ?View Code PHP$this-&#62;embedI18n&#40;array&#40;'en', 'fr',...&#41;&#41;; $this-&#62;widgetSchema-&#62;setLabel&#40;'en', 'Anglais'&#41;; $this-&#62;widgetSchema-&#62;setLabel&#40;'fr', 'Français'&#41;; &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/formulaires-i18n-et-ajout-de-langues-automatise-691">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Ce post à pour but de faciliter les embedI18n pour les formulaires ayant des champs en i18n.<br />
<span id="more-691"></span><br />
Il s&#8217;agit normalement de ceci dans votre formulaire principal (donc objectForm.class.php, et non objectTranslationForm.class.php) :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69110"><td class="code" id="p691code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">embedI18n</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'en'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,...</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'en'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Anglais'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Français'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #339933;">...</span>
<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Il y aura donc autant de lignes que de langues à ajouter.</p>
<p>Imaginons maintenant la situation suivante :</p>
<p>Je suis développeur web, et je réalise un site international pour un client Mr Gui, il me donne la liste des langues, je code tous mes formulaires, et le lendemain, Mr Gui m&#8217;appelle, et me dit qu&#8217;il est désolé, il a oublié 3 langues, seulement voilà, j&#8217;ai 27 formulaires dans mon appli&#8230; (et oui il s&#8217;agit d&#8217;un énorme site, Mr Gui est un très gros client&#8230;). Je reprend donc mes 27 formulaires, et je rajoute mes embedForm et mes setLabel.<br />
Mais, le lendemain, Mr Gui me rappelle pour me dire que finalement, le finlandais c&#8217;est pas la peine de le mettre, je dois donc r&#8217;ouvrir mes 27 formulaires et supprimer dans chacun le finlandais dans le embedI18n et dans le setLabel.</p>
<p>En résumé, même si une situation pareil est exagérée, il serait quand même pratique de centraliser les cultures, et d&#8217;automatiser les embedI18n et setLabel.</p>
<p>Voilà donc la solution que je propose aujourd&#8217;hui, en 2 étapes :</p>
<p><strong>Etape 1 : centraliser les cultures</strong></p>
<p>On sait déjà que Symfony permet l&#8217;utilisation dans les apps des fichier de configuration app.yml pour tout ce qui est options du site, et paramètres globaux. Nous allons donc utiliser ce principe pour définir toutes les langues.<br />
Sachant que ces langues ne sont pas forcément propres à une application en particulier (frontend, backend, etc.) il convient de placer le fichier des langues dans un dossier plus haut placé. Créons donc un dossier config dans le dossier apps, et plaçons y un fichier app.yml (il pourra éventuellement contenir d&#8217;autres infos que les langues, on ne l&#8217;appellera donc pas languages.yml ou cultures.yml, &#8230;)</p>
<p><em>/apps/config/app.yml :</em></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code11'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69111"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p691code11"><pre class="yaml" style="font-family:monospace;">all:
  cultures:
    enabled:
      fr: Français
      en: English
      es: Español</pre></td></tr></table></div>

<p>Facile pour l&#8217;instant non ?<br />
La syntaxe globale est en fait la suivante :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code12'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69112"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p691code12"><pre class="yaml" style="font-family:monospace;">environnement:
  cultures:
    enabled:
      clé: label</pre></td></tr></table></div>

<p><strong>Etape 2 : automatisation dans les formulaires</strong></p>
<p>Maintenant que les langues sont centralisées, reste plus qu&#8217;à automatiser les formulaires, la méthode est la suivante:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69113"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p691code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> sfYaml<span style="color: #339933;">::</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_apps_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../config/app.yml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* 1 */</span>
  <span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cultures'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'enabled'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* 2 */</span>
  <span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_keys"><span style="color: #990000;">array_keys</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$languages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* 3 */</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">embedI18n</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* 4 */</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/* 5 */</span>
  <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$languages</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  parent<span style="color: #339933;">::</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Explications :<br />
1 : le sfConfig::get() n&#8217;est pas joignable depuis les formulaires, et puis de toutes façons, le fichier n&#8217;est pas placé dans une app, il faut donc le charger autrement.<br />
Le framework Symfony dispose d&#8217;un Yaml Loader qui le permet.</p>
<p>2 : les fichiers *.yml sont chargé par le loader Symfony comme des tableaux, construits de la manière suivante :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code14'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69114"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p691code14"><pre class="yaml" style="font-family:monospace;">tableau:
  clé1: valeur
  sous-tableau:
    sous-clé1: valeur
    sous-tableau2 : { sous-sous-clé1: valeur, sous-sous-clé2: valeur }</pre></td></tr></table></div>

<p>Tout ceci sera chargé comme suit par le loader :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69115"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p691code15"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'tableau'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'clé1'</span> <span style="color: #339933;">=&gt;</span> valeur<span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'sous-tableau'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'sous-clé1'</span> <span style="color: #339933;">=&gt;</span> valeur<span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'sous-sous-tableau'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'sous-sous-clé1'</span> <span style="color: #339933;">=&gt;</span> valeur<span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'sous-sous-clé2'</span> <span style="color: #339933;">=&gt;</span> valeur
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>La lige marquée /* 2 */ permet donc de stocker dans la variable $languages un tableau de la forme :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69116"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p691code16"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'fr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Français'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'en'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'English'</span><span style="color: #339933;">,</span>
  <span style="color: #339933;">...,</span>
  <span style="color: #339933;">...</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>3 : cette ligne permet des ranger les clés du tableaux languages (donc &#8216;fr&#8217;, &#8216;en&#8217;, etc.) dans un tableaux où elles seront valeurs, et non clés.<br />
4 : cette ligne embed donc toutes les langues présentes dans le yml<br />
5 : le foreach permet donc de set tous les labels, en correspondance avec les langues.</p>
<p>Et voilà !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/formulaires-i18n-et-ajout-de-langues-automatise-691/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Symfony &amp; jQuery DatePicker</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491#comments</comments>
		<pubDate>Tue, 14 Apr 2009 07:34:36 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[datePicker]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=491</guid>
		<description><![CDATA[Je vais vous montrer dans cet article comment mettre en place rapidement un datePicker jQuery dans un formulaire Symfony 1.2 Pré-requis Plugin sfFormExtraPlugin installé : sfFormExtraPlugin Fichiers externes Télécharger jQuery UI (jquery-1.3.2.min.js, jquery-ui-1.7.1.custom.min.js) Vous pouvez télécharger une version &#171;&#160;customizée&#160;&#187; de &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Je vais vous montrer dans cet article comment mettre en place rapidement un datePicker jQuery dans un formulaire Symfony 1.2</p>
<h2>Pré-requis</h2>
<ul>
<li>Plugin sfFormExtraPlugin installé : <a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin">sfFormExtraPlugin</a>
</li>
</ul>
<p><span id="more-491"></span></p>
<h2>Fichiers externes</h2>
<ul>
<li>
<b>Télécharger jQuery UI </b><br />
<em>(jquery-1.3.2.min.js, jquery-ui-1.7.1.custom.min.js)</em></p>
<p>Vous pouvez télécharger une version &laquo;&nbsp;customizée&nbsp;&raquo; de jQuery UI ici :<br />
<a href="http://jqueryui.com/download">Télécharger JQuery UI</a>
</p>
</li>
<li>
<b>Version française</b><br />
<em>(uidatepicker-fr.js)</em></p>
<p>Vous trouverez le patch français de ce plugin ici :</p>
<p><a href="http://www.remy-solnais.com/jquery-et-datepicker/">Datepicker jQuery en français</a>
</li>
<li><b>Intégration dans Symfony</b>
<ol>
<li><b>JS</b><br />
  Copiez les fichiers :<br />
  <b>[jquery UI]/js/jquery-1.3.2.min.js </b><br />
  <b>[jquery UI]/js/jquery-ui-1.7.1.custom.min.js </b><br />
  <b>uidatepicker-fr.js</b><br />
  directement dans <b>[votre_projet]/web/js</b>
  </li>
<li><b>CSS</b>
<ul>
<li>Copiez le fichier :<br />
<b>[jquery UI]/css/jquery-ui-1.7.1.custom.css</b> dans :<br />
<b>[votre_projet]/web/css.</b>
</li>
<li><span style="color: red;">!! Attention !! </span>:<br />
J&#8217;ai dû remplacer toutes les occurrences de :<br />
<b>url(images/</b> par :<br />
<b>url(../images/</b>
</li>
</ul>
</li>
<li><b>Images</b><br />
N&#8217;oubliez pas de copier le contenu de :<br />
<b>[jquery UI]/css/smoothness/images</b> dans :<br />
<b>[votre_projet]/web/images</b>
</li>
</ol>
</li>
</ul>
<h2>View.yml</h2>
<p>N&#8217;oubliez pas de faire référence aux fichiers externes dans le view :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code25'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49125"><td class="code" id="p491code25"><pre class="yml" style="font-family:monospace;">default:
  http_metas:
    content-type: text/html
&nbsp;
  metas:
    #title:        symfony project
    #description:  symfony project
    #keywords:     symfony, project
    #language:     en
    #robots:       index, follow
&nbsp;
  stylesheets:    [main.css, jquery-ui-1.7.1.custom.css]
&nbsp;
  javascripts:    [jquery-1.3.2.min.js, uidatepicker-fr.js, jquery-ui-1.7.1.custom.min.js]
&nbsp;
  has_layout:     on
  layout:         layout</pre></td></tr></table></div>

<h2>sfWidgetFormJQueryI18nDate.class.php</h2>
<p>J&#8217;ai modifié la classe sfWidgetFormJQueryDate pour qu&#8217;elle soit compatible avec un format de date français.<br />
De plus, on peut facilement configurer les options  du widget jQuery.</p>
<ul>
<li><b>Code source :</b><br />
<u>Fichier :</u> sfWidgetFormJQueryI18nDate.class.php<br />
<u>Chemin :</u> /plugins/sfFormExtraPlugin/lib/widget/</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49126"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
</pre></td><td class="code" id="p491code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier &lt;fabien.potencier@symfony-project.com&gt;
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * sfWidgetFormJQueryDate represents a date widget rendered by JQuery UI.
 *
 * This widget needs JQuery and JQuery UI to work.
 *
 * @package    symfony
 * @subpackage widget
 * @author     Fabien Potencier &lt;fabien.potencier@symfony-project.com&gt;
 * @version    SVN: $Id: sfWidgetFormJQueryDate.class.php 12875 2008-11-10 12:22:33Z fabien $
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormJQueryI18nDate <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormI18nDate
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * Configures the current widget.
   *
   * Available options:
   *
   *  * image:   The image path to represent the widget (false by default)
   *  * config:  A JavaScript array that configures the JQuery date widget
   *  * culture: The user culture
   *
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetForm
   */</span>	
&nbsp;
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;culture&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    parent<span style="color: #339933;">::</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'en'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * @param  string $name        The element name
   * @param  string $value       The date displayed in this widget
   * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
   * @param  array  $errors      An array of errors for the field
   *
   * @return string An HTML tag string
   *
   * @see sfWidgetForm
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', buttonImage: %s, buttonImageOnly: true'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderTag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'input'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_jquery_control'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disabled'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;
  function %s_read_linked()
  {
    \$(&quot;#%s&quot;).val(\$(&quot;#%s&quot;).val() + &quot;/&quot; + \$(&quot;#%s&quot;).val() + &quot;/&quot; + \$(&quot;#%s&quot;).val());
&nbsp;
    return {};
  }
&nbsp;
  function %s_update_linked(date)
  {
    \$(&quot;#%s&quot;).val(date.substring(0, 2));
    \$(&quot;#%s&quot;).val(parseInt(date.substring(3, 5), 10));
    \$(&quot;#%s&quot;).val(date.substring(6, 10));
  }
&nbsp;
  \$(&quot;#%s&quot;).datepicker(\$.extend({}, {
    minDate:    new Date(%s, 1 - 1, 1),
    maxDate:    new Date(%s, 12 - 1, 31),
    onSelect:   %s_update_linked,
    beforeShow: %s_read_linked,    
    %s    
    showOn:     &quot;both&quot;
    %s
  }, \$.datepicker.regional[&quot;%s&quot;]));
&nbsp;
&lt;/script&gt;
EOF</span>
      <span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[day]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[month]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[year]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[day]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[month]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[year]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$id</span><span style="color: #339933;">,</span>
      <a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/max"><span style="color: #990000;">max</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li><b>Explication des modifications :</b>
<ol>
<li>
<b>Ligne 20 :</b><br />
Notre widget dérive désormais de sfWidgetForm<b>I18n</b>Date</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49127"><td class="line_numbers"><pre>20
</pre></td><td class="code" id="p491code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormJQueryDate <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormI18nDate</pre></td></tr></table></div>

</li>
<li><b>Lignes 40, 41 et 42:</b><br />
On ajoute les options &laquo;&nbsp;config&nbsp;&raquo;, &laquo;&nbsp;culture&nbsp;&raquo; et &laquo;&nbsp;years&nbsp;&raquo; avec le paramètre &laquo;&nbsp;options&nbsp;&raquo; de la fonction &laquo;&nbsp;configure&nbsp;&raquo; :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49128"><td class="line_numbers"><pre>40
41
42
</pre></td><td class="code" id="p491code28"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;culture&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li><b>Lignes 85 et 86</b>
<ul>
<li>Il faut inverser l&#8217;ordre du jour et du mois pour être compatible avec un format français, ce qui revient dans un <a href="http://fr.php.net/sprintf">sprintf</a>, à changer l&#8217;ordre des lignes dans le code.
</li>
<li>Il faut faire un <a href="http://www.w3schools.com/jsref/jsref_parseInt.asp">parseInt</a> sur le mois pour transformer &laquo;&nbsp;01&#8243; en &laquo;&nbsp;1&#8243;, parseInt est la fonction javascript permettant de caster une chaîne de caractères en Integer :<br />
Premier paramètre : la chaîne à caster (ici : date.substring(3, 5) )<br />
Deuxième paramètre : Le système numérique à utiliser (ici décimal : 10)
</li>
</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code29'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49129"><td class="line_numbers"><pre>85
86
</pre></td><td class="code" id="p491code29"><pre class="php" style="font-family:monospace;">    \$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    \$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li><b>Lignes 95 et 109</b>
<ul>
<li>On passe les options directement dans le premier argument.<br />
Le <b>%s</b> de la ligne 95 correspond au  <b>$this->getOption(&#8216;config&#8217;)</b> de la  ligne 109<br />
Le <b>%s</b> de la ligne 98 correspond au  <b>$this->getOption(&#8216;culture&#8217;)</b> de la  ligne 109
</li>
<li>Ligne 109 : passage des options et da la culture au widget.
</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49130"><td class="line_numbers"><pre>108
</pre></td><td class="code" id="p491code30"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
</ol>
<h2>Exemple d&#8217;utilisation</h2>
<ul>
<li><b>Schéma</b>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code31'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49131"><td class="code" id="p491code31"><pre class="yml" style="font-family:monospace;">person:
  columns:
    [...]
    birthday:
      type: timestamp
    [...]</pre></td></tr></table></div>

</li>
<li><b>Formulaire (Instanciation du widget)</b>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p491code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49132"><td class="code" id="p491code32"><pre class="php" style="font-family:monospace;">  <span style="color: #009900;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1900</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">2010</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$years</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'birthday'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormJQueryI18nDate<span style="color: #009900;">&#40;</span>
      <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yearRange: \'1900:2009\', 
                           changeYear: true, 
                           changeMonth: true,'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'culture'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'years'</span><span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array_combine"><span style="color: #990000;">array_combine</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #339933;">,</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

</li>
<li><b>Aperçu</b><br />
<img src="http://img152.imageshack.us/img152/8430/jquerydatepickerfr.jpg" title="jquery datepicker fr" alt="jquery datepicker fr" width="450">
</li>
</ul>
<hr />
<h2>Sources</h2>
<ul>
<li>
<em><a href="http://www.symfony-project.org/forms/1_2/en/08-Internationalisation-and-Localisation">Symfony Internationalisation and Localisation</a></em>
</li>
<li>
<em><a href="http://www.symfony-project.org/forms/1_2/en/A-Widgets">Symfony Widgets</a></em>
</li>
<li>
<em><a href="http://jqueryui.com/">jQuery UI</a></em>
</li>
<li>
<em><a href="http://www.remy-solnais.com/jquery-et-datepicker/">Remy Solnais jquery et datepicker en Français</a></em>
</li>
<li>
<em><a href="http://www.w3schools.com/jsref/jsref_parseInt.asp">W3schools parseInt en Javascript</a></em>
</li>
<li>
<em><a href="http://fr.php.net/sprintf">PHP.net fonction sprintf</a></em>
</li>
<li>
<em><a href="http://imageshack.us/">ImageShack</a></em>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Internationalisation et formulaire avec Symfony</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/12x/internationalisation-et-formulaire-399</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/12x/internationalisation-et-formulaire-399#comments</comments>
		<pubDate>Wed, 18 Mar 2009 18:18:44 +0000</pubDate>
		<dc:creator>yoye</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=399</guid>
		<description><![CDATA[Aujourd&#8217;hui on va traiter des formulaires et de l&#8217;internationalisation. Une des grandes fiert&#233; de Symfony 1.2 est l&#8217;internationalisation et les formulaires.&#160; Vous avez&#160; eu droit &#224; leur chapitre dans les jobeet. En revanche lorsque l&#8217;on veut&#160; coupler les deux, les &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/12x/internationalisation-et-formulaire-399">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui on va traiter des formulaires et de l&#8217;internationalisation.  Une des grandes fiert&eacute; de Symfony 1.2 est l&#8217;internationalisation et les formulaires.&nbsp; Vous avez&nbsp; eu droit &agrave; leur chapitre dans les jobeet. En revanche lorsque l&#8217;on veut&nbsp; coupler les deux, les choses se compliquent un peu et c&#8217;est bien l&agrave; l&#8217;int&eacute;r&ecirc;t de notre m&eacute;tier.  Le but de cet article n&#8217;&eacute;tant pas d&#8217;expliquer une nouvelle fois le fonctionnement des formulaires ou de l&#8217;I18N, vous comprendrez que je survole certains points. Je vous renverrez simplement <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/10">ici pour les formulaires</a> et <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/19">ici pour l&#8217;I18N</a> .</p>
<p><span id="more-399"></span></p>
<p>Le but est d&#8217;obtenir un site (un bout de site) qui nous permette de faire un listing de recettes et cela dans diff&eacute;rentes langues, on va se contenter du fran&ccedil;ais et de l&#8217;anglais.  Il faut d&#8217;abord commencer par le sch&eacute;ma :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p399code38'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39938"><td class="code" id="p399code38"><pre class="yml" style="font-family:monospace;"> Recipe:
  actAs:
    I18n:
      fields: [name, body, is_activated]
    actAs:
      Sluggable: { fields: [name], uniqueBy: [lang, name] }
  columns:
    name: { type: string(255)}
    body: { type: clob}
    is_activated: { type:boolean, notnull: true, default: 0}</pre></td></tr></table></div>

<p>Le schema est tr&egrave;s simple il n&#8217;y aucune relation avec d&#8217;autres tables, ce qui nous int&eacute;ressent ici c&#8217;est le traitement I18N et les formulaires.  <strong>Petite remarque :</strong>  &#8211; Je passe le is_activated, qui indique si la recette est active ou non, dans le actAs I18N ainsi les recettes par langue seront totalement ind&eacute;pendantes.  &#8211; Le sluggable est pass&eacute; &eacute;galement en deuxi&egrave;me niveau d&#8217;actAs pour permettre &agrave; chaque langue d&#8217;avoir son propre slug.  &#8211; Dernier point, il ne faut surtout pas mettre de unique : true dans la partie columns de notre schema, sinon on va se retrouver &agrave; ne pas pouvoir mettre &agrave; jour une langue ind&eacute;pendament de l&#8217;autre.  Maintenant que l&#8217;on visualise le sch&eacute;ma et donc les classes qui en d&eacute;coulent on va parler code. Comme on en a l&#8217;habitude on va g&eacute;n&eacute;rer nos mod&egrave;les, notre CRUD&nbsp;de recettes.  On va maintenant s&#8217;attaquer &agrave; notre classe RecipeForm.class.php, on veut que l&#8217;utilisateur n&#8217;ai pas &agrave; rentrer les recettes dans les deux langues mais uniquement dans la sienne. Pour cela il faut lui afficher uniquement le formulaire rattach&eacute; &agrave; sa culture.  <strong>Modifions notre classe:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p399code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39939"><td class="code" id="p399code39"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">class</span> RecipeForm <span style="color: #000000; font-weight: bold;">extends</span> BaseRecipeForm
 <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$lang</span><span style="color: #339933;">;</span> 
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lang</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fr'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lang</span><span style="color: #339933;">;</span> 
&nbsp;
      parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La premi&egrave;re &eacute;tape est donc de red&eacute;finir le constructeur de notre classe auquel on va soumettre une langue par d&eacute;faut et de cr&eacute;er un attribut priv&eacute; pour d&eacute;finir la langue ($lang).  On va maintenant d&eacute;finir l&#8217;affichage de notre formulaire en modifiant la fonction configure()</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p399code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39940"><td class="code" id="p399code40"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cultures</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cultures</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
&nbsp;
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cultures</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$culture</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$i18nObject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Translation</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$culture</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i18n</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RecipeTranslationForm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i18nObject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i18n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i18n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i18n</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_activated'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i18n</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'size'</span><span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i18n</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextarea<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cols'</span><span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">58</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rows'</span><span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">embedForm</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$culture</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i18n</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Dans notre action on va appeler ce formulaire comme suit :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p399code41'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39941"><td class="code" id="p399code41"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeNew<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">culture</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCulture</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RecipeForm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">culture</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Vous noterez que l&#8217;on passe la culture en attribut ainsi on peut le r&eacute;cup&eacute;rer dans le template :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p399code42'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39942"><td class="code" id="p399code42"><pre class="php" style="font-family:monospace;">render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Il vous suffit de mettre d&eacute;sormais tout les champs et les label &agrave; afficher et le tour est jou&eacute;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/12x/internationalisation-et-formulaire-399/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

