Continued on translations
This commit is contained in:
@@ -54,10 +54,12 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
$item_id = $this->getRequest()->get('item_id', '');
|
||||
|
||||
$all_strings = $translated_strings = array();
|
||||
$all_strings = array();
|
||||
|
||||
$template = $directory = $i18n_directory = false;
|
||||
|
||||
$mode = 'template';
|
||||
|
||||
if (! empty($item_id)) {
|
||||
|
||||
switch($item_to_translate) {
|
||||
@@ -66,7 +68,14 @@ class TranslationsController extends BaseAdminController
|
||||
if (null !== $module = ModuleQuery::create()->findPk($item_id)) {
|
||||
$directory = THELIA_MODULE_DIR . $module->getBaseDir();
|
||||
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath();
|
||||
$mode = 'php';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'co' :
|
||||
$directory = THELIA_ROOT . 'core/lib/Thelia';
|
||||
$i18n_directory = THELIA_ROOT . 'core/lib/Thelia/Config/I18n';
|
||||
$mode = 'php';
|
||||
break;
|
||||
|
||||
case 'fo' :
|
||||
@@ -90,7 +99,7 @@ class TranslationsController extends BaseAdminController
|
||||
if ($directory) {
|
||||
|
||||
// Load strings
|
||||
$this->walkDir($directory, $all_strings);
|
||||
$this->walkDir($directory, $mode, $all_strings);
|
||||
|
||||
// Load translated strings
|
||||
if ($i18n_directory) {
|
||||
@@ -103,7 +112,6 @@ class TranslationsController extends BaseAdminController
|
||||
'item_to_translate' => $item_to_translate,
|
||||
'item_id' => $item_id,
|
||||
'all_strings' => $all_strings,
|
||||
'translated_strings' => $translated_strings,
|
||||
'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0)
|
||||
));
|
||||
}
|
||||
@@ -136,7 +144,18 @@ class TranslationsController extends BaseAdminController
|
||||
return $path;
|
||||
}
|
||||
|
||||
protected function walkDir($directory, &$strings) {
|
||||
protected function walkDir($directory, $mode, &$strings) {
|
||||
|
||||
if ($mode == 'php') {
|
||||
$prefix = '\-\>[\s]*trans[\s]*\(';
|
||||
|
||||
$allowed_exts = array('php');
|
||||
} else {
|
||||
$prefix = '\{intl[\s]l=';
|
||||
|
||||
$allowed_exts = array('html', 'tpl', 'xml');
|
||||
}
|
||||
|
||||
try {
|
||||
//echo "walking in $directory<br />";
|
||||
|
||||
@@ -144,13 +163,13 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
if ($fileInfo->isDot()) continue;
|
||||
|
||||
if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $strings);
|
||||
if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $mode, $strings);
|
||||
|
||||
if ($fileInfo->isFile()) {
|
||||
|
||||
$ext = $fileInfo->getExtension();
|
||||
|
||||
if ($ext == 'html' || $ext == 'tpl' || $ext == 'xml') {
|
||||
if (in_array($ext, $allowed_exts)) {
|
||||
|
||||
if ($content = file_get_contents($fileInfo->getPathName())) {
|
||||
|
||||
@@ -160,7 +179,7 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
$matches = array();
|
||||
|
||||
if (preg_match_all('/{intl[\s]l=((?<![\\\\])[\'"])((?:.(?!(?<![\\\\])\1))*.?)\1/', $content, $matches)) {
|
||||
if (preg_match_all('/'.$prefix.'((?<![\\\\])[\'"])((?:.(?!(?<![\\\\])\1))*.?)\1/', $content, $matches)) {
|
||||
|
||||
// print_r($matches[2]);
|
||||
|
||||
@@ -179,7 +198,9 @@ class TranslationsController extends BaseAdminController
|
||||
$strings[$hash] = array(
|
||||
'files' => array($short_path),
|
||||
'chaine' => $match,
|
||||
'dollar' => strstr($match, '$') !== false);
|
||||
'translation' => $this->getTranslator()->trans($match, array(), 'messages', $this->getCurrentEditionLocale(), false),
|
||||
'dollar' => strstr($match, '$') !== false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,5 +211,4 @@ class TranslationsController extends BaseAdminController
|
||||
echo $ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class Translator extends BaseTranslator
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
|
||||
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null, $return_default_if_not_available = true)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
@@ -64,7 +64,9 @@ class Translator extends BaseTranslator
|
||||
|
||||
if ($this->catalogues[$locale]->has((string) $id, $domain))
|
||||
return parent::trans($id, $parameters, $domain, $locale);
|
||||
else
|
||||
else if ($return_default_if_not_available)
|
||||
return strtr($id, $parameters);
|
||||
else
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
<div class="row inner-toolbar">
|
||||
<div class="col-md-12 inner-actions clearfix">
|
||||
<button type="button" class="btn btn-default btn-success pull-right js-show-logs" title="{intl l='Show \'logs'}">{intl l='Show logs'} <span class="glyphicon glyphicon-eye-open"></span></button>
|
||||
<button type="button" class="btn btn-default btn-success pull-right js-show-logs" title="{intl l='Show logs'}">{intl l='Show logs'} <span class="glyphicon glyphicon-eye-open"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ Parameters:
|
||||
<ul class="nav nav-pills">
|
||||
{loop name="lang_list" type="lang"}
|
||||
<li {if $ID == $edit_language_id}class="active"{/if}>
|
||||
<a href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l='Edit information in %lng' lng=$TITLE}">
|
||||
<a class="language-change-button" data-language-id="{$ID}" href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l='Edit information in %lng' lng=$TITLE}">
|
||||
<img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
close_url = {url path='/admin/configuration'}
|
||||
}
|
||||
|
||||
<input type="hidden" name="edit_language_id" value="{$edit_language_id}" />
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
@@ -94,7 +96,7 @@
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="item_id">{intl l='Select the PDF template you want to translate'}</label>
|
||||
|
||||
<select id="pdf_template" required="required" name="item_id" class="submit-on-change form-control">
|
||||
<select id="item_id" required="required" name="item_id" class="submit-on-change form-control">
|
||||
<option value="">{intl l='Please select the PDF template to translate'}</option>
|
||||
{loop type="template" name="translate-pdf-template" template-type="pdf" backend_context=1}
|
||||
<option value="{$NAME}" {if $item_id == $NAME}selected="selected"{/if}>{$NAME}</option>
|
||||
@@ -123,7 +125,9 @@
|
||||
|
||||
{foreach $all_strings as $hash => $info}
|
||||
|
||||
{if $view_missing_traductions_only != 1 || ! isset($translated_strings[$info.chaine]) || $translated_strings[$info.chaine]== ''}
|
||||
{$not_translated = empty($info.translation)}
|
||||
|
||||
{if $view_missing_traductions_only != 1 || $not_translated }
|
||||
|
||||
{* Create a liste of files names *}
|
||||
|
||||
@@ -172,15 +176,17 @@
|
||||
<span id="{$hash}">{$info.chaine}</span>
|
||||
|
||||
{if $info.dollar}
|
||||
<span class="label label-warning">{intl l='Warning'}</span>
|
||||
{intl l='This string contains a Smarty variable, and cannot not be translated properly'}
|
||||
<div>
|
||||
<span class="label label-warning">{intl l='Warning'}</span>
|
||||
{intl l='Il seems that this string contains a Smarty variable ($). If \'s the case, it cannot be transleted properly.'}
|
||||
</div>
|
||||
{/if}
|
||||
</td>
|
||||
|
||||
<td class="col-md-6">
|
||||
<div class="input-group">
|
||||
<td class="col-md-6" >
|
||||
<div class="input-group {if $not_translated}has-error{/if}">
|
||||
<span class="input-group-addon"><a href="#" data-hash="{$hash}" class="copy-translation" title="{intl l='Copy source text in input field'}"><span class="glyphicon glyphicon-chevron-right"></span></a></span>
|
||||
<input type="text" class="translation_field form-control" name="{$hash}" value="{$translated_strings[$info.chaine]}" />
|
||||
<input type="text" class="translation_field form-control" name="{$hash}" value="{$info.translation}" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -208,6 +214,10 @@
|
||||
|
||||
var translation_changed = false;
|
||||
|
||||
$('#item_to_translate').change(function() {
|
||||
$('#item_id').val('');
|
||||
});
|
||||
|
||||
$('.submit-on-change').change(function() {
|
||||
$('#translation_form').submit();
|
||||
});
|
||||
@@ -233,6 +243,16 @@
|
||||
ev.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// Intercept language changes, to reload string when changing language
|
||||
$('.language-change-button').click(function(ev) {
|
||||
|
||||
$('input[name=edit_language_id]').val($(this).data('language-id'));
|
||||
|
||||
$('#translation_form').submit();
|
||||
|
||||
ev.preventDefault();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{/block}
|
||||
|
||||
Reference in New Issue
Block a user