Skip to content

Commit

Permalink
Merge pull request #250 from saschaleib/saschaleib-patch-language-dir
Browse files Browse the repository at this point in the history
Improvements to the language and writing direction detection
  • Loading branch information
Klap-in committed Aug 13, 2023
2 parents a705163 + 63cb595 commit ce2c1d7
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions helper.php
Expand Up @@ -11,6 +11,14 @@ class helper_plugin_wrap extends DokuWiki_Plugin {
'wrap_info', 'wrap_important', 'wrap_alert', 'wrap_tip', 'wrap_help', 'wrap_todo',
'wrap_download', 'wrap_hi', 'wrap_spoiler');
static protected $paragraphs = array ('wrap_leftalign', 'wrap_rightalign', 'wrap_centeralign', 'wrap_justify');

/* list of languages which normally use RTL scripts */
static protected $rtllangs = array('ar','dv','fa','ha','he','ks','ku','ps','ur','yi','arc');
/* list of right-to-left scripts (may override the language defaults to rtl) */
static protected $rtlscripts = array('arab','thaa','hebr','deva','shrd');
/* selection of left-to-right scripts (may override the language defaults to ltr) */
static protected $ltrscripts = array('latn','cyrl','grek','hebr','cyrs','armn');

static $box_left_pos = 0;
static $box_right_pos = 0;
static $box_first = true;
Expand Down Expand Up @@ -94,14 +102,20 @@ function getAttributes($data, $useNoPrefix=true) {
$attr['class'] = (isset($attr['class']) ? $attr['class'].' ' : '').'wrap__emuhead';
}

//get dir
if($attr['lang']) {
$lang2dirFile = dirname(__FILE__).'/conf/lang2dir.conf';
if (@file_exists($lang2dirFile)) {
$lang2dir = confToHash($lang2dirFile);
$attr['dir'] = strtr($attr['lang'],$lang2dir);
}
}
/* improved RTL detection to make sure it covers more cases: */
if($attr['lang'] && $attr['lang'] !== '') {

// turn the language code into an array of components:
$arr = explode('-', $attr['lang']);

// is the language iso code (first field) in the list of RTL languages?
$rtl = in_array($arr[0], self::$rtllangs);

// is there a Script specified somewhere which overrides the text direction?
$rtl = ($rtl xor (bool) array_intersect( $rtl ? self::$ltrscripts : self::$rtlscripts, $arr));

$attr['dir'] = ( $rtl ? 'rtl' : 'ltr' );
}

return $attr;
}
Expand Down

0 comments on commit ce2c1d7

Please sign in to comment.