suttacentral / bilara

Our Computer Aided Translation software
10 stars 8 forks source link

Add hyphenation support #62

Closed sujato closed 1 year ago

sujato commented 4 years ago

Long words in pali make a bad problem, see eg an3.24.

CSS hyphens: auto fixes this, but there are two problems:

  1. No hyphenation libraries for Pali/Sanskrit.
  2. No auto support in Chrome, apart from Android and Mac (!)

Solution: hack it by adding lang='la' to Pali strings, and appropriate language to translation texts. Latin seems to give good results.

At least it will work in FF and Safari!

Before:

Screenshot from 2020-06-30 09-26-16

After:

Screenshot from 2020-06-30 09-25-58

Add CSS to segments, here is the full thing for best practice:

p {
     -webkit-hyphens: auto;
     -webkit-hyphenate-limit-before: 3;
     -webkit-hyphenate-limit-after: 3;
     -webkit-hyphenate-limit-chars: 6 3 3;
     -webkit-hyphenate-limit-lines: 2;
     -webkit-hyphenate-limit-last: always;
     -webkit-hyphenate-limit-zone: 8%;
     -moz-hyphens: auto;
     -moz-hyphenate-limit-chars: 6 3 3;
     -moz-hyphenate-limit-lines: 2;
     -moz-hyphenate-limit-last: always;
     -moz-hyphenate-limit-zone: 8%;
     -ms-hyphens: auto;
     -ms-hyphenate-limit-chars: 6 3 3;
     -ms-hyphenate-limit-lines: 2;
     -ms-hyphenate-limit-last: always;
     -ms-hyphenate-limit-zone: 8%;
     hyphens: auto;
     hyphenate-limit-chars: 6 3 3;
     hyphenate-limit-lines: 2;
     hyphenate-limit-last: always;
     hyphenate-limit-zone: 8%;
 }
firepick1 commented 4 years ago

Another possibility is to use soft hyphens in the root text: U+00AD (SHY) An invisible, "soft" hyphen. This character is not rendered visibly; instead, it marks a place where the browser should break the word if hyphenation is necessary. In HTML, use ­ to insert a soft hyphen.

https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens