Furigana
This Web Component is the easiest way to write japanese with furigana.
In HTML if you want to display 漢字 you need to write:
<ruby>漢
<rp>(</rp>
<rt>かん</rt>
<rp>)</rp>
</ruby>
<ruby>字
<rp>(</rp>
<rt>じ</rt>
<rp>)</rp>
</ruby>
Disclaimer
Yes.rp
tags are not a compulsory.😀
With Furigana Web Component, things become easy:
<wc-furigana value="漢[かん]字[じ]" />
Check out how to use the component in details here: Furigana.
TL;DR
- Write furigana inside square brackets:
桜[さくら]
. - Spaces will indicate which characters the furigana are above:
私[わたし]はフランス 人[じん]です。
. - Double spaces if you want to display a space character:
一 二 三
.
Framework integrations
Note
The following applies the support for IE11, see below if you don't care about it.
Vue
The following consider an application created with Vue CLI.
- Install the package
npm i @paulbarre/wc-furigana
- Modify the main file of your application to import the package:
main.js
or main.ts
if you are using TypeScript
import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'
// The following can be set into your `vue.config.js` file
Vue.config.ignoredElements = [/wc-furigana/]
applyPolyfills().then(() => {
defineCustomElements(window)
})
- Add a
wc-furigana
toApp.vue
to see if the component is correctly loaded
If the above doesn't work, check out Stencil documentation about integration into a Vue app.
Vuepress
- Install the package
npm i @paulbarre/wc-furigana
-
If you don't have it already, create a configuration file. From root folder add a
.vuepress
subfolder and createconfig.js
. -
Add headers to this configuration file.
module.exports = {
head: [
['script', {
type: 'module',
src: 'https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.esm.js'
}],
['script', {
nomodule: true,
src: 'https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.js'
}]
]
}
Example
You can run the example inexamples
folder withnpm run serve
.
Angular
The following consider an application created with Angular CLI.
- Install the package
npm i @paulbarre/wc-furigana
- You first need to add
CUSTOM_ELEMENTS_SCHEMA
to your application:
app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
@NgModule({
...
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
- Modify the main file to import the package:
main.ts
import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'
applyPolyfills().then(() => {
defineCustomElements(window)
})
- Add a
wc-furigana
toapp.component.html
to see if the component is correctly loaded
If the above doesn't work, check out Stencil documentation about integration into an Angular app.
React
The following consider an application created with Create React App.
- Install the package
npm i @paulbarre/wc-furigana
- Import the package into
index.js
import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'
applyPolyfills().then(() => {
defineCustomElements(window)
})
- Add a
wc-furigana
toApp.js
to see if the component is correctly loaded
If the above doesn't work, check out Stencil documentation about integration into a React app.
I don't care about IE11
If you don't need to support IE11, no need to apply Polyfills:
import { defineCustomElements } from '@paulbarre/wc-furigana/loader'
defineCustomElements(window)
I don't use a framework
Adding the Web Component into a single file without any framework is also possible
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.esm.js"></script>
<script nomodule src="https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.js"></script>
</head>
<body>
<wc-furigana value="漢[かん]字[じ]" />
</body>
</html>
Examples
Check out the folder examples to see how to integrate the component.