Changeset 16480

Show
Ignore:
Timestamp:
05/27/08 23:51:40 (5 months ago)
Author:
adrenalin
Message:

Allow the fallback language to be chosen instead of forced English. A
lot of code cleanup to comply with MidCOM coding standards.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.admin.babel/config/manifest.inc

    r15038 r16480  
    1515            'name' => 'Marcin Sołtysiak', 
    1616            'email' => 'olga@olga.pl', 
     17            'role' => 'lead', 
     18        ), 
     19        'adrenalin' => array 
     20        ( 
     21            'name' => 'Arttu Manninen', 
    1722            'role' => 'lead', 
    1823        ), 
  • trunk/midcom/midcom.admin.babel/documentation/CHANGES

    r12795 r16480  
    88  which might even break existing functionality. 
    99- All items marked with "+" represent completely new features. 
     10 
     112008-05-27 adrenalin 
     12  + Allow the fallback language to be chosen instead of forced English 
     13 
    10142007-10-13 solt 
    1115  + Moved to Asgard plugin 
  • trunk/midcom/midcom.admin.babel/handler/process.php

    r14773 r16480  
    3636        $this->_l10n = $_MIDCOM->i18n->get_l10n('midcom.admin.babel'); 
    3737        $this->_request_data['l10n'] = $this->_l10n; 
    38         $this->_debug_prefix = "midcom_admin_babel::"
     38        $this->_debug_prefix = 'midcom_admin_babel::'
    3939        $this->_save_new = false; 
    4040        $this->_save_update = false; 
     41         
     42        $this->_fallback_language = $_MIDCOM->i18n->get_fallback_language(); 
    4143 
    4244        $_MIDCOM->cache->content->no_cache(); 
     
    4951                'type'  => 'text/css', 
    5052                'media' => 'screen', 
    51                 'href'  => MIDCOM_STATIC_URL ."/midcom.admin.babel/babel.css" 
     53                'href'  => MIDCOM_STATIC_URL .'/midcom.admin.babel/babel.css' 
    5254            ) 
    5355        ); 
     
    165167        } 
    166168 
    167         debug_add("saving data for component '".$this->_component_path."', language '".$this->_lang."'", MIDCOM_LOG_DEBUG); 
     169        debug_add("saving data for component '{$this->_component_path}', language '{$this->_lang}'"); 
    168170 
    169171        $this->_component_l10n = $_MIDCOM->i18n->get_l10n($this->_component_path); 
    170172 
    171         if (array_key_exists("string_id", $_REQUEST)) 
    172         { 
    173             $this->_save_update = Array ( 
    174                 "id" => $_REQUEST["string_id"], 
    175                 "value" => $_REQUEST["string_value"] 
     173        if (array_key_exists('string_id', $_REQUEST)) 
     174        { 
     175            $this->_save_update = array 
     176            ( 
     177                'id' => $_REQUEST['string_id'], 
     178                'value' => $_REQUEST['string_value'] 
    176179            ); 
    177180        } 
    178181 
    179         if ((array_key_exists("new_stringid", $_REQUEST)) && 
    180             ($_REQUEST["new_stringid"] != "") && 
    181             (array_key_exists("new_en", $_REQUEST)) && 
    182             ($_REQUEST["new_en"] != "")) 
    183         { 
    184             $this->_save_new = Array ( 
    185                 "stringid" => $_REQUEST["new_stringid"], 
    186                 "en" => $_REQUEST["new_en"] 
     182        if (   array_key_exists('new_stringid', $_REQUEST) 
     183            && $_REQUEST['new_stringid'] 
     184            && array_key_exists('new_fallback', $_REQUEST) 
     185            && $_REQUEST['new_fallback']) 
     186        { 
     187            $this->_save_new = Array 
     188            ( 
     189                'stringid' => $_REQUEST['new_stringid'], 
     190                $this->_fallback_language => $_REQUEST['new_fallback'] 
    187191            ); 
    188             if ((array_key_exists("new_loc", $_REQUEST)) && 
    189                 ($_REQUEST["new_loc"] != "")) 
    190             { 
    191                 $this->_save_new["loc"] = $_REQUEST["new_loc"]; 
     192             
     193            if (   array_key_exists('new_loc', $_REQUEST) 
     194                && $_REQUEST['new_loc']) 
     195            { 
     196                $this->_save_new['loc'] = $_REQUEST['new_loc']; 
    192197            } 
    193198        } 
     
    198203        if ($this->_save_update) 
    199204        { 
    200             debug_add("Updating strings", MIDCOM_LOG_DEBUG); 
    201             foreach ($this->_save_update["id"] as $k => $v) 
    202             { 
    203                 $id = $this->_save_update["id"][$k]; 
    204                 $loc = $this->_save_update["value"][$k]; 
     205            debug_add('Updating strings', MIDCOM_LOG_DEBUG); 
     206            foreach ($this->_save_update['id'] as $k => $v) 
     207            { 
     208                $id = $this->_save_update['id'][$k]; 
     209                $loc = $this->_save_update['value'][$k]; 
    205210                $origloc = $this->_component_l10n->get($id, $this->_lang); 
    206211 
     
    209214                    if ($loc == $origloc) 
    210215                    { 
    211                         debug_add("    '$id' is unchanged, skipping it."); 
     216                        debug_add("'{$id}' is unchanged, skipping it."); 
    212217                        continue; 
    213218                    } 
    214                     if ($loc == "") 
     219                     
     220                    if (!$loc) 
    215221                    { 
    216                         debug_add("    Resetting '$id'", MIDCOM_LOG_DEBUG); 
     222                        debug_add("Resetting '{$id}'", MIDCOM_LOG_DEBUG); 
    217223                        $this->_component_l10n->delete($id, $this->_lang); 
    218224                        $changes = true; 
     
    220226                    else 
    221227                    { 
    222                         debug_add("    Updating '$id' -> '$loc'", MIDCOM_LOG_DEBUG); 
     228                        debug_add("Updating '{$id}' -> '{$loc}'", MIDCOM_LOG_DEBUG); 
    223229                        $this->_component_l10n->update($id, $this->_lang, $loc); 
    224230                        $changes = true; 
    225231                    } 
    226232                } 
    227                 else if ($loc != ""
    228                 { 
    229                     debug_add("    Creating '$id' -> '$loc'", MIDCOM_LOG_DEBUG); 
     233                else if (!$loc
     234                { 
     235                    debug_add("    Creating '{$id}' -> '{$loc}'", MIDCOM_LOG_DEBUG); 
    230236                    $this->_component_l10n->update($id, $this->_lang, $loc); 
    231237                    $changes = true; 
     
    233239                else 
    234240                { 
    235                     debug_add("    Ignoring '$id' -> '$loc'", MIDCOM_LOG_DEBUG); 
     241                    debug_add("    Ignoring '{$id}' -> '{$loc}'", MIDCOM_LOG_DEBUG); 
    236242                } 
    237243            } 
     
    241247        if ($this->_save_new) 
    242248        { 
    243             debug_add("Creating new string", MIDCOM_LOG_DEBUG); 
    244             // create english string 
    245             $this->_component_l10n->update($this->_save_new["stringid"], "en", $this->_save_new["en"]); 
    246                 // create loc'd string 
    247             if (array_key_exists("loc", $this->_save_new)) 
    248                 $this->_component_l10n->update($this->_save_new["stringid"], $this->_lang, $this->_save_new["loc"]); 
     249            debug_add('Creating new string', MIDCOM_LOG_DEBUG); 
     250             
     251            // create fallback language string 
     252            $this->_component_l10n->update($this->_save_new['stringid'], $this->_fallback_language, $this->_save_new[$this->_fallback_language]); 
     253             
     254            // create loc'd string 
     255            if (array_key_exists('loc', $this->_save_new)) 
     256            { 
     257                $this->_component_l10n->update($this->_save_new['stringid'], $this->_lang, $this->_save_new['loc']); 
     258            } 
    249259 
    250260            $changes = true; 
     
    253263        if ($changes) 
    254264        { 
    255             debug_add("Changes have been made, Flushing to disk now."); 
     265            debug_add('Changes have been made, Flushing to disk now.'); 
    256266            $this->_component_l10n->flush(); 
    257267        } 
     
    322332        $data['section'] = 'core'; 
    323333        midcom_show_style('midcom_admin_babel_status_section_header'); 
     334         
    324335        foreach ($data['components_core'] as $component => $string_counts) 
    325336        { 
     
    328339            midcom_show_style('midcom_admin_babel_status_item'); 
    329340        } 
     341         
    330342        midcom_show_style('midcom_admin_babel_status_section_footer'); 
    331343 
    332344        $data['section'] = 'other'; 
    333345        midcom_show_style('midcom_admin_babel_status_section_header'); 
     346         
    334347        foreach ($data['components_other'] as $component => $string_counts) 
    335348        { 
     
    338351            midcom_show_style('midcom_admin_babel_status_item'); 
    339352        } 
     353         
    340354        midcom_show_style('midcom_admin_babel_status_section_footer'); 
    341355 
     
    359373        } 
    360374 
    361         debug_push($this->_debug_prefix . "handle"); 
     375        debug_push($this->_debug_prefix . 'handle'); 
    362376 
    363377        // make sure text is displayed as utf-8 => REALLY? 
    364         //header("Content-type: text/html; charset=UTF-8"); 
     378        //header('Content-type: text/html; charset=UTF-8'); 
    365379 
    366380        if (   $this->_component_path 
    367381            && $this->_lang) 
    368382        { 
    369             debug_add("Loading i10n class for ".$this->_component_path, MIDCOM_LOG_DEBUG); 
     383            debug_add('Loading i10n class for '.$this->_component_path, MIDCOM_LOG_DEBUG); 
    370384            if (!$this->_component_l10n = $_MIDCOM->i18n->get_l10n($this->_component_path)) 
    371385            { 
     
    426440                $view_strings[$id] = array 
    427441                ( 
    428                     'en'         => $this->_component_l10n->get($id, 'en'), 
     442                    $this->_fallback_language => $this->_component_l10n->get($id, $this->_fallback_language), 
    429443                    $this->_lang => $loc 
    430444                ); 
     
    449463    function _show_permission_check($handler_id, &$data) 
    450464    { 
    451         if ($this->_component_path == "midcom"
     465        if ($this->_component_path == 'midcom'
    452466        { 
    453467            $path = MIDCOM_ROOT . '/midcom/locale'; 
     
    455469        else 
    456470        { 
    457             $path = MIDCOM_ROOT . '/' . str_replace(".", "/", $this->_component_path) . '/locale'; 
    458         } 
    459         $en = "{$path}/default.en.txt"; 
     471            $path = MIDCOM_ROOT . '/' . str_replace('.', '/', $this->_component_path) . '/locale'; 
     472        } 
     473         
     474        $fallback = "{$path}/default.{$this->_fallback_language}.txt"; 
    460475        $main = "{$path}/default.{$this->_lang}.txt"; 
    461476 
    462         if (    ! is_writable($path) 
    463             || (file_exists($en) && ! is_writable($en)) 
    464             || (file_exists($main) && ! is_writable($main))) 
     477        if (   !is_writable($path) 
     478            || (   file_exists($fallback) 
     479                && ! is_writable($fallback)) 
     480            || (   file_exists($main) 
     481                && ! is_writable($main))) 
    465482        { 
    466483            midcom_show_style('midcom_admin_babel_permission_denied'); 
    467484        } 
    468485    } 
    469  
    470  
    471  
    472486} 
    473  
    474487?> 
  • trunk/midcom/midcom.admin.babel/style/midcom_admin_babel_edit.php

    r12850 r16480  
    99asort($components); 
    1010 
     11$fallback_language = $_MIDCOM->i18n->get_fallback_language(); 
    1112$deflang = $languages[$_MIDCOM->i18n->get_fallback_language()]['enname']; 
    1213$editlang = $languages[$data['view_lang']]['enname']; 
     
    2930            <th>&(deflang); (<?php echo $data['l10n']->get('default');?>)</th> 
    3031            <?php  
    31             if ($data['view_lang'] != 'en')  
     32            if ($data['view_lang'] !== $fallback_language) 
    3233            {  
    3334                ?> 
     
    4344        <tr class="newstring"> 
    4445            <td><?php echo $data['l10n']->get('new string')?><br /><input type="text" name="new_stringid" size="35" /></td> 
    45             <td><textarea type="text" name="new_en" cols="30" rows="3" wrap="virtual"></textarea></td> 
     46            <td><textarea type="text" name="new_fallback" cols="30" rows="3" wrap="virtual"></textarea></td> 
    4647            <?php  
    47             if ($data['view_lang'] != 'en')  
     48            if ($data['view_lang'] !== $fallback_language) 
    4849            {  
    4950                ?> 
     
    5859        foreach ($data['view_strings'] as $id => $str)  
    5960        { 
    60             $en = $str['en']; 
     61            $fallback = $str[$fallback_language]; 
    6162            $loc = $str[$data['view_lang']]; 
    62             $row = ($count/2 == floor($count/2))?"even":"odd"; 
     63             
     64            if ($count % 2 === 0) 
     65            { 
     66                $row = 'even'; 
     67            } 
     68            else 
     69            { 
     70                $row = 'odd'; 
     71            } 
    6372            ?> 
    6473            <tr class="string-&(row);"> 
    6574                <th>&(id);</th> 
    6675                <?php  
    67                 if ($data['view_lang'] != 'en')  
     76                if ($data['view_lang'] !== $fallback_language) 
    6877                {  
    6978                    ?> 
    70                     <td><span>&(en);</span></td> 
     79                    <td><span>&(fallback);</span></td> 
    7180                    <?php  
    7281                }