Exemple #1
0
 /**
  * Defines and loads the locale.
  *
  * @param string $LocaleName The name of the locale to load. Locale definitions are kept in each
  * application's locale folder. For example:
  *  /dashboard/locale/$LocaleName.php
  *  /vanilla/locale/$LocaleName.php
  * @param array $ApplicationWhiteList An array of application folders that are safe to examine for locale
  *  definitions.
  * @param array $PluginWhiteList An array of plugin folders that are safe to examine for locale
  *  definitions.
  * @param bool $ForceRemapping For speed purposes, the application folders are crawled for locale
  *  sources. Once sources are found, they are saved in the
  *  cache/locale_mapppings.php file. If ForceRemapping is true, this file will
  *  be ignored and the folders will be recrawled and the mapping file will be
  *  re-generated. You can also simply delete the file and it will
  *  automatically force a remapping.
  */
 public function Set($LocaleName, $ApplicationWhiteList, $PluginWhiteList, $ForceRemapping = FALSE)
 {
     // Get locale sources
     $this->Locale = $LocaleName;
     $LocaleSources = $this->GetLocaleSources($LocaleName, $ApplicationWhiteList, $PluginWhiteList, $ForceRemapping);
     $Codeset = C('Garden.LocaleCodeset', 'UTF8');
     $CurrentLocale = str_replace('-', '_', $LocaleName);
     $SetLocale = $CurrentLocale . '.' . $Codeset;
     setlocale(LC_TIME, $SetLocale, $CurrentLocale);
     if (!is_array($LocaleSources)) {
         $LocaleSources = array();
     }
     // Create a locale config container
     $this->Unload();
     $ConfLocaleOverride = PATH_CONF . '/locale.php';
     $Count = count($LocaleSources);
     for ($i = 0; $i < $Count; ++$i) {
         if ($ConfLocaleOverride != $LocaleSources[$i] && file_exists($LocaleSources[$i])) {
             // Don't double include the conf override file... and make sure it comes last
             $this->Load($LocaleSources[$i], FALSE);
         }
     }
     // Also load any custom defined definitions from the conf directory
     if (file_exists($ConfLocaleOverride)) {
         $this->Load($ConfLocaleOverride, TRUE);
     }
     // Prepare developer mode if needed
     $this->DeveloperMode = C('Garden.Locales.DeveloperMode', FALSE);
     if ($this->DeveloperMode) {
         $this->DeveloperContainer = new Gdn_Configuration();
         $this->DeveloperContainer->Splitting(FALSE);
         $this->DeveloperContainer->Caching(FALSE);
         $DeveloperCodeFile = PATH_CACHE . "/locale-developer-{$LocaleName}.php";
         if (!file_exists($DeveloperCodeFile)) {
             touch($DeveloperCodeFile);
         }
         $this->DeveloperContainer->Load($DeveloperCodeFile, 'Definition', TRUE);
     }
     // Import core (static) translations
     if ($this->DeveloperMode) {
         $this->DeveloperContainer->MassImport($this->LocaleContainer->Get('.'));
     }
     // Allow hooking custom definitions
     $this->FireEvent('AfterSet');
 }