dmBridge PHP API
DMLocalizedString.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00019 abstract class DMLocalizedString {
00020 
00023    private static $strings = array();
00024    
00031    public static function getString($key, $strings_folder = null) {
00032       $strings_folder = $strings_folder
00033          ? $strings_folder : dirname(__FILE__) . "/../../includes/strings";
00034       $code = DMConfigIni::getInstance()->getString("dmbridge.language", "en");
00035       $pathname = $strings_folder . "/strings." . $code . ".txt";
00036       if (!file_exists($pathname)) {
00037          $pathname = $strings_folder . "/strings.en.txt";
00038       }
00039       $sum = md5($pathname);
00040       if (!array_key_exists($sum, self::$strings)) {
00041          self::$strings[$sum] = array();
00042          $fh = fopen($pathname, "rb");
00043          while (!feof($fh)) {
00044             $line = fgets($fh);
00045             $parts = explode('=', $line);
00046             $str_key = array_shift($parts);
00047             self::$strings[$sum][trim($str_key)]
00048                   = trim(implode("=", $parts));
00049          }
00050          fclose($fh);
00051       }
00052 
00053       $key = strtoupper($key);
00054       foreach (self::$strings as $path_sum => $strings) {
00055          if ($path_sum == $sum) {
00056             return (array_key_exists($key, $strings))
00057                   ? $strings[$key] : null;
00058          }
00059       }
00060    }
00061 
00062 }
 All Data Structures Functions Variables