Skip to content

Commit

Permalink
Add translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Muetze42 committed Apr 22, 2022
1 parent ff9e681 commit ff36394
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ Same as a text field and disable „copy to clipboard“ method:
SecretField::make(__('Token'), 'token')->disableClipboard(),
```

#### Translate/Message text
Default:
```json
{
"Copied": "Kopiert",
"Copying failed": "Kopieren fehlgeschlagen"
}
```

Change messages
```php
SecretField::make(__('Token'), 'token')
->copiedMsg(__('Copied'))
->failedMsg(__('Copying failed')),
```

### Misc
For Nova 3:
[nalingia/nova-secret-field](https://github.com/nalingia/nova-secret-field)
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export default {
async copyToClipboard() {
try {
await navigator.clipboard.writeText(this.field.value);
Nova.$toasted.show(this.__('Copied'), {type: 'success'});
Nova.$toasted.show(this.field.copiedMsg, {type: 'success'});
} catch ($e) {
Nova.$toasted.show(this.__('Copying failed'), {type: 'error'});
Nova.$toasted.show(this.field.failedMsg, {type: 'error'});
}
},
},
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default {
async copyToClipboard() {
try {
await navigator.clipboard.writeText(this.field.value);
Nova.$toasted.show(this.__('Copied'), {type: 'success'});
Nova.$toasted.show(this.field.copiedMsg, {type: 'success'});
} catch ($e) {
Nova.$toasted.show(this.__('Copying failed'), {type: 'error'});
Nova.$toasted.show(this.field.failedMsg, {type: 'error'});
}
},
},
Expand Down
16 changes: 15 additions & 1 deletion src/SecretField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ class SecretField extends Field
public function __construct($name, $attribute = null, callable $resolveCallback = null)
{
parent::__construct($name, $attribute, $resolveCallback);
$this->withMeta(['showCopyToClipboard' => true]);
$this->withMeta([
'showCopyToClipboard' => true,
'copiedMsg' => __('Copied'),
'failedMsg' => __('Copying failed'),
]);
}

public function copiedMsg(string $message)
{
$this->withMeta(['copiedMsg' => __('Copied')]);
}

public function failedMsg(string $message)
{
$this->withMeta(['failedMsg' => __('Copied')]);
}

public function disableClipboard(): SecretField
Expand Down

0 comments on commit ff36394

Please sign in to comment.