Skip to content

Commit 703271c

Browse files
committed
add ability to translate every string
1 parent da68671 commit 703271c

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

config/nova-filepond.php

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
<?php
22

33
return [
4+
/**
5+
* All the values will pass through the trans() function
6+
*/
7+
'labels' => [
8+
'decimalSeparator' => 'auto',
9+
'thousandsSeparator' => 'auto',
10+
'idle' => 'Drag & Drop your files or <span class="filepond--label-action"> Browse </span>',
11+
'invalidField' => 'Field contains invalid files',
12+
'fileWaitingForSize' => 'Waiting for size',
13+
'fileSizeNotAvailable' => 'Size not available',
14+
'fileLoading' => 'Loading',
15+
'fileLoadError' => 'Error during load',
16+
'fileProcessing' => 'Uploading',
17+
'fileProcessingComplete' => 'Upload complete',
18+
'fileProcessingAborted' => 'Upload cancelled',
19+
'fileProcessingError' => 'Error during upload',
20+
'fileProcessingRevertError' => 'Error during revert',
21+
'fileRemoveError' => 'Error during remove',
22+
'tapToCancel' => 'tap to cancel',
23+
'tapToRetry' => 'tap to retry',
24+
'tapToUndo' => 'tap to undo',
25+
'buttonRemoveItem' => 'Remove',
26+
'buttonAbortItemLoad' => 'Abort',
27+
'buttonRetryItemLoad' => 'Retry',
28+
'buttonAbortItemProcessing' => 'Cancel',
29+
'buttonUndoItemProcessing' => 'Undo',
30+
'buttonRetryItemProcessing' => 'Retry',
31+
'buttonProcessItem' => 'Upload'
32+
],
433
'doka' => [
534

635
/**
@@ -18,18 +47,18 @@
1847
/**
1948
* Uncomment this to use a circular mask instead of a rectangular one
2049
*/
21-
// 'cropMask' => <<<JAVASCRIPT
22-
// (root, setInnerHTML) => {
23-
// setInnerHTML(root, `
24-
// <mask id="circular-mask">
25-
// <rect x="0" y="0" width="100%" height="100%" fill="white"/>
26-
// <circle cx="50%" cy="50%" r="50%" fill="black"/>
27-
// </mask>
28-
// <rect fill="rgba(255,255,255,.3125)" x="0" y="0" width="100%" height="100%" mask="url(#circular-mask)"/>
29-
// <circle cx="50%" cy="50%" r="50%" fill="transparent" stroke-width="1" stroke="#fff"/>
30-
// `);
31-
// }
32-
// JAVASCRIPT,
50+
// 'cropMask' => <<<JAVASCRIPT
51+
// (root, setInnerHTML) => {
52+
// setInnerHTML(root, `
53+
// <mask id="circular-mask">
54+
// <rect x="0" y="0" width="100%" height="100%" fill="white"/>
55+
// <circle cx="50%" cy="50%" r="50%" fill="black"/>
56+
// </mask>
57+
// <rect fill="rgba(255,255,255,.3125)" x="0" y="0" width="100%" height="100%" mask="url(#circular-mask)"/>
58+
// <circle cx="50%" cy="50%" r="50%" fill="transparent" stroke-width="1" stroke="#fff"/>
59+
// `);
60+
// }
61+
// JAVASCRIPT,
3362
'cropShowSize' => true,
3463
'cropAspectRatioOptions' => [
3564
[

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/FilePondWrapper.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<template>
22

33
<file-pond
4-
v-bind="$attrs"
4+
v-bind="{ ...$attrs, ...field.labels }"
55
ref="filepond"
66
:style="cssVars"
77
:name="nameField"
88
:image-preview-height="field.multiple ? 150 : null"
9-
:label-idle="__('Drop files here...')"
109
:allow-multiple="field.multiple"
1110
:accepted-file-types="field.mimesTypes"
1211
:instant-upload="true"

src/Filepond.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Http\File;
88
use Illuminate\Support\Collection;
99
use Illuminate\Support\Facades\Storage;
10+
use Illuminate\Support\Str;
1011
use Laravel\Nova\Fields\Field;
1112
use Laravel\Nova\Http\Controllers\ResourceShowController;
1213
use Laravel\Nova\Http\Requests\NovaRequest;
@@ -138,6 +139,11 @@ public function withDoka(array $options = []): self
138139
]);
139140
}
140141

142+
public function labels(array $labels): self
143+
{
144+
return $this->withMeta([ 'labels' => $labels ]);
145+
}
146+
141147
/**
142148
* Disable Doka, you dont need to call this method if you haven't globally enabled it from the config file
143149
*
@@ -391,6 +397,19 @@ public static function getPathFromServerId(string $serverId): string
391397
return decrypt($serverId);
392398
}
393399

400+
private function getLabels(): Collection
401+
{
402+
403+
$labels = collect(config('nova-filepond.labels', []))
404+
->merge($this->meta[ 'labels' ] ?? [])
405+
->mapWithKeys(function ($label, $key) {
406+
return [ "label" . Str::title($key) => trans($label) ];
407+
});
408+
409+
return $labels;
410+
411+
}
412+
394413
/**
395414
* Prepare the field for JSON serialization.
396415
*
@@ -409,6 +428,7 @@ public function jsonSerialize()
409428
'limit' => null,
410429
'dokaOptions' => config('nova-filepond.doka.options'),
411430
'dokaEnabled' => config('nova-filepond.doka.enabled'),
431+
'labels' => $this->getLabels(),
412432
], $this->meta(), parent::jsonSerialize());
413433
}
414434

0 commit comments

Comments
 (0)