Improve translation handling

This commit is contained in:
Sam Georges 2014-10-11 10:37:48 +11:00
parent fd547bb485
commit 4504d5bf4c
11 changed files with 62 additions and 39 deletions

View File

@ -107,6 +107,17 @@ class FormController extends ControllerBehavior
*/
if ($this->controller->isClassExtendedWith('Backend.Behaviors.RelationController'))
$this->controller->initRelation($model);
$this->prepareVars($model);
}
/**
* Prepares common form data
*/
protected function prepareVars($model)
{
$this->controller->vars['formModel'] = $model;
$this->controller->vars['formRecordName'] = Lang::get($this->getConfig('name', 'backend::lang.model.name'));
}
//
@ -124,9 +135,8 @@ class FormController extends ControllerBehavior
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create');
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('create[title]', 'backend::lang.form.create_title');
$model = $this->controller->formCreateModelObject();
$this->initForm($model);
$this->controller->vars['formModel'] = $model;
$this->initForm($model);
}
catch (Exception $ex) {
$this->controller->handleError($ex);
@ -176,9 +186,8 @@ class FormController extends ControllerBehavior
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', 'update');
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('update[title]', 'backend::lang.form.update_title');
$model = $this->controller->formFindModelObject($recordId);
$this->initForm($model);
$this->controller->vars['formModel'] = $model;
$this->initForm($model);
}
catch (Exception $ex) {
$this->controller->handleError($ex);
@ -250,9 +259,8 @@ class FormController extends ControllerBehavior
$this->context = strlen($context) ? $context : $this->getConfig('preview[context]', 'preview');
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('preview[title]', 'backend::lang.form.preview_title');
$model = $this->controller->formFindModelObject($recordId);
$this->initForm($model);
$this->controller->vars['formModel'] = $model;
$this->initForm($model);
}
catch (Exception $ex) {
$this->controller->handleError($ex);
@ -353,10 +361,10 @@ class FormController extends ControllerBehavior
{
$name = $this->getConfig($name, $default);
$vars = [
'name' => Lang::get($this->getConfig('name', trans('backend::lang.model.name')))
'name' => Lang::get($this->getConfig('name', 'backend::lang.model.name'))
];
$vars = array_merge($vars, $extras);
return trans($name, $vars);
return Lang::get($name, $vars);
}
//

View File

@ -163,8 +163,8 @@ return [
'select_placeholder' => 'Bitte auswählen',
'insert_row' => 'Reihe einfügen',
'delete_row' => 'Reihe löschen',
'concurrency-file-changed-title' => 'Datei wurde geändert',
'concurrency-file-changed-description' => 'Die Datei, welche Sie bearbeiten, wurde auf von einem anderen Benutzer geändert. Sie können die Datei entweder erneut laden, wodurch Ihre Änderungen verloren gehen oder Sie überschreiben die Datei auf dem Server',
'concurrency_file_changed_title' => 'Datei wurde geändert',
'concurrency_file_changed_description' => 'Die Datei, welche Sie bearbeiten, wurde auf von einem anderen Benutzer geändert. Sie können die Datei entweder erneut laden, wodurch Ihre Änderungen verloren gehen oder Sie überschreiben die Datei auf dem Server',
'reload' => 'Erneut laden',
],
'relation' => [

View File

@ -139,14 +139,18 @@ return [
'missing_model' => 'Form behavior used in :class does not have a model defined.',
'missing_definition' => "Form behavior does not contain a field for ':field'.",
'not_found' => 'Form record with an ID of :id could not be found.',
'action_confirm' => "Are you sure?",
'create' => 'Create',
'create_and_close' => 'Create and close',
'creating' => 'Creating...',
'creating_name' => 'Creating :name...',
'save' => 'Save',
'save_and_close' => 'Save and close',
'saving' => 'Saving...',
'saving_name' => 'Saving :name...',
'delete' => 'Delete',
'deleting' => 'Deleting...',
'deleting_name' => 'Deleting :name...',
'undefined_tab' => 'Misc',
'field_off' => 'Off',
'field_on' => 'On',
@ -154,6 +158,8 @@ return [
'apply' => 'Apply',
'cancel' => 'Cancel',
'close' => 'Close',
'confirm' => 'Confirm',
'reload' => 'Reload',
'ok' => 'OK',
'or' => 'or',
'confirm_tab_close' => 'Do you really want to close the tab? Unsaved changes will be lost.',
@ -165,16 +171,15 @@ return [
'select_placeholder' => 'please select',
'insert_row' => 'Insert Row',
'delete_row' => 'Delete Row',
'concurrency-file-changed-title' => 'File was changed',
'concurrency-file-changed-description' => 'The file you\'re editing has been changed on disk by another user. You can either reload the file and lose your changes or override the file on the disk.',
'reload' => 'Reload',
'concurrency_file_changed_title' => "File was changed",
'concurrency_file_changed_description' => "The file you're editing has been changed on disk by another user. You can either reload the file and lose your changes or override the file on the disk.",
],
'relation' => [
'missing_definition' => "Relation behavior does not contain a definition for ':field'.",
'missing_model' => "Relation behavior used in :class does not have a model defined.",
'invalid_action_single' => "This action cannot be performed on a singular relationship.",
'invalid_action_multi' => "This action cannot be performed on a multiple relationship.",
'help' => "Click on an item to add",
'help' => "Click on an item to add",
'related_data' => "Related :name data",
'add' => "Add",
'add_selected' => "Add selected",

View File

@ -165,8 +165,8 @@ return [
'select_placeholder' => 'لطفا انتخاب نمایید',
'insert_row' => 'افزودن سطر',
'delete_row' => 'حذف سطر',
'concurrency-file-changed-title' => 'فایل تغییر کرد',
'concurrency-file-changed-description' => 'فایلی که شما ویرایش کردید توسط کاربر دیگری تغییر یافته و ذخیره شده است. شما میتوانید فایل را مجددا بارگذاری نمایید و تغییراتی که اعمال کرده اید را از دست بدهید و یا تغییرات اعمال شده توسط آن کاربر را بین برده و فایل را بازنویسی نمایید.',
'concurrency_file_changed_title' => 'فایل تغییر کرد',
'concurrency_file_changed_description' => 'فایلی که شما ویرایش کردید توسط کاربر دیگری تغییر یافته و ذخیره شده است. شما میتوانید فایل را مجددا بارگذاری نمایید و تغییراتی که اعمال کرده اید را از دست بدهید و یا تغییرات اعمال شده توسط آن کاربر را بین برده و فایل را بازنویسی نمایید.',
'reload' => 'بارگذاری مجدد',
],
'relation' => [

View File

@ -1,8 +1,8 @@
<?php namespace Backend\Traits;
use Request;
use System\Classes\SystemException;
use System\Classes\ApplicationException;
use Request;
/**
* Inspectable Container Trait

View File

@ -218,7 +218,7 @@ class Form extends WidgetBase
}
/**
* Prepares the list data
* Prepares the form data
*/
protected function prepareVars()
{

View File

@ -45,10 +45,17 @@ class ComponentHelpers
/*
* Translate human values
*/
$translate = ['title', 'description'];
$translate = ['title', 'description', 'options'];
foreach ($property as $name => $value) {
if (!in_array($name, $translate)) continue;
$property[$name] = Lang::get($value);
if (!in_array($name, $translate))
continue;
if (is_array($value)) {
array_walk($property[$name], function(&$_value, $key) { $_value = Lang::get($_value); });
}
else {
$property[$name] = Lang::get($value);
}
}
$result[] = $property;

View File

@ -44,12 +44,16 @@ class Components extends FormWidgetBase
$componentObj->alias = $alias;
$componentObj->pluginIcon = 'icon-puzzle-piece';
/*
* Look up the plugin hosting this component
*/
$plugin = $manager->findComponentPlugin($componentObj);
if ($plugin) {
$pluginDetails = $plugin->pluginDetails();
if (isset($pluginDetails['icon']))
$componentObj->pluginIcon = $pluginDetails['icon'];
}
}
catch (Exception $ex) {
$componentObj = new UnknownComponent(null, $properties, $ex->getMessage());

View File

@ -9,9 +9,9 @@
<span class="name"><?= $name ?></span>
<span class="description"><?= $description ?></span>
<span class="alias oc-icon-code"><?= e($component->alias) ?></span>
<input type="hidden" name="component_properties[]" data-inspector-values value="<?= e($this->getComponentPropertyValues($component)) ?>"/>
<input type="hidden" name="component_names[]" value="<?= e($component->name) ?>"></input>
<input type="hidden" name="component_aliases[]" value="<?= e($component->alias) ?>"></input>
<input type="hidden" name="component_properties[]" data-inspector-values value="<?= e($this->getComponentPropertyValues($component)) ?>" />
<input type="hidden" name="component_names[]" value="<?= e($component->name) ?>" />
<input type="hidden" name="component_aliases[]" value="<?= e($component->alias) ?>" />
<a href="#" class="remove">&times;</a>
</div>
</div>

View File

@ -1,18 +1,17 @@
<div class="control-componentlist">
<?php
foreach ($components as $component) {
if ($component->isHidden)
echo $this->makePartial('component', ['component'=>$component]);
}
?>
<?php foreach ($components as $component): ?>
<?php if ($component->isHidden): ?>
<?= $this->makePartial('component', ['component' => $component]) ?>
<?php endif ?>
<?php endforeach ?>
<div class="components" data-control="toolbar">
<div class="layout">
<?php
foreach ($components as $component) {
if (!$component->isHidden)
echo $this->makePartial('component', ['component'=>$component]);
}
?>
<?php foreach ($components as $component): ?>
<?php if (!$component->isHidden): ?>
<?= $this->makePartial('component', ['component' => $component]) ?>
<?php endif ?>
<?php endforeach ?>
</div>
</div>
</div>