Beispiel #1
0
 /**
  * load the locale
  *
  * @access public
  * @param  string $code
  */
 public static function load($code)
 {
     if (self::$_directory === null) {
         self::$_directory = __DIR__ . '/locale/';
     }
     // must be in lower case
     $code = strtolower($code);
     // must be [a-z-0-9]
     if (!preg_match('/^([a-z0-9]+)$/isU', $code)) {
         throw new Html2PdfException(0, 'invalid language code [' . self::$_code . ']');
     }
     // save the code
     self::$_code = $code;
     // get the name of the locale file
     $file = self::$_directory . self::$_code . '.csv';
     // the file must exist
     if (!is_file($file)) {
         throw new Html2PdfException(0, 'language code [' . self::$_code . '] unknown. You can create the translation file [' . $file . '] and send it to the webmaster of html2pdf in order to integrate it into a future release');
     }
     // load the file
     self::$_list = array();
     $handle = fopen($file, 'r');
     while (!feof($handle)) {
         $line = fgetcsv($handle);
         if (count($line) != 2) {
             continue;
         }
         self::$_list[trim($line[0])] = trim($line[1]);
     }
     fclose($handle);
 }
Beispiel #2
0
 /**
  * load the locale
  *
  * @access public
  * @param  string $code
  */
 public static function load($code)
 {
     if (self::$_directory === null) {
         self::$_directory = __DIR__ . '/locale/';
     }
     // must be in lower case
     $code = strtolower($code);
     // must be [a-z-0-9]
     if (!preg_match('/^([a-z0-9]+)$/isU', $code)) {
         throw new Html2PdfException('language code [' . self::$_code . '] invalid.');
     }
     // save the code
     self::$_code = $code;
     // get the name of the locale file
     $file = self::$_directory . self::$_code . '.csv';
     // the file must exist
     if (!is_file($file)) {
         throw new Html2PdfException('language code [' . self::$_code . '] unknown. ' . 'You can create the translation file [' . $file . '] and push it on the Html2Pdf GitHub project.');
     }
     // load the file
     self::$_list = array();
     $handle = fopen($file, 'r');
     while (!feof($handle)) {
         $line = fgetcsv($handle);
         if (count($line) != 2) {
             continue;
         }
         self::$_list[trim($line[0])] = trim($line[1]);
     }
     fclose($handle);
 }