Changeset 1698
- Timestamp:
- 02/13/07 05:36:57 (2 years ago)
- Location:
- branches/0.11
- Files:
-
- 7 modified
-
samples/app/lib/routing/AgaviSampleAppLanguageRoutingCallback.class.php (modified) (1 diff)
-
src/translation/AgaviLocale.class.php (modified) (2 diffs)
-
src/translation/AgaviTranslationManager.class.php (modified) (15 diffs)
-
src/validator/AgaviDateTimeValidator.class.php (modified) (2 diffs)
-
src/validator/AgaviNumberValidator.class.php (modified) (1 diff)
-
tests2/date/CalendarTest.php (modified) (2 diffs)
-
tests2/date/TimeZoneTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/samples/app/lib/routing/AgaviSampleAppLanguageRoutingCallback.class.php
r1604 r1698 21 21 // first, let's check if the locale is allowed 22 22 try { 23 $set = $this->context->getTranslationManager()->get ClosestMatchingLocale($parameters['locale']);23 $set = $this->context->getTranslationManager()->getLocaleIdentifier($parameters['locale']); 24 24 $found = true; 25 25 } catch(AgaviException $e) { -
branches/0.11/src/translation/AgaviLocale.class.php
r1656 r1698 28 28 * @version $Id$ 29 29 */ 30 class AgaviLocale 30 class AgaviLocale extends AgaviParameterHolder 31 31 { 32 32 /** … … 50 50 * 51 51 * @param AgaviContext The current application context. 52 * @param array An associative array of initialization parameters. 52 53 * @param string The identifier of the locale 53 * @param array An associative array of initialization parameters.54 * @param array The locale data. 54 55 * 55 56 * @author Dominik del Bondio <ddb@bitxtender.com> 57 * @author David Zuelke <dz@bitxtender.com> 56 58 * @since 0.11.0 57 59 */ 58 public function initialize(AgaviContext $context, $identifier, array $data = array())60 public function initialize(AgaviContext $context, array $parameters = array(), $identifier, array $data = array()) 59 61 { 60 62 $this->context = $context; 63 $this->parameters = $parameters; 64 61 65 $this->identifier = $identifier; 62 66 $this->data = $data; -
branches/0.11/src/translation/AgaviTranslationManager.class.php
r1695 r1698 62 62 63 63 /** 64 * @var string The current locale.64 * @var string The default locale identifier. 65 65 */ 66 66 protected $defaultLocaleIdentifier = null; … … 81 81 */ 82 82 protected $availableLocales = array(); 83 84 /** 85 * @var array A cache for locale instances. 86 */ 87 protected $localeCache = array(); 83 88 84 89 /** … … 166 171 public function setLocale($identifier) 167 172 { 168 $this->currentLocaleIdentifier = $this->get ClosestMatchingLocale($identifier);173 $this->currentLocaleIdentifier = $this->getLocaleIdentifier($identifier); 169 174 $givenData = AgaviLocale::parseLocaleIdentifier($identifier); 170 175 $actualData = AgaviLocale::parseLocaleIdentifier($this->currentLocaleIdentifier); … … 203 208 204 209 /** 210 * Retrieve the default locale. 211 * 212 * @return AgaviLocale The current default. 213 * 214 * @author David Zülke <dz@bitxtender.com> 215 * @since 0.11.0 216 */ 217 public function getDefaultLocale() 218 { 219 $this->getLocale($this->defaultLocale); 220 } 221 222 /** 223 * Retrieve the default locale identifier. 224 * 225 * @return string The default locale identifier. 226 * 227 * @author David Zülke <dz@bitxtender.com> 228 * @since 0.11.0 229 */ 230 public function getDefaultLocaleIdentifier() 231 { 232 return $this->defaultLocaleIdentifier; 233 } 234 235 /** 205 236 * Sets the default domain. 206 237 * … … 250 281 $this->loadCurrentLocale(); 251 282 } elseif(is_string($locale)) { 252 $locale = $this->getLocale FromIdentifier($locale);283 $locale = $this->getLocale($locale); 253 284 } 254 285 … … 285 316 $this->loadCurrentLocale(); 286 317 } elseif(is_string($locale)) { 287 $locale = $this->getLocale FromIdentifier($locale);318 $locale = $this->getLocale($locale); 288 319 } 289 320 … … 320 351 $this->loadCurrentLocale(); 321 352 } elseif(is_string($locale)) { 322 $locale = $this->getLocale FromIdentifier($locale);353 $locale = $this->getLocale($locale); 323 354 } 324 355 … … 358 389 $this->loadCurrentLocale(); 359 390 } elseif(is_string($locale)) { 360 $locale = $this->getLocale FromIdentifier($locale);391 $locale = $this->getLocale($locale); 361 392 } 362 393 … … 475 506 { 476 507 if(!$this->currentLocale || $this->currentLocale->getIdentifier() != $this->givenLocaleIdentifier) { 477 $this->currentLocale = $this->getLocale FromIdentifier($this->givenLocaleIdentifier);508 $this->currentLocale = $this->getLocale($this->givenLocaleIdentifier); 478 509 foreach($this->translators as $translatorList) { 479 510 foreach($translatorList as $translator) { … … 507 538 508 539 /** 540 * @see AgaviTranslationManager::getLocaleIdentifier 541 * 542 * @deprecated 543 */ 544 public function getClosestMatchingLocale($identifier) 545 { 546 return $this->getLocaleIdentifier($identifier); 547 } 548 549 /** 509 550 * Returns the identifier of the available locale which matches the given 510 551 * locale identifier most. 511 552 * 512 * @param string Thelocale identifier513 * 514 * @return string The locale identifier of the available locale.515 * 516 * @author Dominik del Bondio <ddb@bitxtender.com> 517 * @ since 0.11.0518 * /519 public function getClosestMatchingLocale($identifier)520 {521 553 * @param string A locale identifier 554 * 555 * @return string The actual locale identifier of the available locale. 556 * 557 * @author Dominik del Bondio <ddb@bitxtender.com> 558 * @author David Zülke <dz@bitxtender.com> 559 * @since 0.11.0 560 */ 561 public function getLocaleIdentifier($identifier) 562 { 522 563 // if a locale with the given identifier doesn't exist try to find the closest 523 564 // match or bail out on no match or an ambigious match … … 566 607 567 608 /** 609 * @see AgaviTranslationManager::getLocale 610 * 611 * @deprecated 612 */ 613 public function getLocaleFromIdentifier($identifier) 614 { 615 return $this->getLocale($identifier); 616 } 617 618 /** 568 619 * Returns a new AgaviLocale object from the given identifier. 569 620 * 570 621 * @param string The locale identifier 622 * @param bool Force a new instance even if an identical one exists. 571 623 * 572 624 * @return AgaviLocale The locale instance which matches the available … … 574 626 * 575 627 * @author Dominik del Bondio <ddb@bitxtender.com> 576 * @since 0.11.0 577 */ 578 public function getLocaleFromIdentifier($identifier) 628 * @author David Zülke <dz@bitxtender.com> 629 * @since 0.11.0 630 */ 631 public function getLocale($identifier, $forceNew = false) 579 632 { 580 633 // enable shortcut notation to only set options to the current locale … … 589 642 } 590 643 // this doesn't care about the options 591 $availableLocale = $this->availableLocales[$this->getClosestMatchingLocale($identifier)]; 644 $availableLocale = $this->availableLocales[$this->getLocaleIdentifier($identifier)]; 645 646 // if the user wants all options reset he supplies an 'empty' option set (identifier ends with @) 647 if(substr($identifier, -1) == '@') { 648 $idData['options'] = array(); 649 } else { 650 $idData['options'] = array_merge($availableLocale['identifierData']['options'], $idData['options']); 651 } 652 653 if(($atPos = strpos($identifier, '@')) !== false) { 654 $identifier = $availableLocale['identifierData']['locale_str'] . substr($identifier, $atPos); 655 } else { 656 $identifier = $availableLocale['identifier']; 657 } 658 659 if(!$forceNew && isset($this->localeCache[$identifier])) { 660 return $this->localeCache[$identifier]; 661 } 592 662 593 663 if(!isset($this->localeDataCache[$idData['locale_str']])) { … … 616 686 } 617 687 618 $this->localeDataCache[$idData['locale_str']] = array_merge_recursive($data, $availableLocale['parameters']);688 $this->localeDataCache[$idData['locale_str']] = $data; 619 689 } 620 690 621 691 $data = $this->localeDataCache[$idData['locale_str']]; 622 623 // if the user wants all options reset he supplies an 'empty' option set (identifier ends with @)624 if(substr($identifier, -1) == '@') {625 $idData['options'] = array();626 } else {627 $idData['options'] = array_merge($availableLocale['identifierData']['options'], $idData['options']);628 }629 692 630 693 if(isset($idData['options']['calendar'])) { … … 640 703 } 641 704 642 if(($atPos = strpos($identifier, '@')) !== false) {643 $identifier = $availableLocale['identifierData']['locale_str'] . substr($identifier, $atPos);644 } else {645 $identifier = $availableLocale['identifier'];646 }647 648 705 $locale = new AgaviLocale(); 649 $locale->initialize($this->context, $identifier, $data); 706 $locale->initialize($this->context, $availableLocale['parameters'], $identifier, $data); 707 708 if(!$forceNew) { 709 $this->localeCache[$identifier] = $locale; 710 } 650 711 651 712 return $locale; -
branches/0.11/src/validator/AgaviDateTimeValidator.class.php
r1656 r1698 93 93 94 94 $check = $this->getParameter('check', true); 95 $locale = $this->hasParameter('locale') ? $tm->getLocale FromIdentifier($this->getParameter('locale')) : $tm->getCurrentLocale();95 $locale = $this->hasParameter('locale') ? $tm->getLocale($this->getParameter('locale')) : $tm->getCurrentLocale(); 96 96 97 97 if($this->hasMultipleArguments() && !$this->getParameter('arguments_format')) { … … 131 131 $matchedFormat = false; 132 132 foreach($this->getParameter('formats', array()) as $item) { 133 $itemLocale = empty($item['locale']) ? $locale : $tm->getLocale FromIdentifier($item['locale']);133 $itemLocale = empty($item['locale']) ? $locale : $tm->getLocale($item['locale']); 134 134 $type = empty($item['type']) ? 'format' : $item['type']; 135 135 -
branches/0.11/src/validator/AgaviNumberValidator.class.php
r1660 r1698 55 55 if(!$this->getParameter('no_locale', false)) { 56 56 if($locale = $this->getParameter('in_locale')) { 57 $locale = $this->getContext()->getTranslationManager()->getLocale FromIdentifier($locale);57 $locale = $this->getContext()->getTranslationManager()->getLocale($locale); 58 58 } else { 59 59 $locale = $this->getContext()->getTranslationManager()->getCurrentLocale(); -
branches/0.11/tests2/date/CalendarTest.php
r1281 r1698 313 313 { 314 314 // TODO: check how to do this properly ... 315 $c = $this->tm->createCalendar($this->tm->getLocale FromIdentifier('en_US'));315 $c = $this->tm->createCalendar($this->tm->getLocale('en_US')); 316 316 $c->setLenient(false); 317 317 $c->clear(); … … 727 727 * to loop_addroll. - aliu */ 728 728 $times = 20; 729 $cal = $this->tm->createCalendar($this->tm->getLocale FromIdentifier('de_DE'));729 $cal = $this->tm->createCalendar($this->tm->getLocale('de_DE')); 730 730 $sdf = new AgaviSimpleDateFormat("YYYY'-W'ww-ee", AgaviLocale::getGermany()); 731 731 $sdf->applyLocalizedPattern("JJJJ'-W'ww-ee"); -
branches/0.11/tests2/date/TimeZoneTest.php
r1303 r1698 815 815 public function testDisplayName() 816 816 { 817 $enLocale = $this->tm->getLocale FromIdentifier('en_US');817 $enLocale = $this->tm->getLocale('en_US'); 818 818 819 819 $i = 0; … … 863 863 // Make sure we get the default display format for Locales 864 864 // with no display name data. 865 $mt_MT = $this->tm->getLocale FromIdentifier("mt_MT");865 $mt_MT = $this->tm->getLocale("mt_MT"); 866 866 867 867 $name = $zone->getDisplayName($mt_MT);

