Skip to content

Commit 22a6694

Browse files
committed
3.0.0
1 parent da9aab4 commit 22a6694

20 files changed

+1311
-440
lines changed

config/translation-manager.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
'route' => [
1414
'prefix' => 'translations',
15+
'namespace' => 'HighSolutions\TranslationManager',
1516
'middleware' => [
1617
'web',
1718
'auth',
@@ -44,4 +45,26 @@
4445
*/
4546
'sort_keys ' => false,
4647

48+
/**
49+
* Highlight lines with locale marked (e.g. EN at the end of text)
50+
*/
51+
'highlight_locale_marked' => false,
52+
53+
/**
54+
* Enable live translation of content.
55+
*/
56+
'live_translation_enabled' => false,
57+
58+
/**
59+
* Define who and when can manage module.
60+
*
61+
* @return bool
62+
*/
63+
'permissions' => function () {
64+
if(env('APP_ENV') == 'local')
65+
return true;
66+
67+
return false;
68+
},
69+
4770
);

intro.jpg

103 KB
Loading

readme.md

Lines changed: 166 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,107 @@
11
Laravel Translation Manager
22
=============================
33

4-
This is a package to manage Laravel translation files.
5-
It does not replace the Translation system, only import/export the php files to a database and make them editable through a webinterface.
6-
The workflow would be:
4+
Easy management of translations in Laravel.
75

8-
- Import translations: Read all translation files and save them in the database
9-
- Find all translations in php/twig sources
10-
- Optionally: Listen to missing translation with the custom Translator
11-
- Translate all keys through the webinterface
12-
- Export: Write all translations back to the translation files.
6+
![Laravel-Translation-Manager by HighSolutions](https://raw.githubusercontent.com/highsolutions/laravel-translations-manager/master/intro.jpg)
137

14-
This way, translations can be saved in git history and no overhead is introduced in production.
8+
Installation
9+
------------
1510

16-
![Screenshot](http://i.imgur.com/4th2krf.png)
17-
18-
## Installation
19-
20-
Require this package in your composer.json and run composer update (or run `composer require highsolutions/laravel-translation-manager` directly):
11+
Add the following line to the `require` section of your Laravel webapp's `composer.json` file:
2112

2213
```javascript
23-
"highsolutions/laravel-translation-manager": "0.3.x"
14+
"require": {
15+
"highsolutions/laravel-translation-manager": "0.3.x"
16+
}
2417
```
2518

26-
After updating composer, add the ServiceProvider to the providers array in config/app.php
19+
Run `composer update` to install the package.
20+
21+
Then, update `config/app.php` by adding an entry for the service provider:
2722

2823
```php
24+
'providers' => [
2925
// ...
3026
HighSolutions\TranslationManager\ManagerServiceProvider::class,
27+
];
3128
```
3229

33-
You need to run the migrations for this package.
30+
Next, publish all package resources:
3431

3532
```bash
36-
php artisan vendor:publish --provider="HighSolutions\TranslationManager\ManagerServiceProvider" --tag=migrations
37-
php artisan migrate
33+
php artisan vendor:publish --provider="HighSolutions\TranslationManager\ManagerServiceProvider"
3834
```
3935

40-
You need to publish the config file for this package. This will add the file `config/translation-manager.php`, where you can configure this package.
36+
This will add to your project:
37+
38+
- migration - database table for storing translations
39+
- configuration - package configurations
40+
- views - configurable views for translation management
41+
- translations - translations for webinterface
42+
43+
Remember to launch migration:
4144

4245
```bash
43-
php artisan vendor:publish --provider="HighSolutions\TranslationManager\ManagerServiceProvider" --tag=config
46+
php artisan migrate
4447
```
4548

46-
In order to edit the default template, the views must be published as well. The views will then be placed in `resources/views/vendor/translation-manager`.
49+
Moreover, you have to disable `ONLY_FULL_GROUP_ID` strict mode for database connection. There are two ways:
4750

48-
```bash
49-
php artisan vendor:publish --provider="HighSolutions\TranslationManager\ManagerServiceProvider" --tag=views
51+
```php
52+
'mysql' => [
53+
// ...
54+
'strict' => false,
55+
],
5056
```
5157

52-
Routes are added in the ServiceProvider. You can set the group parameters for the routes in the configuration.
53-
You can change the prefix or filter/middleware for the routes. If you want full customisation, you can extend the ServiceProvider and override the `map()` function.
58+
or
59+
60+
```php
61+
'mysql' => [
62+
// ...
63+
'modes' => [
64+
'NO_ZERO_DATE',
65+
// you can specify what you want, without ONLY_FULL_GROUP_ID
66+
],
67+
],
68+
```
69+
70+
Workflow
71+
------------
72+
73+
This package doesn't replace the Translation system, only import/export PHP files to a database and make them editable in browser.
74+
Package contains helper for live editing content on website.
75+
76+
The workflow would be:
5477

55-
This example will make the translation manager available at `http://yourdomain.com/translations`
78+
- Import translations: Read all translation files and save them in the database
79+
- Find all translations in php/twig sources
80+
- Optionally: Listen to missing translation with the custom Translator
81+
- Translate all keys through the webinterface
82+
- Export: Write all translations back to the translation files.
5683

5784
Usage
5885
------
5986

60-
### Web interface
87+
You can access package in `http://yourdomain.com/translations` in default configuration. You can change as you pleased.
6188

62-
When you have imported your translation (via buttons or command), you can view them in the webinterface (on the url you defined with the controller).
63-
You can click on a translation and an edit field will popup. Just click save and it is saved :)
64-
When a translation is not yet created in a different locale, you can also just edit it to create it.
89+
Configuration
90+
-------------
6591

66-
Using the buttons on the webinterface, you can import/export the translations. For publishing translations, make sure your application can write to the language directory.
92+
| Setting name | Description | Default value |
93+
|--------------------------|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
94+
| route | Route declaration (prefix, namespace, middlewares etc.) | [,'prefix' => 'translations', 'namespace' => 'HighSolutions\TranslationManager', 'middleware' => [,'web', 'auth',],] |
95+
| delete_enabled | Enable deletion of translations | true |
96+
| exclude_groups | Exclude specific file groups (like validation, pagination, routes etc.) | [] |
97+
| sort_keys | Export translations with keys output alphabetically. | false |
98+
| highlight_locale_marked | Highlight lines with locale marked as not translated. | false |
99+
| live_translation_enabled | Enable live translation of content. | false |
100+
| permissions | Define whow and when can edit translations. | function () {return env('APP_ENV') == 'local'; } |
67101

68-
You can also use the commands below.
102+
103+
Commands
104+
---------
69105

70106
### Import command
71107

@@ -85,35 +121,36 @@ The found keys will be added to the database, so they can be easily translated.
85121
This can be done through the webinterface, or via an Artisan command.
86122

87123
```bash
88-
$ php artisan translations:find
124+
php artisan translations:find
89125
```
90126

91127
### Export command
92128

93-
The export command will write the contents of the database back to app/lang php files.
129+
The export command will write the contents of the database back to resources/lang php files.
94130
This will overwrite existing translations and remove all comments, so make sure to backup your data before using.
95131
Supply the group name to define which groups you want to publish.
132+
If you want to export all groups, provide `*` as name of group.
96133

97134
```bash
98-
$ php artisan translations:export <group>
135+
php artisan translations:export <group>
99136
```
100137

101-
For example, `php artisan translations:export reminders` when you have 2 locales (en/nl), will write to `app/lang/en/reminders.php` and `app/lang/nl/reminders.php`
138+
For example, `php artisan translations:export reminders` when you have 2 locales (en/pl), will write to `resources/lang/en/reminders.php` and `resources/lang/pl/reminders.php`
102139

103140
### Clean command
104141

105142
The clean command will search for all translation that are NULL and delete them, so your interface is a bit cleaner. Note: empty translations are never exported.
106143

107144
```bash
108-
$ php artisan translations:clean
145+
php artisan translations:clean
109146
```
110147

111148
### Reset command
112149

113150
The reset command simply clears all translation in the database, so you can start fresh (by a new import). Make sure to export your work if needed before doing this.
114151

115152
```bash
116-
$ php artisan translations:reset
153+
php artisan translations:reset
117154
```
118155

119156
### Detect missing translations
@@ -131,12 +168,98 @@ This will extend the Translator and will create a new database entry, whenever a
131168
This way it shows up in the webinterface and can be edited and later exported.
132169
You shouldn't use this in production, just in production to translate your views, then just switch back.
133170

171+
Live editing
172+
---------
173+
174+
When you have translations in database, you can use `transEditable` method instead of `trans` whenever it's suitable. To do this, you have to make few steps:
175+
176+
Update `config/app.php` by adding an entry for the service provider (another one):
177+
178+
```php
179+
'providers' => [
180+
// ...
181+
HighSolutions\TranslationManager\TranslationServiceProvider::class,
182+
];
183+
```
184+
185+
Add these two methods to `app\helpers.php` file.
186+
187+
```php
188+
if (!function_exists('transEditable')) {
189+
/**
190+
* Translate the given message and wraps it in .editable container to allow editing
191+
*
192+
* @param string $id
193+
* @param array $parameters
194+
* @param string $domain
195+
* @param string $locale
196+
* @return \Symfony\Component\Translation\TranslatorInterface|string
197+
*/
198+
function transEditable($id = null, $parameters = [], $domain = 'messages', $locale = null) {
199+
return app('translator')->transEditable($id, $parameters, $locale);
200+
}
201+
}
202+
203+
if (!function_exists('isLiveTranslationEnabled')) {
204+
/**
205+
* Return true if live translation enabled
206+
*
207+
* @return bool
208+
*/
209+
function isLiveTranslationEnabled() {
210+
return Request::cookie('live-translation-enabled') || config('translation-manager.live_translation_enabled');
211+
}
212+
}
213+
```
214+
215+
In your layout view add this scripts and style (see Layout customization section):
216+
217+
```html
218+
<link href="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet"/>
219+
<style>
220+
.editable-click {
221+
border-bottom-color: red;
222+
cursor: pointer;
223+
}
224+
225+
.editableform .control-group {
226+
display: block;
227+
}
228+
229+
.editable-input {
230+
display: block;
231+
}
232+
233+
.editable-input > textarea {
234+
width: 100% !important;
235+
}
236+
237+
.editable-buttons {
238+
margin: 10px 0 0;
239+
text-align: right;
240+
width: 100%;
241+
}
242+
243+
.editable-buttons .editable-submit {
244+
float: right;
245+
margin-left: 10px;
246+
}
247+
</style>
248+
// ...
249+
<script src="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
250+
```
251+
134252
Changelog
135253
---------
136254

137255
0.3.0
138256

139-
* TODO
257+
* Support for subdirectories
258+
* Support for array translations
259+
* New design
260+
* Permission management
261+
* Translations for view
262+
* Live editing
140263

141264
0.2.0
142265

@@ -145,7 +268,9 @@ Changelog
145268
Roadmap
146269
-------
147270

148-
* TODO
271+
* Duplicate translations of one locale to another with locale suffix.
272+
* Detection of incorrect files.
273+
* Support vendor translations files.
149274
* Unit tests!
150275

151276
Credits

resources/lang/en/panel.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
return array(
4+
'actions' => array(
5+
'add' => 'Add new keys to file',
6+
'append' => 'Add only new translations',
7+
'back' => 'Go back to main site',
8+
'clean' => 'Remove all empty translations',
9+
'cleanOrReset' => 'Clean translations',
10+
'delete' => 'Delete this translation',
11+
'export' => 'Export all changes to files',
12+
'find' => 'Find missing translations',
13+
'import' => 'Import all files to database',
14+
'publish' => 'Publish this file',
15+
'replace' => 'Replace all translations',
16+
'reset' => 'Clear translations database',
17+
),
18+
'group' => array(
19+
'add-lines' => 'Write new keys for file, one in line',
20+
),
21+
'rows' => array(
22+
'confirm-delete' => 'Are you sure to delete this translations?',
23+
'edit' => 'Save changes',
24+
'key' => 'Key',
25+
),
26+
'welcome' => array(
27+
'availableFiles' => 'Available files',
28+
'chooseGroup' => 'Choose group to edit files.',
29+
'doImport' => 'There is no translation files imported to database. Please launch import operation.',
30+
'title' => 'Welcome in Laravel Translation Manager',
31+
),
32+
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<ul class="c-translation-module__menu indent-{{ $indent }}">
2+
@foreach($groups as $key => $value)
3+
@if(is_array($value) == false)
4+
<li class="c-translation-module__file {!! $value == $group ? ' active' : '' !!}{!! in_array($value, $highlighted) ? ' highlight' : '' !!}">
5+
<a href="{{ route('translation-manager.view', [$value]) }}">
6+
<span>{{ $key }}</span>
7+
</a>
8+
</li>
9+
@else
10+
<li class="c-translation-module__file">
11+
<a nohref>
12+
<span>{{ $key }}</span>
13+
</a>
14+
@include('translation-manager::files_list', ['groups' => $value, 'indent' => $indent + 1])
15+
</li>
16+
@endif
17+
@endforeach
18+
</ul>

resources/views/index.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('translation-manager::layout')
2+
3+
@section('translate_section')
4+
@if($canManage)
5+
@include('translation-manager::index_manage')
6+
@endif
7+
@endsection

0 commit comments

Comments
 (0)