Skip to content

Commit

Permalink
Merge pull request #2324 from luischavez/master
Browse files Browse the repository at this point in the history
added the option to translate the menu from the language files, updated docs
  • Loading branch information
z-song authored Aug 22, 2018
2 parents 45b91dd + 11c034b commit 66f0e1d
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 3 deletions.
16 changes: 16 additions & 0 deletions docs/en/model-form-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ $form->select('user_id')->options(function ($id) {
return [$user->id => $user->name];
}
})->ajax('/admin/api/users');

// using ajax and show selected item:

$form->select('user_id')->options(User::class)->ajax('/admin/api/users');

// or specifying the name and id

$form->select('user_id')->options(User::class, 'name', 'id')->ajax('/admin/api/users');
```

<sub>Notice:if you have modified the value of the `route.prefix` in the `config/admin.php` file, this api route should be modified to `config('admin.route.prefix').'/api/users'`.</sub>
Expand Down Expand Up @@ -171,6 +179,14 @@ public function city(Request $request)
## Multiple select
```php
$form->multipleSelect($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);

// using ajax and show selected items:

$form->multipleSelect($column[, $label])->options(Model::class)->ajax('ajax_url');

// or specifying the name and id

$form->multipleSelect($column[, $label])->options(Model::class, 'name', 'id')->ajax('ajax_url');
```

You can store value of multiple select in two ways, one is `many-to-many` relation.
Expand Down
14 changes: 14 additions & 0 deletions docs/en/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ Open `http://localhost:8000/admin/auth/menu`, add menu link and refresh the page

> Where `uri` fills in the path part that does not contain the prefix of the route, such as the full path `http://localhost:8000/admin/demo/users`, just input `demo/users`, If you want to add an external link, just fill in the full url, such as `http://laravel-admin.org/`.
### Menu translations

append menu titles in menu_titles index at your language files.
For example 'Work Units' title:

in resources/lang/es/admin.php
```php
...
// lowercase and replace spaces with _
'menu_titles' => [
'work_units' => 'Unidades de trabajo'
],
```

## Build grid and form

The rest needs to be done is open `app/Admin/Contollers/UserController.php`, find `form()` and `grid()` method and write few lines of code with `model-grid` and `model-form`,for more detail, please read [model-grid](/en/model-grid.md) and [model-form](/en/model-form.md).
16 changes: 16 additions & 0 deletions docs/zh/model-form-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ $form->select($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Opt
或者从api中获取选项列表:
```php
$form->select($column[, $label])->options('/api/users');

// 使用ajax并显示所选项目

$form->select($column[, $label])->options(Model::class)->ajax('/api/users');

// 或指定名称和ID

$form->select($column[, $label])->options(Model::class, 'name', 'id')->ajax('/api/users');
```
其中api接口的格式必须为下面格式:
```php
Expand Down Expand Up @@ -190,6 +198,14 @@ public function city(Request $request)

```php
$form->multipleSelect($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);

// 使用ajax并显示所选项目:

$form->multipleSelect($column[, $label])->options(Model::class)->ajax('ajax_url');

// 或指定名称和ID

$form->multipleSelect($column[, $label])->options(Model::class, 'name', 'id')->ajax('ajax_url');
```

多选框可以处理两种情况,第一种是`ManyToMany`的关系。
Expand Down
14 changes: 14 additions & 0 deletions docs/zh/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ $router->resource('users', UserController::class);

> 其中`uri`填写不包含路由前缀的的路径部分,比如完整路径是`http://localhost:8000/admin/demo/users`, 那么就填`demo/users`,如果要添加外部链接,只要填写完整的url即可,比如`http://laravel-admin.org/`.
### 菜单翻译

在您的语言文件的menu_titles索引中追加菜单标题。
例如“工作单位”标题:

在resources/lang/es/admin.php中
```php
...
// 用_小写并用_替换空格
'menu_titles' => [
'work_units' => 'Unidades de trabajo'
],
```

## 创建表格表单

剩下的工作就是构建数据表格和表单了,打开 `app/Admin/Contollers/UserController.php`,找到`form()``grid()`方法,然添加构建代码更多详细使用请查看[model-grid](/zh/model-grid.md)[model-form](/zh/model-form.md)
2 changes: 2 additions & 0 deletions resources/lang/ar/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
'filter_clear' => 'عرض الكل',
'filter_placeholder' => 'تنقية',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@
'filter_clear' => 'Show all',
'filter_placeholder' => 'Filter',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/es/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@
'all' => 'Todas',
'current_page' => 'Página actual',
'selected_rows' => 'Filas seleccionadas',

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/fa/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
'filter_clear' => 'نمایش همه',
'filter_placeholder' => 'فیلتر کردن',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/fr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
'filter_clear' => 'Affichez tous',
'filter_placeholder' => 'Filtre',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/he/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@
'pagination' => [
'range' => ':last מ :total תוצאות',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/ja/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
'filter_clear' => '全て表示',
'filter_placeholder' => 'フィルタ',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/nl/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
'filter_clear' => 'Toon alle',
'filter_placeholder' => 'Filter',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/pl/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@
'pagination' => [
'range' => 'Wyświetlono :first do :last z wszystkich :total',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/pt-BR/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@
'filter_clear' => 'Mostrar tudo',
'filter_placeholder' => 'Filtrar',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/pt/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@
'filter_clear' => 'Mostrar tudo',
'filter_placeholder' => 'Filtrar',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/ru/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@
'pagination' => [
'range' => 'Записи с :first по :last из :total',
],

'menu_titles' => [],
];
2 changes: 2 additions & 0 deletions resources/lang/tr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@
'filter_clear' => 'Tümümnü göster',
'filter_placeholder' => 'Filtrele',
],

'menu_titles' => [],
];
1 change: 1 addition & 0 deletions resources/lang/zh-CN/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@
'filter_clear' => '显示全部',
'filter_placeholder' => '过滤',
],
'menu_titles' => [],
];
1 change: 1 addition & 0 deletions resources/lang/zh-TW/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@
'filter_clear' => '顯示全部',
'filter_placeholder' => '過濾',
],
'menu_titles' => [],
];
10 changes: 7 additions & 3 deletions resources/views/partials/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
<a href="{{ admin_base_path($item['uri']) }}">
@endif
<i class="fa {{$item['icon']}}"></i>
<span>{{$item['title']}}</span>
@if (Lang::has($titleTranslation = 'admin.menu_titles.' . trim(str_replace(' ', '_', strtolower($item['title'])))))
<span>{{ __($titleTranslation) }}</span>
@else
<span>{{ $item['title'] }}</span>
@endif
</a>
</li>
@else
<li class="treeview">
<a href="#">
<i class="fa {{$item['icon']}}"></i>
<span>{{$item['title']}}</span>
<i class="fa {{ $item['icon'] }}"></i>
<span>{{ $item['title'] }}</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
Expand Down

0 comments on commit 66f0e1d

Please sign in to comment.