summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspiderr <spiderr@bitweaver.org>2025-05-24 20:01:41 -0400
committerspiderr <spiderr@bitweaver.org>2025-05-24 20:01:41 -0400
commitb01baded7e661fa6cdf217c5d7cb04e6dbf8e2b2 (patch)
treee2dd1d9679946fee7d622ac2ef58c0dfd04b0d15
parent2336127922acda2dd9e7c69b40b93ee66ee92179 (diff)
downloadlanguages-b01baded7e661fa6cdf217c5d7cb04e6dbf8e2b2.tar.gz
languages-b01baded7e661fa6cdf217c5d7cb04e6dbf8e2b2.tar.bz2
languages-b01baded7e661fa6cdf217c5d7cb04e6dbf8e2b2.zip
empty check on pString in ::translate
-rw-r--r--includes/classes/BitLanguage.php76
1 files changed, 40 insertions, 36 deletions
diff --git a/includes/classes/BitLanguage.php b/includes/classes/BitLanguage.php
index 79e5166..dfc4791 100644
--- a/includes/classes/BitLanguage.php
+++ b/includes/classes/BitLanguage.php
@@ -583,48 +583,52 @@ class BitLanguage extends BitSingleton {
*/
function translate( $pString ) {
global $gBitTranslationHash, $gBitSystem;
- $sourceHash = $this->getSourceHash( $pString );
- $cacheFile = TEMP_PKG_PATH."lang/".$this->mLanguage."/".$sourceHash;
- if( $this->mLanguage == 'en' ) {
- $ret = $pString;
- } elseif( !empty( $this->mStrings[$this->mLanguage][$sourceHash] ) ) {
- $ret = $this->mStrings[$this->mLanguage][$sourceHash]['trans'];
- } elseif( file_exists( $cacheFile ) && !$gBitSystem->isFeatureActive( 'i18n_interactive_translation' ) ) {
- $ret = file_get_contents( $cacheFile );
- } else {
- if( empty( $this->mStrings[$this->mLanguage] ) ) {
- $this->verifyTranslationLoaded( $this->mLanguage );
- }
- $tran = $this->lookupTranslation( $pString, $this->mLanguage );
- if( empty( $tran ) ) {
- // lookup failed. let's snag the first part of the langCode if it is a dialect (e.g. pt-br )
- $dialect = strpos( $this->mLanguage, '-' );
- if( $dialect ) {
- $tran = $this->lookupTranslation( $pString, substr( $this->mLanguage, 0, $dialect ) );
+ if( !empty( $pString ) ) {
+ $sourceHash = $this->getSourceHash( $pString );
+ $cacheFile = TEMP_PKG_PATH."lang/".$this->mLanguage."/".$sourceHash;
+ if( $this->mLanguage == 'en' ) {
+ $ret = $pString;
+ } elseif( !empty( $this->mStrings[$this->mLanguage][$sourceHash] ) ) {
+ $ret = $this->mStrings[$this->mLanguage][$sourceHash]['trans'];
+ } elseif( file_exists( $cacheFile ) && !$gBitSystem->isFeatureActive( 'i18n_interactive_translation' ) ) {
+ $ret = file_get_contents( $cacheFile );
+ } else {
+ if( empty( $this->mStrings[$this->mLanguage] ) ) {
+ $this->verifyTranslationLoaded( $this->mLanguage );
}
+ $tran = $this->lookupTranslation( $pString, $this->mLanguage );
if( empty( $tran ) ) {
- $tran = $pString;
+ // lookup failed. let's snag the first part of the langCode if it is a dialect (e.g. pt-br )
+ $dialect = strpos( $this->mLanguage, '-' );
+ if( $dialect ) {
+ $tran = $this->lookupTranslation( $pString, substr( $this->mLanguage, 0, $dialect ) );
+ }
+ if( empty( $tran ) ) {
+ $tran = $pString;
+ }
}
+ // write out the cache - translated or not so we don't keep hitting the database
+ mkdir_p( dirname( $cacheFile ) );
+ $fp = fopen( $cacheFile, 'w' );
+ fwrite( $fp, $tran );
+ fclose( $fp );
+ $this->mStrings[$this->mLanguage][$sourceHash]['trans'] = $tran;
+ $ret = $tran;
}
- // write out the cache - translated or not so we don't keep hitting the database
- mkdir_p( dirname( $cacheFile ) );
- $fp = fopen( $cacheFile, 'w' );
- fwrite( $fp, $tran );
- fclose( $fp );
- $this->mStrings[$this->mLanguage][$sourceHash]['trans'] = $tran;
- $ret = $tran;
- }
- // interactive translation process
- if( $gBitSystem->isFeatureActive( 'i18n_interactive_translation' ) ) {
- if( empty( $gBitTranslationHash ) ) {
- $gBitTranslationHash = array();
- }
- if( !$index = array_search( $sourceHash, $gBitTranslationHash ) ) {
- $gBitTranslationHash[] = $sourceHash;
- $index = count( $gBitTranslationHash ) - 1;
+ // interactive translation process
+ if( $gBitSystem->isFeatureActive( 'i18n_interactive_translation' ) ) {
+ if( empty( $gBitTranslationHash ) ) {
+ $gBitTranslationHash = array();
+ }
+ if( !$index = array_search( $sourceHash, $gBitTranslationHash ) ) {
+ $gBitTranslationHash[] = $sourceHash;
+ $index = count( $gBitTranslationHash ) - 1;
+ }
+ $ret .= '_'.$index;
}
- $ret .= '_'.$index;
+ } else {
+ $ret = $pString;
}
return $ret;