-
Notifications
You must be signed in to change notification settings - Fork 28
Furigana
Furigana makes reading Japanese easier by putting small kana letters above kanji. The Furigana plugin builds furigana for each word made by Limelight. By default, furigana is made using the HTML5 ruby tag. However, for users who wish to do something different, tags can be configured in config.php.
Furigana can be accessed for the entire text using the the LimelightResults object and furigana for individual words can be retrieved from the LimelightWord object. Both objects use the furigana() method to access furigana.
Get furigana as an array for the entire text using the furigana() method.
$results = $limelight->parse('ライムは、柑橘類の一種です。');
echo $results->furigana()->all();
// [
// 'ライム',
// 'は',
// '、',
// '<ruby><rb>柑橘類</rb><rp>(</rp><rt>かんきつるい</rt><rp>)</rp></ruby>',
// 'の',
// '<ruby><rb>一</rb><rp>(</rp><rt>いち</rt><rp>)</rp></ruby>',
// '<ruby><rb>種</rb><rp>(</rp><rt>しゅ</rt><rp>)</rp></ruby>',
// 'です',
// '。'
Get a furigana string using the string() method.
$furigana = $results->string('furigana');
// 'ライムは、<ruby><rb>柑橘類</rb><rp>(</rp><rt>かんきつるい</rt><rp>)</rp></ruby>の<ruby><rb>一</rb><rp>(</rp><rt>いち</rt><rp>)</rp></ruby><ruby><rb>種</rb><rp>(</rp><rt>しゅ</rt><rp>)</rp></ruby>です。'
Which looks like this in the browser:
ライムは、柑橘類の一種です。
Get furigana for a single word with the furigana() method.
$results = $limelight->parse('ライムは、柑橘類の一種です。');
$furigana = $results->pull(3)->furigana();
// '<ruby><rb>柑橘類</rb><rp>(</rp><rt>かんきつるい</rt><rp>)</rp></ruby>'
In the browser:
柑橘類
The furigana plugin uses HTML5 ruby wrappers to generate furigana. However, if you wish to use your own implementation, wrappers can be configured in the config.php file.
The default configuration looks like this:
'Furigana' => [
'furigana_wrapper' => '<rt>{{}}</rt>',
'kanji_furigana_wrapper' => '<ruby>{{}}</ruby>',
'kanji_wrapper' => '',
'word_wrapper' => '',
]
Double curly braces act as place holders between opening and closing tags.
Tags are applied in the following order:
<word_wrapper><kanji_furigana_wrapper><kanji_wrapper>
kanji</kanji_wrapper><furigana_wrapper>
furigana</furigana_wrapper></kanji_furigana_wrapper>
other characters</word_wrapper>