summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspiderr <spider@viovio.com>2011-04-30 00:47:46 -0400
committerspiderr <spider@viovio.com>2011-04-30 00:47:46 -0400
commit8207024c6e242f500b49b171a1527f8e6111e69a (patch)
treecba721c47a4544257a167b4673d90380a198f63e
parentd5b6c2b342deda0b0cde496c4bda5cc344e23e18 (diff)
downloadlanguages-8207024c6e242f500b49b171a1527f8e6111e69a.tar.gz
languages-8207024c6e242f500b49b171a1527f8e6111e69a.tar.bz2
languages-8207024c6e242f500b49b171a1527f8e6111e69a.zip
seperate out string translation per language into a separate file, add support for google translate API
-rw-r--r--BitLanguage.php11
-rw-r--r--ajax_translate.php24
-rw-r--r--edit_languages.php28
-rw-r--r--icons/google-favicon.pngbin0 -> 993 bytes
-rw-r--r--templates/edit_languages.tpl249
-rw-r--r--templates/menu_languages.tpl1
-rw-r--r--templates/menu_languages_admin.tpl3
-rw-r--r--templates/translate_strings.tpl81
-rw-r--r--translate_strings.php99
9 files changed, 316 insertions, 180 deletions
diff --git a/BitLanguage.php b/BitLanguage.php
index 1e7510e..b92dee6 100644
--- a/BitLanguage.php
+++ b/BitLanguage.php
@@ -637,6 +637,17 @@ class BitLanguage extends BitBase {
}
/**
+ * getMasterString
+ *
+ * @param string $pSourceHash
+ * @access public
+ * @return master string with given source hash
+ */
+ function getMasterString( $pSourceHash ) {
+ return( $this->mDb->getOne( "SELECT `source` FROM `" . BIT_DB_PREFIX . "i18n_masters` WHERE `source_hash` = ? ", array( $pSourceHash ) ) );
+ }
+
+ /**
* getSourceHash
*
* @param string $pString
diff --git a/ajax_translate.php b/ajax_translate.php
new file mode 100644
index 0000000..7b97111
--- /dev/null
+++ b/ajax_translate.php
@@ -0,0 +1,24 @@
+<?php
+
+$gLightweightScan = TRUE;
+require_once( '../kernel/setup_inc.php' );
+
+$translation = NULL;
+
+if( !empty( $_REQUEST['lang'] ) && !empty( $_REQUEST['source_hash'] ) ) {
+ if( $masterString = $gBitLanguage->getMasterString( $_REQUEST['source_hash'] ) ) {
+
+ $googleUrl = "https://www.googleapis.com/language/translate/v2?key=".$gBitSystem->getConfig('google_api_key')."&source=en&target=".$_REQUEST['lang']."&q=".urlencode( $masterString );
+
+ if( $fh = fopen( $googleUrl, "r" ) ) {
+ $jsonResponse = fread( $fh, 8192 );
+ $data = json_decode( $jsonResponse );
+ fclose( $fh );
+ }
+ if( !empty( $data->data->translations[0]->translatedText ) ) {
+ $translation = $data->data->translations[0]->translatedText;
+ }
+ }
+}
+
+print $translation;
diff --git a/edit_languages.php b/edit_languages.php
index e596629..b4e20d8 100644
--- a/edit_languages.php
+++ b/edit_languages.php
@@ -102,34 +102,8 @@ if( !empty( $_REQUEST['clear_cache'] ) ) {
$gBitSmarty->assign_by_ref( 'defaults', $languages[$_REQUEST['lang']] );
}
$gBitSmarty->assign( 'editDescription', TRUE );
-} elseif( !empty( $_REQUEST['save_translations'] ) ) {
- $editLang = $_REQUEST['lang'];
- $gBitLanguage->loadLanguage( $editLang );
- $storedStrings = NULL;
- foreach( $_REQUEST['edit_trans'] as $sourceHash => $string ) {
- if( $string != $gBitLanguage->mStrings[$editLang][$sourceHash]['trans'] ) {
- // we need to remove the $_REQUEST slashes here to avoid stuff like:
- // {$gBitSystem->getConfig(\'stuff\')} in the translated strings -
- // it will kill the site since smarty won't be able to interpret
- // the template anymore --xing
- if( ini_get( 'magic_quotes_gpc' ) ) {
- $string = stripslashes( $string );
- }
- $gBitLanguage->storeTranslationString( $editLang, $string, $sourceHash );
- // update string in template as well
- $tranStrings[$sourceHash]['trans'] = $string;
- // this has to be the source, otherwise the translated string will enter the db and be recognised as a used master
- $storedStrings[] = $gBitLanguage->mStrings[$editLang][$sourceHash]['source'];
- }
- }
- $tranStrings = $gBitLanguage->getTranslationString( $sourceHash, $editLang );
- $gBitSmarty->assign_by_ref('tranStrings', $tranStrings );
- $gBitSmarty->assign( 'lang', $editLang );
- $gBitSmarty->assign( 'translate', TRUE );
- $gBitSmarty->assign( 'saveSuccess', tra( "The following items have been saved successfully" ).":" );
- $gBitSmarty->assign( 'storedStrings', $storedStrings );
}
-$gBitSystem->display( 'bitpackage:languages/edit_languages.tpl', tra( 'Edit Translations' ) , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:languages/edit_languages.tpl', tra( 'Edit Languages' ) , array( 'display_mode' => 'edit' ));
?>
diff --git a/icons/google-favicon.png b/icons/google-favicon.png
new file mode 100644
index 0000000..81e390d
--- /dev/null
+++ b/icons/google-favicon.png
Binary files differ
diff --git a/templates/edit_languages.tpl b/templates/edit_languages.tpl
index 4295b42..c726436 100644
--- a/templates/edit_languages.tpl
+++ b/templates/edit_languages.tpl
@@ -7,177 +7,122 @@
</div>
<div class="body">
- {if !$translate}
- {jstabs}
- {if $editDescription}
- {if $gBitUser->hasPermission( 'p_languages_create' )}
- {jstab title="Create or Edit Language"}
- {form legend="Create or Edit Language"}
- {formfeedback error=$saveErrors }
- <input type="hidden" name="update_lang_code" value="{$defaults.lang_code}" />
- <div class="row">
- {formlabel label="Native name of the language" for="native_name"}
- {forminput}
- <input type="text" id="native_name" name="native_name" size="45" value="{$defaults.native_name}" />
- {/forminput}
- </div>
- <div class="row">
- {formlabel label="English name of the language" for="english_name"}
- {forminput}
- <input type="text" name="english_name" id="english_name" size="45" value="{$defaults.english_name}" />
- {/forminput}
- </div>
- <div class="row">
- {formlabel label="Language code" for="lang_code"}
- {forminput}
- <input type="text" name="lang_code" id="lang_code" size="8" maxlength="32" value="{$defaults.lang_code}" />
- {formhelp note='For official language codes, see <a class="external" href="http://www.loc.gov/standards/iso639-2/langcodes.html">ISO639-1</a> and to add a localisation you can append the country code from <a class="external" href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1</a>.<br />e.g. ISO639-1 for english is "en" and the country code for britain is "uk". The resulting code is "en-uk".'}
- {/forminput}
- </div>
- <div class="row">
- {formlabel label="Disabled" for="is_disabled"}
- {forminput}
- <input type="checkbox" name="is_disabled" id="is_disabled" {if $isDisabled || $defaults.is_disabled}checked="checked"{/if} value="y" />
- {formhelp note="Disabling a language will remove it from available language menus."}
- {/forminput}
- </div>
- <div class="row submit">
- <input type="submit" name="save_language" value="{tr}Save Language{/tr}" />
- </div>
- {formhelp note="A note for localisations: when you have a language, say 'de' and you add a localisation such as 'de-at' it will first check de-at for a string and then fall back to de. If it still hasn't found a translation, it will default to english."}
- {/form}
- {/jstab}
- {/if}
- {/if}
-
- {jstab title="Choose Language"}
- {formfeedback success=$saveSuccess}
- {form legend="Choose language"}
- <div class="row">
- {formlabel label="Select the language to edit" for="select_language"}
- {forminput}
- <select name="lang" id="select_language">
- {foreach from=$languages key=langCode item=lang}
- {if $langCode != 'en'}
- <option value="{$langCode}" {if $defaults.lang_code eq $langCode}selected="selected"{/if}>{$lang.full_name}</option>
- {/if}
- {/foreach}
- </select>
- {/forminput}
- </div>
-
- {if $gBitSystem->isFeatureActive( 'i18n_track_translation_usage' )}
+ {jstabs}
+ {if $editDescription}
+ {if $gBitUser->hasPermission( 'p_languages_create' )}
+ {jstab title="Create or Edit Language"}
+ {form legend="Create or Edit Language"}
+ {formfeedback error=$saveErrors }
+ <input type="hidden" name="update_lang_code" value="{$defaults.lang_code}" />
<div class="row">
- {formlabel label="Display all strings" for="all_trans"}
+ {formlabel label="Native name of the language" for="native_name"}
{forminput}
- <input type="checkbox" id="all_trans" name="all_trans" {if $allTrans}checked="checked"{/if} value="y" />
- {formhelp note="This will display translation strings for all bitweaver versions. This means it will also show strings that are not used at all and might be useless to you."}
+ <input type="text" id="native_name" name="native_name" size="45" value="{$defaults.native_name}" />
+ {/forminput}
+ </div>
+ <div class="row">
+ {formlabel label="English name of the language" for="english_name"}
+ {forminput}
+ <input type="text" name="english_name" id="english_name" size="45" value="{$defaults.english_name}" />
+ {/forminput}
+ </div>
+ <div class="row">
+ {formlabel label="Language code" for="lang_code"}
+ {forminput}
+ <input type="text" name="lang_code" id="lang_code" size="8" maxlength="32" value="{$defaults.lang_code}" />
+ {formhelp note='For official language codes, see <a class="external" href="http://www.loc.gov/standards/iso639-2/langcodes.html">ISO639-1</a> and to add a localisation you can append the country code from <a class="external" href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1</a>.<br />e.g. ISO639-1 for english is "en" and the country code for britain is "uk". The resulting code is "en-uk".'}
+ {/forminput}
+ </div>
+ <div class="row">
+ {formlabel label="Disabled" for="is_disabled"}
+ {forminput}
+ <input type="checkbox" name="is_disabled" id="is_disabled" {if $isDisabled || $defaults.is_disabled}checked="checked"{/if} value="y" />
+ {formhelp note="Disabling a language will remove it from available language menus."}
{/forminput}
</div>
- {/if}
-
- <div class="row">
- {formlabel label="Only Untranslated" for="un_trans"}
- {forminput}
- <input type="checkbox" id="un_trans" name="un_trans" />
- {formhelp note="Display only untranslated strings when editing the language translations."}
- {/forminput}
- </div>
-
- {formfeedback warning="Editing a language for the first time will cause an import of the language. this can take several minutes, depending on your configuration."}
-
- <div class="row submit">
- <input type="submit" name="delete_language" value="{tr}Delete Language{/tr}" />&nbsp;
- <input type="submit" name="edit_language" value="{tr}Edit Description{/tr}" />&nbsp;
- <input type="submit" name="translate" value="{tr}Edit Translations{/tr}" />
- </div>
-
- {formhelp note="
- <dl>
- <dt>Delete Language</dt>
- <dd>Delete the language from your server.</dd>
- <dt>Edit Description</dt>
- <dd>Edit the description of the language, including language code.</dd>
- <dt>Edit Translations</dt>
- <dd>Edit the translated strings of the selected language.</dd>
- </dl>
- "}
-
- {if $gBitUser->hasPermission( 'p_languages_create' )}
<div class="row submit">
- <input type="submit" name="new_language" value="{tr}Create New Language{/tr}" />
+ <input type="submit" name="save_language" value="{tr}Save Language{/tr}" />
</div>
- {/if}
- {/form}
- {/jstab}
+ {formhelp note="A note for localisations: when you have a language, say 'de' and you add a localisation such as 'de-at' it will first check de-at for a string and then fall back to de. If it still hasn't found a translation, it will default to english."}
+ {/form}
+ {/jstab}
+ {/if}
+ {/if}
- {jstab title="Language Cache"}
- {formfeedback success=$saveSuccess}
- {form legend="Clear Language Cache"}
+ {jstab title="Choose Language"}
+ {formfeedback success=$saveSuccess}
+ {form legend="Choose language"}
+ <div class="row">
+ {formlabel label="Select the language to edit" for="select_language"}
+ {forminput}
+ <select name="lang" id="select_language">
+ {foreach from=$languages key=langCode item=lang}
+ {if $langCode != 'en'}
+ <option value="{$langCode}" {if $defaults.lang_code eq $langCode}selected="selected"{/if}>{$lang.full_name}</option>
+ {/if}
+ {/foreach}
+ </select>
+ {/forminput}
+ </div>
+
+ {if $gBitSystem->isFeatureActive( 'i18n_track_translation_usage' )}
<div class="row">
- {formlabel label="Clear Language Cache" for="clear_cache"}
+ {formlabel label="Display all strings" for="all_trans"}
{forminput}
- <input type="submit" name="clear_cache" id="clear_cache" value="{tr}Clear Cache{/tr}" />
- {formhelp note="Clear the cached language translations for all languages. It is necessary to clear the cache when you have made changes to the language database."}
+ <input type="checkbox" id="all_trans" name="all_trans" {if $allTrans}checked="checked"{/if} value="y" />
+ {formhelp note="This will display translation strings for all bitweaver versions. This means it will also show strings that are not used at all and might be useless to you."}
{/forminput}
</div>
- {/form}
- {/jstab}
- {/jstabs}
-
- {else}
+ {/if}
- {form}
- {alphabar iall=1 lang=$lang translate=1 un_trans=$unTrans all_trans=$allTrans}
+ <div class="row">
+ {formlabel label="Only Untranslated" for="un_trans"}
+ {forminput}
+ <input type="checkbox" id="un_trans" name="un_trans" />
+ {formhelp note="Display only untranslated strings when editing the language translations."}
+ {/forminput}
+ </div>
- <input type="hidden" name="lang" value="{$lang}" />
- <input type="hidden" name="char" value="{$char}" />
+ {formfeedback warning="Editing a language for the first time will cause an import of the language. this can take several minutes, depending on your configuration."}
- {if $storedStrings}
- {formfeedback success=$saveSuccess}
- <ul>
- {foreach from=$storedStrings item=string}
- <li>{$string}</li>
- {/foreach}
- </ul>
+ <div class="row submit">
+ <input type="submit" name="delete_language" value="{tr}Delete Language{/tr}" />&nbsp;
+ <input type="submit" name="edit_language" value="{tr}Edit Description{/tr}" />&nbsp;
+ <input type="submit" name="translate" value="{tr}Edit Translations{/tr}" />
+ </div>
- {legend legend="Clear Language Cache"}
- <div class="row">
- {formlabel label="Clear Language Cache" for="clear_cache"}
- {forminput}
- <input type="submit" name="clear_cache" id="clear_cache" value="{tr}Clear Cache{/tr}" />
- {formhelp note="Clear the cached language translations for all languages. It is necessary to clear the cache when you have made changes to the language database."}
- {/forminput}
- </div>
- {/legend}
- {else}
- {legend legend="Edit `$languages.$lang.full_name` Language"}
- {foreach from=$tranStrings key=sourceHash item=tran}
- {if $allTrans || (!$gBitSystem->isFeatureActive( 'i18n_track_translation_usage' ) || $tran.version)}
- <div class="row{if !$tran.version and !allTrans} warning{/if}">
- {formlabel label="Translate" for="h_$sourceHash"}
- {forminput}
- {$tran.source|escape|nl2br}<br/>
- {if $tran.textarea}
- <textarea name="edit_trans[{$sourceHash}]" id="h_{$sourceHash}" rows="5" cols="50">{$tran.trans|escape|stripslashes}</textarea>
- {else}
- <input name="edit_trans[{$sourceHash}]" id="h_{$sourceHash}" value="{$tran.trans|escape|stripslashes}" size="45" maxlength="255" />
- {/if}
- {/forminput}
- </div>
- {/if}
- {/foreach}
+ {formhelp note="
+ <dl>
+ <dt>Delete Language</dt>
+ <dd>Delete the language from your server.</dd>
+ <dt>Edit Description</dt>
+ <dd>Edit the description of the language, including language code.</dd>
+ <dt>Edit Translations</dt>
+ <dd>Edit the translated strings of the selected language.</dd>
+ </dl>
+ "}
+ {if $gBitUser->hasPermission( 'p_languages_create' )}
<div class="row submit">
- <input type="submit" name="cancel" value="{tr}Cancel{/tr}" />&nbsp;
- <input type="submit" name="save_translations" value="{tr}Save{/tr}" />
+ <input type="submit" name="new_language" value="{tr}Create New Language{/tr}" />
</div>
+ {/if}
+ {/form}
+ {/jstab}
- {alphabar iall=1 lang=$lang translate=1 un_trans=$unTrans all_trans=$allTrans}
- {/legend}
- {/if}
- {/form}
- {/if}
+ {jstab title="Language Cache"}
+ {formfeedback success=$saveSuccess}
+ {form legend="Clear Language Cache"}
+ <div class="row">
+ {formlabel label="Clear Language Cache" for="clear_cache"}
+ {forminput}
+ <input type="submit" name="clear_cache" id="clear_cache" value="{tr}Clear Cache{/tr}" />
+ {formhelp note="Clear the cached language translations for all languages. It is necessary to clear the cache when you have made changes to the language database."}
+ {/forminput}
+ </div>
+ {/form}
+ {/jstab}
+ {/jstabs}
</div><!-- end .body -->
</div><!-- end .languages -->
{/strip}
diff --git a/templates/menu_languages.tpl b/templates/menu_languages.tpl
index 20f44cb..d32bd22 100644
--- a/templates/menu_languages.tpl
+++ b/templates/menu_languages.tpl
@@ -2,6 +2,7 @@
{if $gBitUser->hasPermission( 'p_languages_edit' )}
<ul>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}edit_languages.php">{biticon iname="preferences-desktop-locale" iexplain="Edit Languages" ilocation=menu}</a></li>
+ <li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}translate_strings.php">{biticon iname="preferences-desktop-locale" iexplain="Translate Strings" ilocation=menu}</a></li>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}import.php">{biticon iname="view-refresh" iexplain="Import / Export" ilocation=menu}</a></li>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}master_strings.php">{biticon iname="text-html" iexplain="Master Strings" ilocation=menu}</a></li>
</ul>
diff --git a/templates/menu_languages_admin.tpl b/templates/menu_languages_admin.tpl
index d69d64d..c046a69 100644
--- a/templates/menu_languages_admin.tpl
+++ b/templates/menu_languages_admin.tpl
@@ -2,7 +2,8 @@
<ul>
<li><a class="item" href="{$smarty.const.KERNEL_PKG_URL}admin/index.php?page=languages">{tr}Language Settings{/tr}</a></li>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}edit_languages.php">{tr}Edit Languages{/tr}</a></li>
+ <li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}translate_strings.php">{tr}Translate Strings{/tr}</a></li>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}import.php">{tr}Import / Export{/tr}</a></li>
<li><a class="item" href="{$smarty.const.LANGUAGES_PKG_URL}master_strings.php">{tr}Master Strings{/tr}</a></li>
</ul>
-{/strip} \ No newline at end of file
+{/strip}
diff --git a/templates/translate_strings.tpl b/templates/translate_strings.tpl
new file mode 100644
index 0000000..0d43dfe
--- /dev/null
+++ b/templates/translate_strings.tpl
@@ -0,0 +1,81 @@
+{strip}
+<div class="floaticon">{bithelp}</div>
+
+<script type="text/javascript">/* <![CDATA[ */
+{literal}
+var ajax = new BitBase.SimpleAjax();
+function autoTranslate( pElementId ) {
+console.log( pElementId );
+ ajax.connect( "{/literal}{$smarty.const.LANGUAGES_PKG_URL}ajax_translate.php{literal}"
+ , "lang={/literal}{$editLang}{literal}&source_hash=" + escape( pElementId )
+ , function (r) {
+ document.getElementById( 'h_'+pElementId ).value = r.responseText;
+ }
+ , "GET"
+ );
+}
+{/literal}
+/* ]]> */</script>
+
+<div class="edit languages">
+ <div class="header">
+ <h1>{tr}Edit Languages{/tr}</h1>
+ </div>
+
+ <div class="body">
+ {form}
+ <div class="row">
+ {formlabel label="Select the language to edit" for="select_language"}
+ {forminput}
+ <select name="choose_lang" id="select_language" onchange="this.form.submit()">
+ <option value="">{tr}Select the language to edit{/tr}</option>
+ {foreach from=$languages key=langCode item=language}
+ {if $langCode != 'en'}
+ <option value="{$langCode}" {if $smarty.request.choose_lang == $langCode}selected="selected"{/if}>{$language.full_name}</option>
+ {/if}
+ {/foreach}
+ </select>
+ {/forminput}
+ </div>
+
+ {alphabar iall=1 lang=$smarty.request.lang translate=1 un_trans=$unTrans all_trans=$allTrans}
+
+ <input type="hidden" name="lang" value="{$editLang}" />
+ <input type="hidden" name="char" value="{$char}" />
+
+ {if $smarty.request.lang}
+ {legend legend="Edit `$languages.$lang.full_name` Language"}
+ {foreach from=$tranStrings key=sourceHash item=tran}
+ {if $allTrans || (!$gBitSystem->isFeatureActive( 'i18n_track_translation_usage' ) || $tran.version)}
+ <div class="row{if !$tran.version and !allTrans} warning{/if}">
+ <div class="formlabel">
+ <label for="h_{$sourceHash}">{tr}Translate{/tr}</label>
+ {if $gBitSystem->getConfig('google_api_key')}
+ <div class="autotranslate" onclick="autoTranslate('{$sourceHash}')">{biticon iname="google-favicon" ipackage="languages" iexplain="Auto-Translate"} Auto</div>
+ {/if}
+ </div>
+ {forminput}
+ {$tran.source|escape|nl2br}<br/>
+ {if $tran.textarea}
+ <textarea style="font-size:medium;width:100%" name="edit_trans[{$sourceHash}]" id="h_{$sourceHash}" rows="5" cols="50">{$tran.trans|escape|stripslashes}</textarea>
+ {else}
+ <input style="font-size:medium;width:100%" name="edit_trans[{$sourceHash}]" id="h_{$sourceHash}" value="{$tran.trans|escape|stripslashes}" size="45" maxlength="255" />
+ {/if}
+ {/forminput}
+ </div>
+ {/if}
+ {/foreach}
+
+ <div class="row submit">
+ <input type="submit" name="cancel" value="{tr}Cancel{/tr}" />&nbsp;
+ <input type="submit" name="save_translations" value="{tr}Save{/tr}" />
+ </div>
+
+ {alphabar iall=1 lang=$editLang translate=1 un_trans=$unTrans all_trans=$allTrans}
+ {/legend}
+ {/if}
+ {/form}
+ </div><!-- end .body -->
+</div><!-- end .languages -->
+{/strip}
+
diff --git a/translate_strings.php b/translate_strings.php
new file mode 100644
index 0000000..3143ba6
--- /dev/null
+++ b/translate_strings.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @package languages
+ * @subpackage functions
+ * @version $Header$
+ *
+ * Copyright (c) 2005 bitweaver.org
+ * Copyright (c) 2004-2005, Christian Fowler, et. al.
+ * All Rights Reserved. See below for details and a complete list of authors.
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
+ */
+
+/**
+ * Initialization
+ */
+require_once( '../kernel/setup_inc.php' );
+
+$gBitSystem->verifyPermission( 'p_languages_edit' );
+
+// Get available languages from DB
+$languages = $gBitLanguage->listLanguages();
+$gBitSmarty->assign_by_ref('languages', $languages);
+
+if( !empty( $_REQUEST['all_trans'] ) ) {
+ $gBitSmarty->assign( 'allTrans', 1 );
+}
+
+if( !empty( $_REQUEST['un_trans'] ) ) {
+ $gBitSmarty->assign( 'unTrans', 1 );
+}
+
+
+if( !empty( $_REQUEST['save_translations'] ) ) {
+ $editLang = $_REQUEST['lang'];
+ $gBitLanguage->loadLanguage( $editLang );
+ $storedStrings = NULL;
+ foreach( $_REQUEST['edit_trans'] as $sourceHash => $string ) {
+ if( $string != $gBitLanguage->mStrings[$editLang][$sourceHash]['trans'] ) {
+ // we need to remove the $_REQUEST slashes here to avoid stuff like:
+ // {$gBitSystem->getConfig(\'stuff\')} in the translated strings -
+ // it will kill the site since smarty won't be able to interpret
+ // the template anymore --xing
+ if( ini_get( 'magic_quotes_gpc' ) ) {
+ $string = stripslashes( $string );
+ }
+ $gBitLanguage->storeTranslationString( $editLang, $string, $sourceHash );
+ // update string in template as well
+ $tranStrings[$sourceHash]['trans'] = $string;
+ // this has to be the source, otherwise the translated string will enter the db and be recognised as a used master
+ $storedStrings[] = $gBitLanguage->mStrings[$editLang][$sourceHash]['source'];
+ }
+ }
+ $tranStrings = $gBitLanguage->getTranslationString( $sourceHash, $editLang );
+ $gBitSmarty->assign_by_ref('tranStrings', $tranStrings );
+ $gBitSmarty->assign( 'lang', $editLang );
+ $gBitSmarty->assign( 'translate', TRUE );
+ $gBitSmarty->assign( 'saveSuccess', tra( "The following items have been saved successfully" ).":" );
+ $gBitSmarty->assign( 'storedStrings', $storedStrings );
+}
+
+if( !empty( $_REQUEST['choose_lang'] ) ) {
+ $editLang = $_REQUEST['choose_lang'];
+ $gBitSmarty->assign( 'editLang', $editLang );
+ if( !empty( $_REQUEST['hash'] ) ) {
+ $tranStrings = $gBitLanguage->getTranslationString( $_REQUEST['hash'], $editLang );
+ $gBitSmarty->assign_by_ref('tranStrings', $tranStrings );
+ } else {
+ // what strings do we want to display?
+ if( empty( $_REQUEST['char'] ) ) {
+ $pattern = "/^a/i";
+ } elseif ( $_REQUEST['char'] == '0-9' ) {
+ $pattern = "/^\d/";
+ } elseif ( $_REQUEST['char'] == '+' ) {
+ $pattern = "/^[^a-zA-Z]/";
+ } elseif ( $_REQUEST['char'] == 'all' ) {
+ $pattern = "//";
+ } else {
+ $pattern = "/^".$_REQUEST['char']."/i";
+ }
+ $gBitLanguage->loadLanguage( $editLang );
+ $tranStr = $gBitLanguage->mStrings[$editLang];
+ foreach( $tranStr as $key => $tran ) {
+ // display only the wanted strings and apply a textbox if the string is too long
+ if( !empty( $_REQUEST['un_trans'] ) && empty( $tran['trans'] ) || empty( $_REQUEST['un_trans'] ) ) {
+ if( preg_match( $pattern, $tran['source'] ) ) {
+ $tranStrings[$key] = $tran;
+ if( strlen( $tran['source'] ) > 50 ) {
+ $tranStrings[$key]['textarea'] = TRUE;
+ }
+ }
+ }
+ }
+ $gBitSmarty->assign( 'char', empty( $_REQUEST['char'] ) ? '' : $_REQUEST['char'] );
+ $gBitSmarty->assign_by_ref( 'tranStrings', $tranStrings );
+ }
+}
+
+$gBitSystem->display( 'bitpackage:languages/translate_strings.tpl', tra( 'Edit Translations' ) , array( 'display_mode' => 'edit' ));
+