Install
@beforesemicolon/intl is designed to work in plain HTML, any framework, and tests.
You have two options:
- package manager + module usage
- CDN + browser globals
Both approaches expose the same runtime behavior.
Via package manager
bash
1npm install @beforesemicolon/intlThen initialize the runtime from your app entrypoint:
ts
1import {2 initIntl,3 intlMsg,4 intlNumber,5} from '@beforesemicolon/intl'Use any exported helpers directly from your bundler or ESM loader.
Via CDN (browser build)
html
1<script src="https://unpkg.com/@beforesemicolon/web-component/dist/client.js"></script>2<script src="https://unpkg.com/@beforesemicolon/intl/dist/client.js"></script>When loaded this way, helper functions are available on window.BFS.INTL:
html
1<script>2 const { initIntl, intlMsg, intlNumber } = window.BFS.INTL3</script>Minimal runtime setup
html
1<intl-locale locale="en-US" fallback-locale="en" src-dir="/locales">2 <intl-msg key="hello">Hello</intl-msg>3 <intl-number type="currency" currency="USD">1200</intl-number>4</intl-locale>src-dir loads /locales/{locale}.json by default (/locales/en-US.json).
How to choose a setup
| Scenario | Setup |
|---|---|
| Static pages | Use CDN scripts and intl-* tags |
| SPA or app framework | Use module imports and initIntl() |
| Tests and snapshots | Use initIntl() with messages |
Common installation notes
- Use
srcfor exact scoped files such as/locales/en.checkout.json. - Use
src-dirfor directory-based locale files such as/locales/{locale}.json. localeomits => runtime falls back todocument.documentElement.lang.fallback-localedefaults toen.- Add
update-documentonly on the app root locale scope.
Troubleshooting
If formatting is not updating:
- verify both scripts are loaded for browser/global mode
- verify your
src/src-dirURLs return valid JSON - ensure
intl-localeexists in the DOM before components mount