/** * Load language file. Each language file contains three arrays: * about, dictionary and transliterations. * * @param string $path * Path of the language file that should be loaded * @param boolean $clear * True, if the current dictionary should be cleared, defaults to false */ public static function load($path, $clear = false) { // Initialize or clear dictionary if (!self::$_dictionary instanceof Dictionary || $clear === true) { self::initialize(); } // Load language file if (file_exists($path)) { require $path; } // Define default dates if (empty(self::$_dates)) { $dates = array('yesterday', 'today', 'tomorrow', 'now', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'sec', 'second', 'min', 'minute', 'hour', 'day', 'fortnight', 'forthnight', 'month', 'year', 'secs', 'seconds', 'mins', 'minutes', 'hours', 'days', 'fortnights', 'forthnights', 'months', 'years', 'weekday', 'weekdays', 'week', 'weeks', 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'next', 'last', 'previous', 'this'); foreach ($dates as $date) { self::$_dates[$date] = $date; } } // Merge dictionaries if (isset($dictionary) && is_array($dictionary)) { self::$_dictionary->merge($dictionary); // Add date translations foreach (self::$_dates as $key => $value) { self::$_dates[$key] = __($key); } } // Populate transliterations if (isset($transliterations) && is_array($transliterations)) { self::$_transliterations = array_merge(self::$_transliterations, $transliterations); } // Use default if no transliterations are provided with the translations if (empty(self::$_transliterations)) { include LANG . '/lang.en.php'; self::$_transliterations = $transliterations; } }
<?php namespace Util; require_once __DIR__ . '/../vendor/autoload.php'; $dict = new Dictionary(array('testing.this' => 'test1', 'testing.t' => 'test', 'testing.te' => 'test', 'testing.tes.flip' => 'test')); $dict['testing.it.some.more'] = 'ssssss'; $dict['testing.test'] = '1'; $dict['testing.tea'] = '1'; $dict['banana.tea'] = '1'; $dict['banana.te.a'] = '1'; $dict['banana.te'] = 'a'; $dict->merge(array('test.again' => 'a', 'test.another' => 'b', 'banana.tea.chai' => 'good')); echo '<pre>'; print_r($dict->get()); print_r($dict['test.again']);