Jump to content

Specifying direction of language : RTL


Recommended Posts

When adding a language from Setup > Languages , where can we specify the direction is RTL ? So that the input field values direction change. 

Basically I need to work on the Arabic language.

Link to comment
Share on other sites

I don't know for sure but I don't think that this is possible. All posts that I found do not mention any solutions either:

https://processwire.com/talk/topic/17834-how-to-rtl-admintheme-core-files/

https://processwire.com/talk/topic/7262-ckeditor-rtl/

https://processwire.com/talk/topic/13540-ck-editor-rlt-for-arabic/ (@flydev seems to have tested it)

But UIkit supports RTL, so it might be possible?

  • Like 1
Link to comment
Share on other sites

This is possible if we can add 

dir="rtl"

inside the input element. Inorder for this to happen, when creating new language we need to define the direction as rtl. I have manually edited the input field and added dir=rtl . 

image.png.2bd839524f0e7ad02cd1be2f878f325b.png

Link to comment
Share on other sites

Hi, you could set a hook to set dir attribute on html tag or only on input(s) on language based and using bidir plugin on ck-editor to get parts of or whole backend as rtl as explained in thread linked by Bernhard, still seem the way to go.

  • Like 1
Link to comment
Share on other sites

One solution I got from @ryan https://github.com/processwire/processwire-issues/issues/2037#issuecomment-2643216328

the most direct to me seems just to use a hook in `site/templates/admin.php` and apply the dir attribute with JS.

1. 

$wire->addHookAfter('ProcessPageEdit::execute', function(HookEvent $e) {
  $rtl = [ 'arabic', 'japanese' ];
  $js = '';
  foreach($e->wire()->languages as $l) {
    if(!in_array($l->name, $rtl)) continue;
    $js .= "$('.LanguageSupport[data-language=$l]').find('input[type=text],textarea').attr('dir', 'rtl');";
  }
  if($js) $e->return .= "<script>$js</script>";
});
 
If you wanted it configurable with a checkbox on each language page (in Setup > Languages). Then you'd add a new checkbox field named "rtl" to your "language" template, and then use this code instead:
 
2. 
 
$wire->addHookAfter('ProcessPageEdit::execute', function(HookEvent $e) {
  $js = '';
  foreach($e->wire()->languages as $l) {
    if(!$l->rtl) continue;
    $js .= "$('.LanguageSupport[data-language=$l]').find('input[type=text],textarea').attr('dir', 'rtl');";
  }
  if($js) $e->return .= "<script>$js</script>";
});

I have used the 2nd option. Also 

  Quote

adding to `site/ready.php` worked. But not in `site/templates/admin.php`

Expand  

The only issue now is the ckeditor / tinymce is not rtl. I want to find a way to fix that also.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...