class Localization
{
+
+ protected $rtlLocales = ['ar'];
+
/**
* Handle an incoming request.
*
$locale = setting()->getUser(user(), 'language', $defaultLang);
}
+ // Set text direction
+ if (in_array($locale, $this->rtlLocales)) {
+ config()->set('app.rtl', true);
+ }
+
app()->setLocale($locale);
Carbon::setLocale($locale);
return $next($request);
'locale' => env('APP_LANG', 'en'),
'locales' => ['en', 'ar', 'de', 'es', 'es_AR', 'fr', 'nl', 'pt_BR', 'sk', 'sv', 'ja', 'pl', 'it', 'ru', 'zh_CN', 'zh_TW'],
+ /*
+ |--------------------------------------------------------------------------
+ | Right-to-left text control
+ |--------------------------------------------------------------------------
+ |
+ | Right-to-left text control is set to false by default since English
+ | is the primary supported application but this may be dynamically
+ | altered by the applications localization system.
+ |
+ */
+
+ 'rtl' => false,
+
/*
|--------------------------------------------------------------------------
| Auto-detect the locale for public users
constructor(elem) {
this.elem = elem;
+ this.textDirection = document.getElementById('page-editor').getAttribute('text-direction');
this.markdown = new MarkdownIt({html: true});
this.markdown.use(mdTasksLists, {label: true});
codeMirrorSetup() {
let cm = this.cm;
+ // Text direction
+ // cm.setOption('direction', this.textDirection);
+ cm.setOption('direction', 'ltr'); // Will force to remain as ltr for now due to issues when HTML is in editor.
// Custom key commands
let metaKey = code.getMetaKey();
const extraKeys = {};
constructor(elem) {
this.elem = elem;
+ this.textDirection = document.getElementById('page-editor').getAttribute('text-direction');
this.plugins = "image table textcolor paste link autolink fullscreen imagetools code customhr autosave lists codeeditor media";
this.loadPlugins();
drawIoPlugin();
this.plugins += ' drawio';
}
+ if (this.textDirection === 'rtl') {
+ this.plugins += ' directionality'
+ }
+ }
+
+ getToolBar() {
+ const textDirPlugins = this.textDirection === 'rtl' ? 'ltr rtl' : '';
+ return `undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr drawio media | removeformat code ${textDirPlugins} fullscreen`
}
getTinyMceConfig() {
body_class: 'page-content',
browser_spellcheck: true,
relative_urls: false,
+ directionality : this.textDirection,
remove_script_host: false,
document_base_url: window.baseUrl('/'),
statusbar: false,
valid_children: "-div[p|h1|h2|h3|h4|h5|h6|blockquote],+div[pre],+div[img]",
plugins: this.plugins,
imagetools_toolbar: 'imageoptions',
- toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr drawio media | removeformat code fullscreen",
+ toolbar: this.getToolBar(),
content_style: "body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}",
style_formats: [
{title: "Header Large", format: "h2"},
newWrap.className = 'CodeMirrorContainer';
newWrap.setAttribute('data-lang', lang);
+ newWrap.setAttribute('dir', 'ltr');
newTextArea.style.display = 'none';
elem.parentNode.replaceChild(newWrap, elem);
}
ul {
padding-left: $-m * 1.3;
+ padding-right: $-m * 1.3;
list-style: disc;
ul {
list-style: circle;
ol {
list-style: decimal;
padding-left: $-m * 2;
+ padding-right: $-m * 2;
}
li.checkbox-item, li.task-list-item {
drawio-enabled="{{ config('services.drawio') ? 'true' : 'false' }}"
editor-type="{{ setting('app-editor') }}"
page-id="{{ $model->id or 0 }}"
+ text-direction="{{ config('app.rtl') ? 'rtl' : 'ltr' }}"
page-new-draft="{{ $model->draft or 0 }}"
page-update-draft="{{ $model->isDraft or 0 }}">
-<div>
+<div dir="auto">
<h1 class="break-text" v-pre id="bkmrk-page-title">{{$page->name}}</h1>
}
}
+ public function test_rtl_config_set_if_lang_is_rtl()
+ {
+ $this->asEditor();
+ $this->assertFalse(config('app.rtl'), "App RTL config should be false by default");
+ setting()->putUser($this->getEditor(), 'language', 'ar');
+ $this->get('/');
+ $this->assertTrue(config('app.rtl'), "App RTL config should have been set to true by middleware");
+ }
+
}
\ No newline at end of file