Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-30 17:36:52

dorijan
New Member
From: Serbia
Registered: 2021-01-04
Posts: 4
Website Twitter

Hyphenate

Hyphenation patterns for many languages are widely available.
I have them for Serbian Cyrillic and Latin.
Browser support and CSS rules work for several well-known languages.

It would be useful to have hyphenation plugin which would accomodate other languages.
One plugin-multilingual support.
Thus a newspaper and book-alike websites could be created in many languages.

Unfortunately I do not have technical skills (at least not yet) to make one and pat_hyphenate is not maintained any more (Thank you Patrick for fast response).

Is it doable?

Regards D.B.


Thrive on simplicity

Offline

#2 2021-05-25 10:07:10

etc
Developer
Registered: 2010-11-11
Posts: 4,435
Website GitHub

Re: Hyphenate

Hi Dorijan,

it’s both easy and difficult. To test the easy part, just save the following in textpattern/plugins/abc_hyphen.php file:

<?php
$plugin['name'] = 'abc_hyphen';
$plugin['version'] = '0.1';
$plugin['author'] = 'Textpattern Community';
$plugin['author_uri'] = 'https://github.com/textpattern';
$plugin['description'] = 'Hard-coded hyphenation';
$plugin['order'] = '5';

if (txpinterface == 'admin')
  register_callback('abc_hyphen', 'textfilter', 'filter', 0);

function abc_hyphen($event, $step, &$rs) {
  $rs = strtr($rs, array('Србиjа' => 'Ср&shy;би&shy;jа'));
}

Now each occurrence of ‘Србиjа’ in Body or Excerpt should be hyphenated on article save in their _html versions used for the output (check the preview). You must, of course, import the whole hyphenation array from somewhere (file, …), but you get the idea.

More difficult parts:

  • take the article language into account (well, rather easy);
  • make the hyphenation case insensitive;
  • avoid inappropriate substrings hyphenation;
  • avoid hyphenating eventual tag names like e.g. <object> and attributes.

But feel free to experiment.

Offline

#3 2021-05-26 07:22:18

etc
Developer
Registered: 2010-11-11
Posts: 4,435
Website GitHub

Re: Hyphenate

A third-party (phpSyllable) based plugin is available now (txp 4.8+ only). It will append a ‘Hyphenate’ textfilter option to Body and Excerpt.

The hyphenation will be done using the public language patterns (if available). About 75 languages are included, you can remove the unused ones and download them again when necessary.

Edit: hmm, working on my localhost, but not on the demo site. Investigating… done!

Offline

Board footer

Powered by FluxBB