Skip to content
Open

I18n #58

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
"psr-4": {
"Laralib\\L5scaffold\\": "src/"
}
},
"scripts": {
"post-update-cmd": [
"php -r \"copy('src/stubs/i18n/en.stub', '../../../resources/lang/en/l5scaffold.php');\""
]
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ php artisan make:scaffold Tweet --prefix="admin"
![image](http://i65.tinypic.com/afehl5.jpg)


## Internationalization (I18l)

After instalation/update through Composer a new file with default labels in english called `l5scaffold.php` will be placed at language resources app folder `resources/lang/en`.

To change the labels of your app, you just need to add a new language file called `l5scaffold.php` into `resources/lang/YOUR_APP_LANGUAGE`.
And then configure your app Location acording to the docs of [Laravel Localization](https://laravel.com/docs/5.2/localization) component.

# Todo task list
1 - Validations
Expand Down
6 changes: 3 additions & 3 deletions src/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class {{class}} extends Controller {

${{model_name_var_sgl}}->save();

return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item created successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', trans('l5scaffold.item_created'));
}

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ class {{class}} extends Controller {

${{model_name_var_sgl}}->save();

return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item updated successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', trans('l5scaffold.item_updated'));
}

/**
Expand All @@ -102,7 +102,7 @@ class {{class}} extends Controller {
${{model_name_var_sgl}} = {{model_name_class}}::findOrFail($id);
${{model_name_var_sgl}}->delete();

return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', 'Item deleted successfully.');
return redirect()->route('{{prefix}}{{model_name_var}}.index')->with('message', trans('l5scaffold.item_deleted'));
}

}
6 changes: 3 additions & 3 deletions src/stubs/html_assets/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@endsection
@section('header')
<div class="page-header">
<h1><i class="glyphicon glyphicon-plus"></i> {{Class}} / Create </h1>
<h1><i class="glyphicon glyphicon-plus"></i> {{Class}} / @lang('l5scaffold.create') </h1>
</div>
@endsection

Expand All @@ -19,8 +19,8 @@

{{content_fields}}
<div class="well well-sm">
<button type="submit" class="btn btn-primary">Create</button>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<button type="submit" class="btn btn-primary">@lang('l5scaffold.create')</button>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> @lang('l5scaffold.back')</a>
</div>
</form>

Expand Down
6 changes: 3 additions & 3 deletions src/stubs/html_assets/edit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@endsection
@section('header')
<div class="page-header">
<h1><i class="glyphicon glyphicon-edit"></i> {{Class}} / Edit #{{${{classSingle}}->id}}</h1>
<h1><i class="glyphicon glyphicon-edit"></i> {{Class}} / @lang('l5scaffold.edit') #{{${{classSingle}}->id}}</h1>
</div>
@endsection

Expand All @@ -20,8 +20,8 @@

{{content_fields}}
<div class="well well-sm">
<button type="submit" class="btn btn-primary">Save</button>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<button type="submit" class="btn btn-primary">@lang('l5scaffold.save')</button>
<a class="btn btn-link pull-right" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> @lang('l5scaffold.back')</a>
</div>
</form>

Expand Down
2 changes: 1 addition & 1 deletion src/stubs/html_assets/error.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if (count($errors) > 0)
<div class="alert alert-danger">
<p>There were some problems with your input.</p>
<p>@lang('l5scaffold.input_errors')</p>
<ul>
@foreach ($errors->all() as $error)
<li><i class="glyphicon glyphicon-remove"></i> {{ $error }}</li>
Expand Down
12 changes: 6 additions & 6 deletions src/stubs/html_assets/index.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="page-header clearfix">
<h1>
<i class="glyphicon glyphicon-align-justify"></i> {{Class}}
<a class="btn btn-success pull-right" href="{{ route('{{prefix}}{{class}}.create') }}"><i class="glyphicon glyphicon-plus"></i> Create</a>
<a class="btn btn-success pull-right" href="{{ route('{{prefix}}{{class}}.create') }}"><i class="glyphicon glyphicon-plus"></i> @lang('l5scaffold.create')</a>
</h1>

</div>
Expand All @@ -19,7 +19,7 @@
<tr>
<th>ID</th>
{{header_fields}}
<th class="text-right">OPTIONS</th>
<th class="text-right">@lang('l5scaffold.options')</th>
</tr>
</thead>

Expand All @@ -29,12 +29,12 @@
<td>{{${{classSingle}}->id}}</td>
{{content_fields}}
<td class="text-right">
<a class="btn btn-xs btn-primary" href="{{ route('{{prefix}}{{class}}.show', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-eye-open"></i> View</a>
<a class="btn btn-xs btn-warning" href="{{ route('{{prefix}}{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<a class="btn btn-xs btn-primary" href="{{ route('{{prefix}}{{class}}.show', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-eye-open"></i> @lang('l5scaffold.view')</a>
<a class="btn btn-xs btn-warning" href="{{ route('{{prefix}}{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> @lang('l5scaffold.edit')</a>
<form action="{{ route('{{prefix}}{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-trash"></i> Delete</button>
<button type="submit" class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-trash"></i> @lang('l5scaffold.delete')</button>
</form>
</td>
</tr>
Expand All @@ -43,7 +43,7 @@
</table>
{!! ${{class}}->render() !!}
@else
<h3 class="text-center alert alert-info">Empty!</h3>
<h3 class="text-center alert alert-info">@lang('l5scaffold.empty')!</h3>
@endif

</div>
Expand Down
8 changes: 4 additions & 4 deletions src/stubs/html_assets/show.stub
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@extends('layout')
@section('header')
<div class="page-header">
<h1>{{Class}} / Show #{{${{classSingle}}->id}}</h1>
<h1>{{Class}} / @lang('l5scaffold.show') #{{${{classSingle}}->id}}</h1>
<form action="{{ route('{{prefix}}{{class}}.destroy', ${{classSingle}}->id) }}" method="POST" style="display: inline;" onsubmit="if(confirm('Delete? Are you sure?')) { return true } else {return false };">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="btn-group pull-right" role="group" aria-label="...">
<a class="btn btn-warning btn-group" role="group" href="{{ route('{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> Edit</a>
<button type="submit" class="btn btn-danger">Delete <i class="glyphicon glyphicon-trash"></i></button>
<a class="btn btn-warning btn-group" role="group" href="{{ route('{{class}}.edit', ${{classSingle}}->id) }}"><i class="glyphicon glyphicon-edit"></i> @lang('l5scaffold.edit')</a>
<button type="submit" class="btn btn-danger">@lang('l5scaffold.delete') <i class="glyphicon glyphicon-trash"></i></button>
</div>
</form>
</div>
Expand All @@ -25,7 +25,7 @@
{{content_fields}}
</form>

<a class="btn btn-link" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> Back</a>
<a class="btn btn-link" href="{{ route('{{prefix}}{{class}}.index') }}"><i class="glyphicon glyphicon-backward"></i> @lang('l5scaffold.back')</a>

</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions src/stubs/i18n/en.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
return [
'create' => 'Create',
'edit' => 'Edit',
'save' => 'Save',
'input_errors' => 'There were some problems with your input.',
'options' => 'OPTIONS',
'view' => 'View',
'empty' => 'No records.',
'id' => 'ID',
'delete' => 'Delete',
'delete_confirmation' => 'Delete? Are you sure?',
'back' => 'Back',
'item_created' => 'Item created successfully.',
'item_updated' => 'Item updated successfully.',
'item_deleted' => 'Item deleted successfully.',
];