source: trunk/client/inc/hpdf403/_class/locale.class.php@ 404

Last change on this file since 404 was 349, checked in by roby, 4 years ago
File size: 2.2 KB
Line 
1<?php
2/**
3 * HTML2PDF Librairy - HTML2PDF Locale
4 *
5 * HTML => PDF convertor
6 * distributed under the LGPL License
7 *
8 * @author Laurent MINGUET <webmaster@html2pdf.fr>
9 * @version 4.03
10 */
11
12class HTML2PDF_locale
13{
14 /**
15 * code of the current used locale
16 * @var string
17 */
18 static protected $_code = null;
19
20 /**
21 * texts of the current used locale
22 * @var array
23 */
24 static protected $_list = array();
25
26 /**
27 * directory where locale files are
28 * @var string
29 */
30 static protected $_directory = null;
31
32 /**
33 * load the locale
34 *
35 * @access public
36 * @param string $code
37 */
38 static public function load($code)
39 {
40 if (self::$_directory===null) {
41 self::$_directory = dirname(dirname(__FILE__)).'/locale/';
42 }
43
44 // must be in lower case
45 $code = strtolower($code);
46
47 // must be [a-z-0-9]
48 if (!preg_match('/^([a-z0-9]+)$/isU', $code)) {
49 throw new HTML2PDF_exception(0, 'invalid language code ['.self::$_code.']');
50 }
51
52 // save the code
53 self::$_code = $code;
54
55 // get the name of the locale file
56 $file = self::$_directory.self::$_code.'.csv';
57
58 // the file must exist
59 if (!is_file($file)) {
60 throw new HTML2PDF_exception(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');
61 }
62
63 // load the file
64 self::$_list = array();
65 $handle = fopen($file, 'r');
66 while (!feof($handle)) {
67 $line = fgetcsv($handle);
68 if (count($line)!=2) continue;
69 self::$_list[trim($line[0])] = trim($line[1]);
70 }
71 fclose($handle);
72 }
73
74 /**
75 * clean the locale
76 *
77 * @access public static
78 */
79 static public function clean()
80 {
81 self::$_code = null;
82 self::$_list = array();
83 }
84
85 /**
86 * get a text
87 *
88 * @access public static
89 * @param string $key
90 * @return string
91 */
92 static public function get($key, $default='######')
93 {
94 return (isset(self::$_list[$key]) ? self::$_list[$key] : $default);
95 }
96}
Note: See TracBrowser for help on using the repository browser.