Show
Ignore:
Timestamp:
02/29/2008 04:44:17 PM (9 months ago)
Author:
Shadowhand
Message:

Added the start of l10n features.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/core/Kohana.php

    r2175 r2202  
    828828                        // Add the arguments into the line 
    829829                        $line = vsprintf($line, is_array($args[0]) ? $args[0] : $args); 
     830                } 
     831 
     832                return $line; 
     833        } 
     834 
     835        /** 
     836         * Fetch an i10n locale item. 
     837         * 
     838         * @param   string  locale key to fetch 
     839         * @return  mixed   NULL if the key is not found 
     840         */ 
     841        public static function locale($key) 
     842        { 
     843                static $locale = array(); 
     844 
     845                // Extract the main group from the key 
     846                $group = explode('.', $key, 2); 
     847                $group = $group[0]; 
     848 
     849                if (empty($language[$group])) 
     850                { 
     851                        // Messages from this file 
     852                        $messages = array(); 
     853 
     854                        // The name of the file to search for 
     855                        $filename = Config::item('locale.country'); 
     856 
     857                        // Loop through the files and include each one, so SYSPATH files 
     858                        // can be overloaded by more localized files 
     859                        foreach(self::find_file('i10n', $filename) as $file) 
     860                        { 
     861                                include $file; 
     862 
     863                                // Merge in configuration 
     864                                if ( ! empty($locale) AND is_array($locale)) 
     865                                { 
     866                                        foreach($locale as $k => $v) 
     867                                        { 
     868                                                $messages[$k] = $v; 
     869                                        } 
     870                                } 
     871                        } 
     872 
     873                        // Cache the type 
     874                        $language[$group] = $messages; 
     875                } 
     876 
     877                // Get the line from the language 
     878                $line = self::key_string($key, $language); 
     879 
     880                // Return the key string as fallback 
     881                if ($line === NULL) 
     882                { 
     883                        Log::add('error', 'Missing i10n entry '.$key.' for locale '.$filename); 
     884                        return NULL; 
    830885                } 
    831886