This repo is archived since all major browsers support this feature.
This project polyfills the Intl.Segmenter API for browsers that do not support it.
See the bugzilla issue here.
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Packages are available at:
- https://www.npmjs.com/package/intl-segmenter-polyfill-rs
- https://www.npmjs.com/package/intl-segmenter-polyfill-rs-web
cargo install wasm-pack
Use your package manager to install binaryen
.
cargo install icu_datagen
bash icu-datagen.sh
bash build.sh
import * as IntlSegmeterPolyfill from "intl-segmenter-polyfill-rs";
// Browsers like firefox
if (Intl.Segmenter === undefined) {
Intl.Segmenter = IntlSegmeterPolyfill.Segmenter;
const segmenterFr = new Intl.Segmenter('fr', { granularity: 'sentence' });
const string1 = 'Hello World. Xin chào thế giới!';
const iterator1 = segmenterFr.segment(string1)[Symbol.iterator]();
console.log(iterator1.next().value.segment);
// Expected output: 'Hello World. '
console.log(iterator1.next().value.segment);
// Expected output: 'Xin chào thế giới!'
}
<!-- Modify your src according to your need -->
<script type="module" src="/node_modules/intl-segmenter-polyfill-rs-web/intl_segmenter_polyfill_rs.js"></script>
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.