Skip to content

Commit 2800f98

Browse files
authored
Update translatable docs (#577)
* Document translatable entry language selection UI in 6.x and 7.x (#649)
1 parent 74a813e commit 2800f98

3 files changed

Lines changed: 41 additions & 20 deletions

File tree

6.x/crud-operation-update.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,6 @@ class Product extends Model
364364
use CrudTrait;
365365
use HasTranslations;
366366

367-
/*
368-
|--------------------------------------------------------------------------
369-
| GLOBAL VARIABLES
370-
|--------------------------------------------------------------------------
371-
*/
372-
373367
protected $table = 'products';
374368
protected $primaryKey = 'id';
375369
protected $fillable = ['name', 'category_id', 'options', 'price', 'tags'];
@@ -383,6 +377,19 @@ class Product extends Model
383377
384378
Change the languages available to translate to/from, in your crud config file (```config/backpack/crud.php```). By default there are quite a few enabled (English, French, German, Italian, Romanian).
385379

380+
381+
#### Updating and creating translatable entries
382+
383+
When you're creating a translatable entry, the entry will be created in the current user app locale. Either the one set in `config/app.php` or if you allow your admins to change the panel locale, the one set by them will be used.
384+
385+
When you update a translatable entry you choose in what language you want to create the translation for, idependently of the panel language or app locale.
386+
387+
When the entry has no translations in the chosen language for translation, you will get the option to select another language to copy the translations from.
388+
389+
390+
![https://backpackforlaravel.com/uploads/docs/translatable-bar.png](https://backpackforlaravel.com/uploads/docs/translatable-bar.png)
391+
392+
386393
Additionally, if you have slugs (but only if you need translatable slugs), you'll need to use backpack's classes instead of the ones provided by `cviebrock/eloquent-sluggable`.
387394
Make sure you have `cviebrock/eloquent-sluggable` installed as well, if not, please do it with `composer require cviebrock/eloquent-sluggable`:
388395

7.x/crud-fields.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ CRUD::field([ // Checklist
325325
'pivot' => true,
326326
'show_select_all' => true, // default false
327327
// 'number_of_columns' => 3,
328-
328+
329329
]);
330330
```
331331

@@ -874,7 +874,7 @@ CRUD::field([
874874
875875
#### Uploading files with summernote
876876

877-
Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote Uploader](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
877+
Summernote saves images as base64 encoded strings in the database. If you want to save them as files on the server, you can use the [Summernote Uploader](https://backpackforlaravel.com/docs/7.x/crud-uploaders). Please note that the Summernote Uploader is part of the `backpack/pro` package.
878878
Input preview:
879879

880880
![CRUD Field - summernote](https://backpackforlaravel.com/uploads/docs-4-2/fields/summernote.png)
@@ -1153,22 +1153,22 @@ CRUD::field([ // Address google
11531153
]);
11541154
```
11551155

1156-
Using Google Places API is dependent on using an API Key. Please [get an API key](https://console.cloud.google.com/apis/credentials) - you do have to configure billing, but you qualify for $200/mo free usage, which covers most use cases. Then copy-paste that key as your ```services.google_places.key``` value.
1156+
Using Google Places API is dependent on using an API Key. Please [get an API key](https://console.cloud.google.com/apis/credentials) - you do have to configure billing, but you qualify for $200/mo free usage, which covers most use cases. Then copy-paste that key as your ```services.google_places.key``` value.
11571157

11581158
**IMPORTANT NOTE**: Your key needs access to the following APIS:
11591159
- Maps JavaScript API;
11601160
- Places API;
11611161
- Geocoding API.
11621162

1163-
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
1163+
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
11641164

11651165
So inside your ```config/services.php``` please add the items below:
11661166
```php
11671167
'google_places' => [
11681168
'key' => 'the-key-you-got-from-google-places'
11691169
],
11701170
```
1171-
Alternatively you can set the key in your field definition, but we do **not recommend** it:
1171+
Alternatively you can set the key in your field definition, but we do **not recommend** it:
11721172
```php
11731173
[
11741174
'name' => 'google_field',
@@ -1445,7 +1445,7 @@ Using Google Places API is dependent on using an API Key. Please [get an API key
14451445
- Places API;
14461446
- Geocoding API.
14471447

1448-
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
1448+
While developing you can use an "unrestricted key" (no restrictions for where the key is used), but for production you should use a separate key, and **MAKE SURE** you restrict the usage of that key to your own domain.
14491449

14501450
**How to save in multiple inputs?**
14511451

@@ -1791,7 +1791,7 @@ CRUD::field([
17911791

17921792
By default Backpack does not allow you to select the same pivot twice. If you want to allow the selection of the same pivot more than once you should take some setup steps before. Follow along with the steps below:
17931793

1794-
**1)** Make sure your pivot table has a unique key, usually an auto-increment id. If you don't have one, you can add it with a migration.
1794+
**1)** Make sure your pivot table has a unique key, usually an auto-increment id. If you don't have one, you can add it with a migration.
17951795

17961796
**2)** Add the `id` to your `->withPivot()` fields on your relation. Eg:
17971797
```php
@@ -1816,7 +1816,7 @@ CRUD::field([
18161816
'name' => 'companies',
18171817
'type' => 'relationship',
18181818
'allow_duplicate_pivots' => true,
1819-
'subfields' => // your subfields (do not add `id` as a subfield. That's done automatically by Backpack).
1819+
'subfields' => // your subfields (do not add `id` as a subfield. That's done automatically by Backpack).
18201820
]);
18211821
```
18221822

@@ -2179,8 +2179,9 @@ CRUD::field([ // select2_from_array
21792179
'options' => ['one' => 'One', 'two' => 'Two'],
21802180
'allows_null' => false,
21812181
'default' => 'one',
2182+
// 'multiple' => true, // allows multiple selections
21822183
// 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
2183-
// 'sortable' => true, // requires the field to accept multiple values, and allow the selected options to be sorted;
2184+
// 'sortable' => true, // requires the field to accept multiple values, and allow the selected options to be sorted.
21842185
// 'tagging' => true, // allow users to type and create new options.
21852186
]);
21862187
```
@@ -2369,7 +2370,7 @@ CRUD::field([
23692370
'minimum_input_length' => 2, // minimum characters to type before querying results
23702371
'multiple' => true, // allow multiple selections
23712372
'include_all_form_fields' => false, // only send the current field through AJAX (for a smaller payload if you're not using multiple chained select2s)
2372-
2373+
23732374
// OPTIONAL - if the response is a list of objects (and not a simple array)
23742375
'attribute' => 'title', // attribute to show in the select2
23752376
'attributes_to_store' => ['id', 'title'], // attributes to store in the database
@@ -2420,7 +2421,7 @@ public function fetchAirports()
24202421

24212422
#### Storing only one the id in the database
24222423

2423-
A very common use case you may have is to store only the id of the selected item in the database instead of a `json` string. For those cases you can achieve that by setting the `attributes_to_store` attribute to an array with only one item, the id of the selected item and do a little trick with the model events to store the id you want, and to give the field that id in a way it understands.
2424+
A very common use case you may have is to store only the id of the selected item in the database instead of a `json` string. For those cases you can achieve that by setting the `attributes_to_store` attribute to an array with only one item, the id of the selected item and do a little trick with the model events to store the id you want, and to give the field that id in a way it understands.
24242425

24252426
```php
24262427

@@ -2429,7 +2430,7 @@ CRUD::field([
24292430
'type' => 'select2_json_from_api',
24302431
'name' => 'airport_id', // dont make your column json if not storing json on it!
24312432
// .... the rest your field configuration
2432-
'attribute' => 'id',
2433+
'attribute' => 'id',
24332434
'attributes_to_store' => ['id'],
24342435
'events' => [
24352436
'saving' => function($entry) {
@@ -2446,7 +2447,7 @@ CRUD::field([
24462447

24472448
### slug <span class="badge badge-pill badge-info">PRO</span>
24482449

2449-
Track the value of a different text input and turn it into a valid URL segment (aka. slug), as you type, using Javascript. Under the hood it uses [slugify](https://github.com/simov/slugify/blob/master/README.md) to generate the slug with some sensible defaults.
2450+
Track the value of a different text input and turn it into a valid URL segment (aka. slug), as you type, using Javascript. Under the hood it uses [slugify](https://github.com/simov/slugify/blob/master/README.md) to generate the slug with some sensible defaults.
24502451

24512452
```php
24522453
CRUD::field([ // Text

7.x/crud-operation-update.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ProductCrudController extends CrudController
335335
}
336336
```
337337

338-
>But before you do that, ask yourself - **_is this something that should be done when an entry is added/updated/deleted from the application, too_**? Not just the admin admin? If so, a better place for it would be the Model. Remember your Model is a pure Eloquent Model, so the cleanest way might be to use [Eloquent Event Observers](https://laravel.com/docs/12.x/eloquent#events) or [accessors and mutators](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators).
338+
>But before you do that, ask yourself - **_is this something that should be done when an entry is added/updated/deleted from the application, too_**? Not just the admin admin? If so, a better place for it would be the Model. Remember your Model is a pure Eloquent Model, so the cleanest way might be to use [Eloquent Event Observers](https://laravel.com/docs/5.5/eloquent#events) or [accessors and mutators](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators).
339339
340340
<a name="translatable-models"></a>
341341
### Translatable models and multi-language CRUDs
@@ -383,6 +383,19 @@ class Product extends Model
383383
384384
Change the languages available to translate to/from, in your crud config file (```config/backpack/crud.php```). By default there are quite a few enabled (English, French, German, Italian, Romanian).
385385

386+
387+
#### Updating and creating translatable entries
388+
389+
When you're creating a translatable entry, the entry will be created in the current user app locale. Either the one set in `config/app.php` or if you allow your admins to change the panel locale, the one set by them will be used.
390+
391+
When you update a translatable entry you choose in what language you want to create the translation for, idependently of the panel language or app locale.
392+
393+
When the entry has no translations in the chosen language for translation, you will get the option to select another language to copy the translations from.
394+
395+
396+
![https://backpackforlaravel.com/uploads/docs/translatable-bar.png](https://backpackforlaravel.com/uploads/docs/translatable-bar.png)
397+
398+
386399
Additionally, if you have slugs (but only if you need translatable slugs), you'll need to use backpack's classes instead of the ones provided by `cviebrock/eloquent-sluggable`.
387400
Make sure you have `cviebrock/eloquent-sluggable` installed as well, if not, please do it with `composer require cviebrock/eloquent-sluggable`:
388401

0 commit comments

Comments
 (0)