This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
Añadiendo los comportamientos
$('#search_keywords').keyup(function(key) { if (this.value.length >= 3 || this.value == '') { $('#jobs').load( $(this).parents('form').attr('action'), { query: this.value + '*' } ); } }); $('.search input[type="submit"]').hide();
web/js/search.js $(document).ready(function() { $('.search input[type="submit"]').hide(); $('#search_keywords').keyup(function(key) { if (this.value.length >= 3 || this.value == '') { $('#loader').show(); $('#jobs').load( $(this).parents('form').attr('action'), { query: this.value + '*' }, function() { $('#loader').hide(); } ); } }); });
apps/frontend/templates/layout.php
AJAX en las acciones
AJAX layout + renderPartial()
JavaScript layout + searchSuccess.php
apps/frontend/modules/job/actions/actions.class.php public function executeSearch(sfWebRequest $request) { if (!$query = $request‐>getParameter('query')) { return $this‐>forward('job', 'index'); } $this‐>jobs = JobeetJobPeer::getForLuceneQuery($query); if ($request‐>isXmlHttpRequest()) { return $this‐>renderPartial( 'job/list', array('jobs' => $this‐>jobs) ); }
AJAX
}
apps/frontend/modules/job/actions/actions.class.php public function executeSearch(sfWebRequest $request) { if (!$query = $request‐>getParameter('query')) { return $this‐>forward('job', 'index'); } $this‐>jobs = JobeetJobPeer::getForLuceneQuery($query);
if ($request‐>isXmlHttpRequest()) { if ('*' == $query || !$this‐>jobs) { return $this‐>renderText('No results.'); } else { return $this‐>renderPartial( 'job/list', array('jobs' => $this‐>jobs) ); } } }
http://www.symfony‐project.org/api/1_2/sfAction
renderText() renderPartial() renderComponent()
Capítulo 19
i18n y l10n
i18n y l10n "La internacionalización es el proceso de diseñar aplicaciones de software que puedan ser adaptadas a distintos idiomas y regiones sin necesidad de realizar cambios en su ingeniería."
"La localización es el proceso de adaptar el software para una región o idioma específicos mediante la inclusión de componentes específicos de esa región y mediante la traducción del texto."
El usuario
idioma + país = cultura es_ES
fr_FR
es_AR
fr_BE
es_MX
fr_CA
es_PE
idioma (ISO 3166‐1) país (ISO 639‐1)
$this‐>getUser()‐>setCulture('fr_BE'); echo $this‐>getUser()‐>getCulture();
apps/frontend/config/
all: .settings: default_culture: es_ES
settings.yml
$idiomas = $request‐>getLanguages(); $idiomas = $request‐>getPreferredCulture( array('en', 'fr') );
Incluyendo la cultura en la URL
apps/frontend/config/
settings.yml
category: url: /:sf_culture/category/:slug.:sf_format class: sfPropelRoute param: { module: category, action: show, sf_format: html } options: { model: JobeetCategory, type: object } requirements: sf_format: (?:html|atom) job_search: url: /:sf_culture/search param: { module: job, action: search }
Cambiando de idioma
$ ./symfony plugin:install sfFormExtraPlugin
$ ./symfony cc
apps/frontend/templates/
layout.php
$ ./symfony generate:module frontend idioma
apps/frontend/modules/idioma/actions/
components.class.php
class languageComponents extends sfComponents { public function executeIdioma(sfWebRequest $request) { $this‐>form = new sfFormLanguage( $this‐>getUser(), array('languages' => array('en', 'fr')) ); } }
apps/frontend/config/
routing.yml
cambiar_idioma: url: /cambiar_idioma param: { module: idioma, action: cambiarIdioma } apps/frontend/modules/idioma/actions/
actions.class.php
class idiomaActions extends sfActions { public function executeCambiarIdioma(sfWebRequest $request) { $form = new sfFormLanguage( $this‐>getUser(), array('languages' => array('en', 'fr')) ); $form‐>process($request); return $this‐>redirect('@localized_homepage'); } }
apps/frontend/config/
localized_homepage: url: /:sf_culture/ param: { module: job, action: index } requirements: sf_culture: (?:fr|en|es|eu)
routing.yml
Internacionalización
Where are you from?
Vous êtes d'où ?
どこから来ましたか
ASCII
ISO‐8859‐1
UTF‐8
apps/frontend/config/
settings.yml
all: .settings: charset: utf‐8 i18n: on standard_helpers: [Partial, Cache, I18N]
layout.php
apps/frontend/templates/
• gettext • SQLite
_ _( )
• MySQL
• XLIFF
$ ./symfony i18n:extract frontend fr ‐‐auto‐save apps/frontend/i18n/fr/
messages.xml
<xliff version="1.0">
'<strong>'.$pager‐>getNbResults().'' ), $pager‐>getNbResults() ) ?>
$ ./symfony i18n:extract frontend fr ‐‐auto‐save
apps/frontend/i18n/fr/
messages.xml
config/
schema.yml
jobeet_category: _attributes: { isI18N: true, i18nTable: jobeet_category_i18n } id: ~ jobeet_category_i18n: id: { type: integer, required: true, primaryKey: true, foreignTable: jobeet_category, foreignReference: id } culture: { isCulture: true, type: varchar, size: 7, required: true, primaryKey: true } name: { type: varchar(255), required: true } slug: { type: varchar(255), required: true }
data/fixtures/
010_categories.yml
JobeetCategory: design: { } programming: { } JobeetCategoryI18n: design_en: { id: design, culture: en, name: Design } programming_en: { id: programming, culture: en, name: Programming } design_fr: { id: design, culture: fr, name: Design } programming_fr: { id: programming, culture: fr, name: Programmation }
apps/frontend/config/
routing.yml
category: url: /:sf_culture/category/:slug.:sf_format class: sfPropelRoute param: { module: category, action: show, sf_format: html } options: { model: JobeetCategory, type: object, method: doSelectForSlug } requirements: sf_format: (?:html|atom)
$ ./symfony propel:data‐load /frontend_dev.php/fr/category/programmation /frontend_dev.php/en/category/programming
lib/form/
JobeetCategoryForm.class.php
class JobeetCategoryForm extends BaseJobeetCategoryForm { public function configure() { unset($this['jobeet_category_affiliate_list']);
$this‐>embedI18n(array('en', 'fr')); $this‐>widgetSchema‐>setLabel('en', 'English'); $this‐>widgetSchema‐>setLabel('fr', 'French'); } }
Localización
format_date() format_datetime() format_number() format_currency() format_country() format_language()
sfWidgetFormI18nDate sfWidgetFormI18nDateTime sfWidgetFormI18nTime sfWidgetFormI18nSelectCountry sfWidgetFormI18nSelectCurrency sfWidgetFormI18nSelectLanguage sfValidatorI18nChoiceCountry sfValidatorI18nChoiceLanguage