Hi all.

As you probably are aware of - there is a new menu system in HEAD.
The menu items are collected from all applications in one operation and cached 
for later use.

However there is one issue concerning translation:

There is a lot of menu items (the app property has about 110 of it's one) - and 
message_id's are bound to conflict across applications if all are placed in 
'common'.

as an example - 'project' does not have the same translation in the app project 
as in the app property.

This problem (I think) is only true for the menu-translations.
a simple workaround is to allow to ask for translations from a specific 
application.
There is already a flag for this- but it is a boolean - and only forces to 
check for 'common'.
What I propose - it to alter this from a bolean to a string - allowing asking 
for translations for an application as well.

The function is tested at the ReSight project and performs as intended, works 
for both shm and non-shm enabled environment.

See attachment

How about it ?

Regards

Sigurd
                /**
                * Translate a string
                *
                * @param string $key the string to translate - truncates at 230 
chars
                * @param array $vars substitutions to apply to string 
"%$array_key" must be present in $key
                * @param string $app_name ask for translation from a desired 
application (or common), should be used when calling this from non module 
contexts
                * @return string the translated string - when unable to be 
translated, the string is returned as "!$key"
                */
                public function translate($key, $vars = array(), $app_name = 
false )
                {
                        $ret = $key;
                        if ( !$userlang = $this->userlang )
                        {
                                $userlang = 'en';
                        }

                        $lookup_key = strtolower(trim(substr($key, 0, 
self::MAX_MESSAGE_ID_LENGTH)));
                        $lookup_app = $app_name ? $app_name : $this->lookup_app;

                        if ( !is_array($this->lang) 
                                || 
(!isset($this->lang[$lookup_app][$lookup_key]) && !$this->loaded_from_shm))
                        {
                                if ( !$app_name )
                                {
                                        $order = ' ORDER BY app_name ASC';
                                        $applist = "'common', 'all', 
'{$GLOBALS['phpgw_info']['flags']['currentapp']}'";
                                        if ( 
strcasecmp($GLOBALS['phpgw_info']['flags']['currentapp'], 'common') <= 1 )
                                        {
                                                $order = 'ORDER BY app_name 
DESC';
                                        }
                                        $filter = " AND app_name IN({$applist}) 
{$order}";
                                }
                                else
                                {
                                        $filter = " AND app_name = '" . 
$lookup_app . "'";
                                }

                                $sql = 'SELECT message_id, content'
                                        . " FROM phpgw_lang WHERE lang = 
'{$userlang}' AND message_id = '" . 
$GLOBALS['phpgw']->db->db_addslashes($lookup_key) . '\''
                                        . $filter;

                                
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);

                                while ($GLOBALS['phpgw']->db->next_record())
                                {
                                        $this->lang[$lookup_app][$lookup_key] = 
$GLOBALS['phpgw']->db->f('content', true);
                                }
                        }

                        $ret = "!{$key}";       // save key if we dont find a 
translation
                        $key = $lookup_key;

                        if ( isset($this->lang[$lookup_app][$key]) )
                        {
                                $ret = $this->lang[$lookup_app][$key];
                        }

                        $ndx = 1;
                        foreach ( $vars as $key => $val )
                        {
                                $ret = preg_replace( "/%$ndx/", $val, $ret );
                                ++$ndx;
                        }
                        return $ret;
                }
_______________________________________________
phpGroupWare-developers mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/phpgroupware-developers

Reply via email to