diff options
| author | spiderr <spider@viovio.com> | 2011-05-03 00:00:20 -0400 |
|---|---|---|
| committer | spiderr <spider@viovio.com> | 2011-05-03 00:00:20 -0400 |
| commit | 59c411475fd0689464c9dd043b0d34ce6001c1c1 (patch) | |
| tree | c5d0bf0c4e29c22db5555a413be2bc35093c8741 /ajax_translate.php | |
| parent | 0c629fd10a6ea3fc8be98a1f82de2bb16dad26cb (diff) | |
| download | languages-59c411475fd0689464c9dd043b0d34ce6001c1c1.tar.gz languages-59c411475fd0689464c9dd043b0d34ce6001c1c1.tar.bz2 languages-59c411475fd0689464c9dd043b0d34ce6001c1c1.zip | |
add auto translate for master strings; genericize auto javascript; ajax returns null when translation == masterstring
Diffstat (limited to 'ajax_translate.php')
| -rw-r--r-- | ajax_translate.php | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/ajax_translate.php b/ajax_translate.php index 400b658..cc0d668 100644 --- a/ajax_translate.php +++ b/ajax_translate.php @@ -7,8 +7,8 @@ $translation = NULL; if( !empty( $_REQUEST['lang'] ) && !empty( $_REQUEST['source_hash'] ) ) { if( $masterString = $gBitLanguage->getMasterString( $_REQUEST['source_hash'] ) ) { - // convert smarty to tags so it is shielded from translation, escape <> tags with htmlentities before inserting our <smarty></smarty> wrappers - $preppedMaster = preg_replace( '/\{/', '<smarty ', htmlentities( $masterString ) ); + // convert smarty to tags so it is shielded from translation + $preppedMaster = preg_replace( '/\{/', '<smarty ', $masterString ); // needs to be a full tag so we can cleanly de-tagify after translation $preppedMaster = preg_replace( '/}/', '></smarty>', $preppedMaster ); @@ -21,13 +21,14 @@ if( !empty( $_REQUEST['lang'] ) && !empty( $_REQUEST['source_hash'] ) ) { } if( !empty( $data->data->translations[0]->translatedText ) ) { $translation = urldecode( $data->data->translations[0]->translatedText ); - - //detagify - $preppedTranslation = preg_replace( '/<smarty /', '{', $translation ); - // needs to be a full tag so we can cleanly de-tagify after translation - $preppedTranslation = preg_replace( '/><\/smarty>/', '}', $preppedTranslation ); - - print json_encode( array( 'source_hash' => $_REQUEST['source_hash'], 'translation' => html_entity_decode( $preppedTranslation ) ) ); + if( $translation != $masterString ) { + //detagify + $preppedTranslation = preg_replace( '/<smarty /', '{', $translation ); + // needs to be a full tag so we can cleanly de-tagify after translation + $preppedTranslation = preg_replace( '/><\/smarty>/', '}', $preppedTranslation ); + + print json_encode( array( 'lang_code' => $_REQUEST['lang'], 'source_hash' => $_REQUEST['source_hash'], 'translation' => $preppedTranslation ) ); + } } } } |
