You are here

public function PHPExcel_Calculation::setLocale in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php \PHPExcel_Calculation::setLocale()

* Set the locale code * *

Parameters

string $locale The locale to use for formula translation: * @return boolean

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php, line 1962

Class

PHPExcel_Calculation
PHPExcel_Calculation (Multiton)

Code

public function setLocale($locale = 'en_us') {

  //	Identify our locale and language
  $language = $locale = strtolower($locale);
  if (strpos($locale, '_') !== FALSE) {
    list($language) = explode('_', $locale);
  }
  if (count(self::$_validLocaleLanguages) == 1) {
    self::_loadLocales();
  }

  //	Test whether we have any language data for this language (any locale)
  if (in_array($language, self::$_validLocaleLanguages)) {

    //	initialise language/locale settings
    self::$_localeFunctions = array();
    self::$_localeArgumentSeparator = ',';
    self::$_localeBoolean = array(
      'TRUE' => 'TRUE',
      'FALSE' => 'FALSE',
      'NULL' => 'NULL',
    );

    //	Default is English, if user isn't requesting english, then read the necessary data from the locale files
    if ($locale != 'en_us') {

      //	Search for a file with a list of function names for locale
      $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $locale) . DIRECTORY_SEPARATOR . 'functions';
      if (!file_exists($functionNamesFile)) {

        //	If there isn't a locale specific function file, look for a language specific function file
        $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . 'functions';
        if (!file_exists($functionNamesFile)) {
          return FALSE;
        }
      }

      //	Retrieve the list of locale or language specific function names
      $localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
      foreach ($localeFunctions as $localeFunction) {
        list($localeFunction) = explode('##', $localeFunction);

        //	Strip out comments
        if (strpos($localeFunction, '=') !== FALSE) {
          list($fName, $lfName) = explode('=', $localeFunction);
          $fName = trim($fName);
          $lfName = trim($lfName);
          if (isset(self::$_PHPExcelFunctions[$fName]) && $lfName != '' && $fName != $lfName) {
            self::$_localeFunctions[$fName] = $lfName;
          }
        }
      }

      //	Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions
      if (isset(self::$_localeFunctions['TRUE'])) {
        self::$_localeBoolean['TRUE'] = self::$_localeFunctions['TRUE'];
      }
      if (isset(self::$_localeFunctions['FALSE'])) {
        self::$_localeBoolean['FALSE'] = self::$_localeFunctions['FALSE'];
      }
      $configFile = PHPEXCEL_ROOT . 'PHPExcel' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $locale) . DIRECTORY_SEPARATOR . 'config';
      if (!file_exists($configFile)) {
        $configFile = PHPEXCEL_ROOT . 'PHPExcel' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . 'config';
      }
      if (file_exists($configFile)) {
        $localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        foreach ($localeSettings as $localeSetting) {
          list($localeSetting) = explode('##', $localeSetting);

          //	Strip out comments
          if (strpos($localeSetting, '=') !== FALSE) {
            list($settingName, $settingValue) = explode('=', $localeSetting);
            $settingName = strtoupper(trim($settingName));
            switch ($settingName) {
              case 'ARGUMENTSEPARATOR':
                self::$_localeArgumentSeparator = trim($settingValue);
                break;
            }
          }
        }
      }
    }
    self::$functionReplaceFromExcel = self::$functionReplaceToExcel = self::$functionReplaceFromLocale = self::$functionReplaceToLocale = NULL;
    self::$_localeLanguage = $locale;
    return TRUE;
  }
  return FALSE;
}