Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

This projects polyfills the Intl.Segmenter API for browsers that do not support it.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT
Notifications You must be signed in to change notification settings

toeverything/intl-segmenter-polyfill-rs

Repository files navigation

Intl-Segmenter-Polyfill-rs

This repo is archived since all major browsers support this feature.

About

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:

Usage

Install wasm-pack

cargo install wasm-pack

Install binaryen

Use your package manager to install binaryen.

Install icu4x-datagen

cargo install icu_datagen

Generate the data

bash icu-datagen.sh

Build

bash build.sh

Use it in your project

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!'
}

Use it directly in the browser

<!-- Modify your src according to your need -->
<script type="module" src="/node_modules/intl-segmenter-polyfill-rs-web/intl_segmenter_polyfill_rs.js"></script>

License

Licensed under either of

at your option.

About

This projects polyfills the Intl.Segmenter API for browsers that do not support it.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Packages

No packages published