Merge branch 'master' of github.com:thelia/thelia

This commit is contained in:
Manuel Raynaud
2013-11-06 16:05:57 +01:00
5 changed files with 62 additions and 20 deletions

View File

@@ -54,10 +54,12 @@ class TranslationsController extends BaseAdminController
$item_id = $this->getRequest()->get('item_id', ''); $item_id = $this->getRequest()->get('item_id', '');
$all_strings = $translated_strings = array(); $all_strings = array();
$template = $directory = $i18n_directory = false; $template = $directory = $i18n_directory = false;
$mode = 'template';
if (! empty($item_id)) { if (! empty($item_id)) {
switch($item_to_translate) { switch($item_to_translate) {
@@ -66,7 +68,14 @@ class TranslationsController extends BaseAdminController
if (null !== $module = ModuleQuery::create()->findPk($item_id)) { if (null !== $module = ModuleQuery::create()->findPk($item_id)) {
$directory = THELIA_MODULE_DIR . $module->getBaseDir(); $directory = THELIA_MODULE_DIR . $module->getBaseDir();
$i18n_directory = THELIA_TEMPLATE_DIR . $template->getI18nPath(); $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; break;
case 'fo' : case 'fo' :
@@ -90,7 +99,7 @@ class TranslationsController extends BaseAdminController
if ($directory) { if ($directory) {
// Load strings // Load strings
$this->walkDir($directory, $all_strings); $this->walkDir($directory, $mode, $all_strings);
// Load translated strings // Load translated strings
if ($i18n_directory) { if ($i18n_directory) {
@@ -103,7 +112,6 @@ class TranslationsController extends BaseAdminController
'item_to_translate' => $item_to_translate, 'item_to_translate' => $item_to_translate,
'item_id' => $item_id, 'item_id' => $item_id,
'all_strings' => $all_strings, 'all_strings' => $all_strings,
'translated_strings' => $translated_strings,
'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0) 'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0)
)); ));
} }
@@ -136,7 +144,18 @@ class TranslationsController extends BaseAdminController
return $path; 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 { try {
//echo "walking in $directory<br />"; //echo "walking in $directory<br />";
@@ -144,13 +163,13 @@ class TranslationsController extends BaseAdminController
if ($fileInfo->isDot()) continue; if ($fileInfo->isDot()) continue;
if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $strings); if ($fileInfo->isDir()) $this->walkDir($fileInfo->getPathName(), $mode, $strings);
if ($fileInfo->isFile()) { if ($fileInfo->isFile()) {
$ext = $fileInfo->getExtension(); $ext = $fileInfo->getExtension();
if ($ext == 'html' || $ext == 'tpl' || $ext == 'xml') { if (in_array($ext, $allowed_exts)) {
if ($content = file_get_contents($fileInfo->getPathName())) { if ($content = file_get_contents($fileInfo->getPathName())) {
@@ -160,7 +179,7 @@ class TranslationsController extends BaseAdminController
$matches = array(); $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]); // print_r($matches[2]);
@@ -179,7 +198,9 @@ class TranslationsController extends BaseAdminController
$strings[$hash] = array( $strings[$hash] = array(
'files' => array($short_path), 'files' => array($short_path),
'chaine' => $match, '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; echo $ex;
} }
} }
} }

View File

@@ -52,7 +52,7 @@ class Translator extends BaseTranslator
* *
* @api * @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) { if (null === $locale) {
$locale = $this->getLocale(); $locale = $this->getLocale();
@@ -64,7 +64,9 @@ class Translator extends BaseTranslator
if ($this->catalogues[$locale]->has((string) $id, $domain)) if ($this->catalogues[$locale]->has((string) $id, $domain))
return parent::trans($id, $parameters, $domain, $locale); return parent::trans($id, $parameters, $domain, $locale);
else else if ($return_default_if_not_available)
return strtr($id, $parameters); return strtr($id, $parameters);
else
return '';
} }
} }

View File

@@ -26,7 +26,7 @@
<div class="row inner-toolbar"> <div class="row inner-toolbar">
<div class="col-md-12 inner-actions clearfix"> <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>
</div> </div>

View File

@@ -16,7 +16,7 @@ Parameters:
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{loop name="lang_list" type="lang"} {loop name="lang_list" type="lang"}
<li {if $ID == $edit_language_id}class="active"{/if}> <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}" /> <img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
</a> </a>
</li> </li>

View File

@@ -34,6 +34,8 @@
close_url = {url path='/admin/configuration'} close_url = {url path='/admin/configuration'}
} }
<input type="hidden" name="edit_language_id" value="{$edit_language_id}" />
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
@@ -94,7 +96,7 @@
<div class="form-group"> <div class="form-group">
<label class="control-label" for="item_id">{intl l='Select the PDF template you want to translate'}</label> <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> <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} {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> <option value="{$NAME}" {if $item_id == $NAME}selected="selected"{/if}>{$NAME}</option>
@@ -123,7 +125,9 @@
{foreach $all_strings as $hash => $info} {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 *} {* Create a liste of files names *}
@@ -172,15 +176,17 @@
<span id="{$hash}">{$info.chaine}</span> <span id="{$hash}">{$info.chaine}</span>
{if $info.dollar} {if $info.dollar}
<span class="label label-warning">{intl l='Warning'}</span> <div>
{intl l='This string contains a Smarty variable, and cannot not be translated properly'} <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} {/if}
</td> </td>
<td class="col-md-6"> <td class="col-md-6" >
<div class="input-group"> <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> <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> </div>
</td> </td>
</tr> </tr>
@@ -208,6 +214,10 @@
var translation_changed = false; var translation_changed = false;
$('#item_to_translate').change(function() {
$('#item_id').val('');
});
$('.submit-on-change').change(function() { $('.submit-on-change').change(function() {
$('#translation_form').submit(); $('#translation_form').submit();
}); });
@@ -233,6 +243,16 @@
ev.preventDefault(); 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> </script>
{/block} {/block}