diff options
| author | Max Kremmel <xing@synapse.plus.com> | 2008-09-16 08:20:56 +0000 |
|---|---|---|
| committer | Max Kremmel <xing@synapse.plus.com> | 2008-09-16 08:20:56 +0000 |
| commit | 2518bef3991575f9345fbb6a158a8cb394908b58 (patch) | |
| tree | 26875d9f787e1cb9a94126527f3614747f835e04 | |
| parent | c1c489db2e76d5a6d0d9b10c86fb6d848721ac0f (diff) | |
| download | languages-2518bef3991575f9345fbb6a158a8cb394908b58.tar.gz languages-2518bef3991575f9345fbb6a158a8cb394908b58.tar.bz2 languages-2518bef3991575f9345fbb6a158a8cb394908b58.zip | |
add some basic filtering options for easier master string manipulation
| -rw-r--r-- | BitLanguage.php | 33 | ||||
| -rw-r--r-- | master_strings.php | 23 | ||||
| -rw-r--r-- | templates/language_master_strings.tpl | 25 |
3 files changed, 63 insertions, 18 deletions
diff --git a/BitLanguage.php b/BitLanguage.php index 8603e23..ff26283 100644 --- a/BitLanguage.php +++ b/BitLanguage.php @@ -1,7 +1,7 @@ <?php /** * @package languages - * @version $Header: /cvsroot/bitweaver/_bit_languages/BitLanguage.php,v 1.24 2008/06/29 07:51:35 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_languages/BitLanguage.php,v 1.25 2008/09/16 08:20:56 squareing Exp $ * * Copyright (c) 2005 bitweaver.org * Copyright (c) 2004-2005, Christian Fowler, et. al. @@ -250,24 +250,41 @@ class BitLanguage extends BitBase { * loadMasterStrings load all master strings * * @param string $pSourceHash MD5 hash to load + * @param string $pFilter Limit strings loaded to unlimited (default), translated or untranslated * @access public * @return all master strings in $this->mStrings['master'] */ - function loadMasterStrings( $pSourceHash = NULL ) { + function loadMasterStrings( $pSourceHash = NULL, $pFilter = NULL, $pLangCode = NULL ) { $this->verifyMastersLoaded(); - $bindVars = NULL; - $whereSql = NULL; + $bindVars = $whereSql = $joinSql = NULL; + if( $pSourceHash ) { $whereSql = ' WHERE `source_hash`=? '; $bindVars = array( $pSourceHash ); + } else { + // some basic filter options + if( !empty( $pFilter )) { + $joinSql = "LEFT OUTER JOIN `".BIT_DB_PREFIX."i18n_strings` ist ON( im.`source_hash` = ist.`source_hash` )"; + if( $pFilter == 'translated' ) { + $whereSql = "WHERE ist.`trans` IS NOT NULL"; + if( !empty( $pLangCode )) { + $whereSql .= " AND ist.`lang_code` = ?"; + $bindVars[] = $pLangCode; + } + } elseif( $pFilter == 'untranslated' ) { + $whereSql = "WHERE ist.`trans` IS NULL"; + // can't work out SQL to do language limits in this filter + } + } } - $query = "SELECT im.`source_hash` AS `hash_key`, `source`, `package`, im.`source_hash` - FROM `".BIT_DB_PREFIX."i18n_masters` im - $whereSql ORDER BY im.`source`"; + + $query = " + SELECT im.`source_hash` AS `hash_key`, `source`, `package`, im.`source_hash` + FROM `".BIT_DB_PREFIX."i18n_masters` im + $joinSql $whereSql ORDER BY im.`source`"; $this->mStrings['master'] = $this->mDb->getAssoc( $query, $bindVars ); } - /** * storeMasterString store master string * diff --git a/master_strings.php b/master_strings.php index c6a4941..346eb78 100644 --- a/master_strings.php +++ b/master_strings.php @@ -2,7 +2,7 @@ /** * @package languages * @subpackage functions - * @version $Header: /cvsroot/bitweaver/_bit_languages/master_strings.php,v 1.9 2008/06/25 22:21:12 spiderr Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_languages/master_strings.php,v 1.10 2008/09/16 08:20:56 squareing Exp $ */ // Copyright (c) 2005, bitweaver.org @@ -75,14 +75,14 @@ if( !empty( $_REQUEST['change_master'] ) ) { $tranStrings = array(); foreach( $tranArray as $toLangCode ) { $handle = fopen("http://translate.google.com/translate_t?ie=UTF-8&oe=UTF-8&text=".urlencode( $masterString['source'] )."&langpair=en|$toLangCode", "r"); - if($handle) { + if( $handle ) { $contents = ''; - while (!feof($handle)) { - $contents .= fread($handle, 8192); + while( !feof( $handle )) { + $contents .= fread( $handle, 8192 ); } - fclose($handle); + fclose( $handle ); preg_match_all( "!<div id=result_box[^>]*>([^<]*)</div>.*!", $contents, $matches ); - if( isset( $matches[1][0] ) ) { + if( isset( $matches[1][0] )) { $tranStrings[$toLangCode]['guessed'] = TRUE; $tranStrings[$toLangCode]['source_hash'] = $_REQUEST['source_hash']; $tranStrings[$toLangCode]['trans'] = trim( $matches[1][0] ); @@ -118,14 +118,19 @@ if( !empty( $_REQUEST['change_master'] ) ) { } elseif( !empty( $_REQUEST['find'] ) && !empty( $_REQUEST['search'] ) ) { $gBitSmarty->assign_by_ref( 'masterStrings', $gBitLanguage->searchMasterStrings( $_REQUEST['find'] ) ); } else { - $gBitLanguage->loadMasterStrings(); + $gBitLanguage->loadMasterStrings( + NULL, + ( !empty( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : NULL ), + ( !empty( $_REQUEST['filter_lang'] ) ? $_REQUEST['filter_lang'] : NULL ) + ); + // work out what strings to display - if( empty( $_REQUEST['char'] ) ) { + if( empty( $_REQUEST['char'] )) { $pattern = "/^a/i"; } elseif ( $_REQUEST['char'] == '0-9' ) { $pattern = "/^\d/"; } elseif ( $_REQUEST['char'] == '+' ) { - $pattern = "/^[^a-zA-Z]/"; + $pattern = "/^[^a-zA-Z0-9]/"; } elseif ( $_REQUEST['char'] == 'all' ) { $pattern = "//"; } else { diff --git a/templates/language_master_strings.tpl b/templates/language_master_strings.tpl index a5ca603..a2d3289 100644 --- a/templates/language_master_strings.tpl +++ b/templates/language_master_strings.tpl @@ -61,8 +61,31 @@ {else} {minifind name="Search master strings" sort_mode=$sort_mode} + {form legend="Translation Filter"} + <input type="hidden" name="char" value="{$smarty.request.char}" \> + <div class="row"> + {formlabel label="Filter" for=""} + {forminput} + <label><input type="radio" name="filter" {if !$smarty.request.filter }checked="checked" {/if}value="" /> {tr}No filter{/tr}</label><br /> + <label><input type="radio" name="filter" {if $smarty.request.filter == 'untranslated'}checked="checked" {/if}value="untranslated" /> {tr}Only untranslated strings{/tr}</label><br /> + <label><input type="radio" name="filter" {if $smarty.request.filter == 'translated' }checked="checked" {/if}value="translated" /> {tr}Only translated strings{/tr}</label><br /> + <select name="filter_lang" id="filter_lang"> + <option value="">{tr}Any Language{/tr}</option> + {foreach from=$languages key=langCode item=lang} + <option value="{$langCode}" {if $smarty.request.filter_lang == $langCode}selected="selected"{/if}>{$lang.full_name}</option> + {/foreach} + </select> + {formhelp note="Limit the translated filter to this language"} + {/forminput} + </div> + + <div class="submit"> + <input type="submit" name="set_filter" value="{tr}Set Filter{/tr}" /> + </div> + {/form} + {form legend="Translations" id=formid} - {alphabar iall=1} + {alphabar iall=1 filter_lang=$smarty.request.filter_lang filter=$smarty.request.filter} {formfeedback hash=$feedback} |
