Skip to content

Commit ff36394

Browse files
committed
Add translation
1 parent ff9e681 commit ff36394

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ Same as a text field and disable „copy to clipboard“ method:
3030
SecretField::make(__('Token'), 'token')->disableClipboard(),
3131
```
3232

33+
#### Translate/Message text
34+
Default:
35+
```json
36+
{
37+
"Copied": "Kopiert",
38+
"Copying failed": "Kopieren fehlgeschlagen"
39+
}
40+
```
41+
42+
Change messages
43+
```php
44+
SecretField::make(__('Token'), 'token')
45+
->copiedMsg(__('Copied'))
46+
->failedMsg(__('Copying failed')),
47+
```
48+
3349
### Misc
3450
For Nova 3:
3551
[nalingia/nova-secret-field](https://github.com/nalingia/nova-secret-field)

dist/js/field.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/DetailField.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export default {
7171
async copyToClipboard() {
7272
try {
7373
await navigator.clipboard.writeText(this.field.value);
74-
Nova.$toasted.show(this.__('Copied'), {type: 'success'});
74+
Nova.$toasted.show(this.field.copiedMsg, {type: 'success'});
7575
} catch ($e) {
76-
Nova.$toasted.show(this.__('Copying failed'), {type: 'error'});
76+
Nova.$toasted.show(this.field.failedMsg, {type: 'error'});
7777
}
7878
},
7979
},

resources/js/components/IndexField.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export default {
3636
async copyToClipboard() {
3737
try {
3838
await navigator.clipboard.writeText(this.field.value);
39-
Nova.$toasted.show(this.__('Copied'), {type: 'success'});
39+
Nova.$toasted.show(this.field.copiedMsg, {type: 'success'});
4040
} catch ($e) {
41-
Nova.$toasted.show(this.__('Copying failed'), {type: 'error'});
41+
Nova.$toasted.show(this.field.failedMsg, {type: 'error'});
4242
}
4343
},
4444
},

src/SecretField.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ class SecretField extends Field
1616
public function __construct($name, $attribute = null, callable $resolveCallback = null)
1717
{
1818
parent::__construct($name, $attribute, $resolveCallback);
19-
$this->withMeta(['showCopyToClipboard' => true]);
19+
$this->withMeta([
20+
'showCopyToClipboard' => true,
21+
'copiedMsg' => __('Copied'),
22+
'failedMsg' => __('Copying failed'),
23+
]);
24+
}
25+
26+
public function copiedMsg(string $message)
27+
{
28+
$this->withMeta(['copiedMsg' => __('Copied')]);
29+
}
30+
31+
public function failedMsg(string $message)
32+
{
33+
$this->withMeta(['failedMsg' => __('Copied')]);
2034
}
2135

2236
public function disableClipboard(): SecretField

0 commit comments

Comments
 (0)