Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
intl-schematic
Advanced tools
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Raiondesu/intl-schematic/main/logo/Dark%20Logo.svg"> <source media="(prefers-color-scheme: light)" srcset="https://raw.github
A tiny framework-agnostic i18n library (1kb gzip, zero-dependency) that allows to localize and format strings with infinitely expandable functionality.
See a simplified example below and don't be afraid to take a look into the sources to find out more.
// In the real world, this function would probably contain
// a dynamic import of the required translation document
const getDocument = () => ({
"hello": "Hello, World!"
});
t()
)import { createTranslator } from 'intl-schematic';
const t = createTranslator(getDocument);
// OR
const t = createTranslator(getDocument, [
// Add optional plugins here
// they will be applied to translations in corresponding order
]);
console.log(t('hello')); // `Hello, World!`
Many other i18n libraries require deep integration into a specific UI-framework.
This, however, is not the case with intl-schematic
, due to its framework-agnostic and isomorphic architecture.
The only requirement to make it behave "natively" for a certain framework,
is to simply add a reactive dependency to a closure of getLocaleDocument
function (the first argument of createTranslator
).
Here's an example in a "reactive pseudocode":
// Define a reactive variable;
// Solid
const userLocale = createSignal(new Intl.Locale('en'));
// Vue
const userLocale = ref(new Intl.Locale('en'));
const fetchDocument = () => {
// Somehow get a value from the reactive variable
const language = get(userLocale).language;
// Suppose you have a translation document in the `locales` folder
return import(`/locales/${language}.json`);
};
// Create a reactive variable for a translation document
const currentDocument = createSignal();
// Then, in a reactive context (like a UI component)
const t = createTranslator(
// If this function is invoked in a reactive context,
// the framework will most likely track this as a reactive dependency
() => get(currentDocument)
);
// useEffect/watch/computed
createEffect(() => {
// Since calling `fetchDocument`
// involves getting a value from a reactive variable,
// this is tracked as a reactive dependency and will re-run accordingly
fetchDocument()
.then(newDocument => set(currentDocument, newDocument));
});
<p>{t('some key')}</p> // Some text
// Then change the locale
set(userLocale, new Intl.Locale('es'));
// The text re-renders automatically once the new translation document is fetched
<p>{t('some key')}</p> // Algún texto
Even though something like this is fairly trivial to implement,
given a basic knowledge of any specific UI-framework,
intl-schematic
still offers some "in-house"-made integrations:
@intl-schematic/solid
- reactive adapter for solid-js
intl-schematic
and user-defined plugins@intl-schematic/vue
- Work in progressIf you want an integration for your favorite framework, feel free to contibute or create an issue!
This is by far the main strength of the library.
Translating keys relies on simple key-value lookup, and most libraries add many unnecessary features on top of this primitive functionality.
intl-schematic
instead provides a way to extend both its functionality and type definitions in a comprehensive enough way,
so that anyone can pick and choose what exact features are needed for their project without any bloat whatsoever.
In other words, plugins allow to almost infinitely expand the functionality of intl-schematic
.
To find out more, see the main plugins readme.
Current list of all official plugins is as follows:
@intl-schematic/plugin-defaults
@intl-schematic/plugin-arrays
(included in defaults)
@intl-schematic/plugin-functions
@intl-schematic/plugin-locale
(included in defaults)
Intl.Locale
instance@intl-schematic/plugin-nested
@intl-schematic/plugin-processors
(included in defaults)
You might want to install the default plugin collection:
npm i @intl-schematic/plugin-defaults
These allow to use standard Intl features,
like DateTimeFormat
,
PluralRules
and DisplayNames
,
as well as cross-reference keys and many other features.
import { createTranslator } from 'intl-schematic';
import { defaultPlugins, defaultProcessors } from '@intl-schematic/plugin-defaults';
const getDocument = () => ({
price: {
// Processor name - number - means process with Intl.NumberFormat
number: {
// Intl.NumberFormat options
style: "currency",
currency: "USD",
currencyDisplay: "symbol",
trailingZeroDisplay: "stripIfInteger"
},
input: 0 // fallback
}
});
const getLocale = () => new Intl.Locale('en');
const t = createTranslator(getDocument, defaultPlugins(
getLocale,
defaultProcessors
));
console.log(t('price', 123)); // "$123"
FAQs
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Raiondesu/intl-schematic/main/logo/Dark%20Logo.svg"> <source media="(prefers-color-scheme: light)" srcset="https://raw.github
The npm package intl-schematic receives a total of 127 weekly downloads. As such, intl-schematic popularity was classified as not popular.
We found that intl-schematic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.