Пример #1
0
                    <?php 
        echo $row->catName;
        ?>
                </td>
                <?php 
        if ($langs) {
            ?>
                    <?php 
            foreach ($langs as $lcode => $lname) {
                ?>
                    <td class="colName <?php 
                echo $lcode;
                ?>
">
                        <?php 
                $lcode = _queryLang($lcode);
                if (isset($i18n['catName_i18n'][$lcode])) {
                    echo $i18n['catName_i18n'][$lcode];
                } else {
                    echo '&nbsp;';
                }
                ?>
                    </td>
                    <?php 
            }
            ?>
                <?php 
        }
        ?>
            </tr>
        <?php 
/**
 * Get translation strings from the query result
 * and return the array of `$i18n[fieldName][lang] = $value`
 *
 * @param object|array $data   The query result
 * @param array|string $fields The array of field names to get data, e.g.,
 *   'fieldName' or `array('fieldName1', 'fieldName2')`
 * @param string       $lang   The language code to fetch (if it is not provided, all languages will be fetched)
 *
 * @return array|object        The array or object of translation strings
 */
function _getTranslationStrings($data, $fields, $lang = null)
{
    global $lc_defaultLang;
    global $lc_languages;
    $isObject = is_object($data);
    $data = (array) $data;
    $i18n = array();
    if (is_string($fields)) {
        $fields = array($fields);
    }
    foreach ($fields as $name) {
        if ($lang) {
            $lcode = _queryLang($lang);
            if (isset($data[$name . '_' . $lcode]) && $data[$name . '_' . $lcode]) {
                $data[$name . '_i18n'] = $data[$name . '_' . $lcode];
            } else {
                $data[$name . '_i18n'] = $data[$name];
            }
        } else {
            foreach ($lc_languages as $lcode => $lname) {
                $lcode = _queryLang($lcode);
                if (isset($data[$name . '_' . $lcode])) {
                    $data[$name . '_i18n'][$lcode] = $data[$name . '_' . $lcode];
                }
            }
        }
    }
    if ($isObject) {
        $data = (object) $data;
    }
    return $data;
}