Skip to content

Commit

Permalink
Merge pull request #21 from mostafaznv/dev
Browse files Browse the repository at this point in the history
support ui language #20
  • Loading branch information
mostafaznv authored Jun 10, 2022
2 parents 736fba6 + b177656 commit 4255d04
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 69 deletions.
84 changes: 24 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Includes custom written plugins for media (video and image), snippet and publish


## Requirements
- PHP 7.4 or higher
- Laravel 8.* or higher
- PHP 8.0.2 or higher
- Laravel 8.40.* or higher
- Nova 4
- FFMPEG (required for larupload usage)

<br><br>
Expand Down Expand Up @@ -192,7 +193,7 @@ $this->app->bind('ckeditor-image-storage', MyImageStorage::class);
| toolbar | Array | from config file | Set toolbar items |
| height | Integer | from config file | Set editor's height |
| limitOnIndex | Integer | 85 | Set character limit on index |
| contentLanguage | Integer | from config file | Language of editor's content. if you want to change text-direction (RTL, LTR), you need this |
| contentLanguage | String | from config file | Language of editor's content. if you want to change text-direction (RTL, LTR), you need this |
| shouldNotGroupWhenFull | Boolean | from config file | Indicates whether the editor shows 3 dots in overflow mode |
| imageBrowser | Boolean | from config file | Enable/Disable image picker |
| videoBrowser | Boolean | from config file | Enable/Disable video picker |
Expand All @@ -203,64 +204,27 @@ $this->app->bind('ckeditor-image-storage', MyImageStorage::class);
------

## Configuration
You can change configuration options in `app/config/nova-ckeditor.php`
You can change configuration options in `app/config/nova-ckeditor.php`


| key | type | default | description |
|------------------------------------|----------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| video-model | String | App\Models\Video | Path of your video model |
| memory | String | 256M | Max memory (php.ini override) for image resizing |
| max-quality | Integer | 75 | Max image output quality |
| max-width | Integer | 1024 | Image max width |
| max-height | Integer | 768 | Image max height |
| toolbar.height | Integer | 400 | Editor's height. |
| toolbar.content-lang | String `format: ISO 639-1` | en | Language of editor's content. if you want to change text-direction (RTL, LTR), you need this |
| toolbar.ui-language.name | String `format: ISO 639-1` | en | Language of editor's ui. |
| toolbar.ui-language.script | String | null | URL of language file to use in editor's ui.<br>example 1: `asset('js/ckeditor-fa.js')`<br>example 2: `https://cdn.ckeditor.com/ckeditor5/34.0.0/decoupled-document/translations/fa.js` |
| toolbar.should-not-group-when-full | Boolean | false | Indicates whether the editor shows 3 dots in overflow mode |
| toolbar.browser.image | Boolean | true | You can disable image picker by changing this flag |
| toolbar.browser.video | Boolean | true | You can disable video picker by changing this flag |
| toolbar.snippets | Array | | There are some pre-defined snippets in `resources/views/ckeditor`. you can add more snippets if you want. <br> > **Note**: Snippets will only render CkEditor Elements. Standard HTML or Figures (table, image, video), see included views. https://ckeditor.com/docs |
| toolbar.items | Array | | These are toolbar buttons. you can remove or rearrange them |
| toolbar.options | Array | | Options of toolbar items. to see more information, please check the CkEditor's documentation. |

### Video Model
`string` `default: App\Models\Video`

Path of your video model

### Memory
`string` `default: 256M`

Max memory (php.ini override) for image resizing

### Max Quality
`integert` `default: 75`

Max image output quality

### Max Width and Height
`integer` `default width: 1024` `default height: 768`

Image max dimensions

### Toolbar
#### height
`integer` `default: 400`

Editor's height.

#### Content Lang
`string` `default: en` `format: ISO 639-1`

Language of editor's content. if you want to change text-direction (RTL, LTR), you need this

#### Should Not Group When Full
`boolean` `default: false`

Indicates whether the editor shows 3 dots in overflow mode

#### Browser
`boolean` `default: true`

You can disable video and image picker by changing these options

#### Snippets
`array`

There are some pre-defined snippets in `resources/views/ckeditor`. you can add more snippets if you want.

> **Note**: Snippets will only render CkEditor Elements. Standard HTML or Figures (table, image, video), see included views. https://ckeditor.com/docs
#### Items
`array`

These are toolbar buttons. you can remove or rearrange them

#### Options
`array`
Options of toolbar items. to see more information, please check the CkEditor's documentation.

----
🚀 If you find this project interesting, please consider supporting me on the open source journey
Expand Down
10 changes: 10 additions & 0 deletions config/nova-ckeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@

'content-lang' => 'en',

'ui-language' => [
'name' => 'en',

/**
* Example 1: asset('js/ckeditor-fa.js')
* Example 2: 'https://cdn.ckeditor.com/ckeditor5/34.0.0/decoupled-document/translations/fa.js'
*/
'script' => null
],

'should-not-group-when-full' => false,

'browser' => [
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion resources/js/ckeditor/plugins/MediaBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ export default class MediaBrowser {
* @return {ButtonView}
*/
createButton(locale) {
const {t} = locale
const view = new ButtonView(locale)

view.set({
label: this.type === 'imageBrowser' ? 'Insert Image' : 'Insert Video',
label: t(this.type === 'imageBrowser' ? 'Insert Image' : 'Insert Video'),
icon: this.icon,
tooltip: true,
})
Expand Down
9 changes: 4 additions & 5 deletions resources/js/ckeditor/plugins/SnippetBrowser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/**
* @var Nova
*/
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'

export default class SnippetBrowser {

constructor(editor) {
this.editor = editor;
this.config = editor.config;
Expand Down Expand Up @@ -70,12 +66,15 @@ export default class SnippetBrowser {
* @return {ButtonView}
*/
createButton(locale) {
const {t} = locale
const view = new ButtonView(locale)

view.set({
label: 'Insert Snippet',
label: t('Insert Snippet'),
icon: this.icon,
tooltip: true,
})

if (this.isEnabled) {
view.on('execute', this.openModal.bind(this))
}
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/editor-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default {
videoBrowser: this.field.videoBrowser,
snippetBrowser: this.field.snippetBrowser,
language: {
ui: 'en',
ui: this.field.uiLanguage,
content: this.field.contentLanguage
},
toolbar: {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default {

<style lang="sass">
.ck.ck-reset_all, .ck.ck-reset_all *
direction: ltr !important
// direction: ltr !important
.ck-content.ck-editor__editable
resize: vertical
Expand Down
9 changes: 9 additions & 0 deletions src/CkEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class CkEditor extends Field
*/
public string $contentLanguage;

/**
* UI Language
*
* @var string
*/
public string $uiLanguage = 'en';

/**
* Indicates whether the editor shows 3 dots in overflow mode
*
Expand Down Expand Up @@ -93,6 +100,7 @@ public function __construct($name, $attribute = null, callable $resolveCallback
$this->videoBrowser = $config['toolbar']['browser']['video'];
$this->snippetBrowser = $this->prepareSnippets($config['toolbar']['snippets']);
$this->contentLanguage = $config['toolbar']['content-lang'];
$this->uiLanguage = $config['toolbar']['ui-language']['name'] ?? 'en';
$this->shouldNotGroupWhenFull = $config['toolbar']['should-not-group-when-full'];
$this->videoModel = $config['video-model'];
}
Expand Down Expand Up @@ -218,6 +226,7 @@ public function jsonSerialize(): array
'height' => $this->height,
'indexLimit' => $this->indexLimit,
'contentLanguage' => $this->contentLanguage,
'uiLanguage' => $this->uiLanguage,
'shouldNotGroupWhenFull' => $this->shouldNotGroupWhenFull,
'shouldShow' => $this->shouldBeExpanded(),
'videoHasLaruploadTrait' => $this->hasLaruploadTrait(),
Expand Down
4 changes: 4 additions & 0 deletions src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function boot(): void
Nova::provideToScript(['ckeditor' => config('nova-ckeditor', [])]);
Nova::style('field-ckeditor', __DIR__ . '/../dist/css/field.css');

if ($langScript = config('nova-ckeditor.toolbar.ui-language.script')) {
Nova::script('ckeditor-lang', $langScript);
}

// allow hot reloading
if (App::environment('local') && file_exists(__DIR__ . '/../dist/hot')) {
Nova::remoteScript('http://localhost:8080/js/field.js');
Expand Down

0 comments on commit 4255d04

Please sign in to comment.