
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@locmod/intl
Advanced tools
This is lightweight copycat of `react-intl` package with minimal functionality
This is lightweight copycat of react-inlt package with minimal functionality.
Note: For now we have only EN locale and there is no requirements to extract translations to json. All translations injected to js bundle.
Add /// <reference types="@locmod/intl" /> into your next-env.d.ts
import React from 'react'
import { IntlProvider, Message } from 'intl'
const messages = {
title: {
en: 'Hello World',
},
}
const App = () => (
<IntlProvider locale="en">
<Message value={messages.title} />
</IntlProvider>
)
All intl messages should be written separately from components in messages.ts.
const messages = {
title: {
en: 'Hello World',
},
content: {
en: 'Hello, <b>{username}</b>',
},
}
<Message />import { Message } from 'intl'
import messages from './messages'
const App = () => {
const username = 'John Doe'
const contentMessage = useMemo(() => ({
...messages.content,
values: { username },
}), [])
return (
<div>
<Message value={messages.title} />
<Message value={contentMessage} />
</div>
)
}
Component Props
value - string | IntlMessage
html - boolean, "false" by default
<Message /> is ended component and like tags can receive any additional attribute.
<Message value={message} html />
intl.formatMessageWe shouldn't wrap intl.formatMessage with useMemo because its value based on locale.
Intl makes optimizations inside itself.
import { useIntl } from 'intl'
import messages from './messages'
const App = () => {
const intl = useIntl()
const title = intl.formatMessage(messages.title)
const content = intl.formatMessage(messages.content)
return (
<div>
{title}
<span dangerouslySetInnerHTML={{ __html: content }} />
</div>
)
}
Warning: Please use <Message /> when it's possible, and avoid of using intl.formatMessage when it's not necessary.
'Hello, <b>{username}</b>'
formatMessage(message, { username: 'John Doe' }) // Hello, <b>John Doe</b>
Sometimes you'd like to use conditions inside text based on passed value. The most case is plurals. There are couple of formulas:
'{count} {count, plural, one {product} other {products}}'
formatMessage(message, { count: 0 }) // 0 products
formatMessage(message, { count: 1 }) // 1 product
'{count, plural, one {# product} other {# products}}'
formatMessage(message, { count: 0 }) // 0 products
formatMessage(message, { count: 1 }) // 1 product
'Get free {gender, select, female {perfume} male {cologne}}'
formatMessage(message, { gender: 'female' }) // Get free perfume
formatMessage(message, { gender: 'male' }) // Get free cologne
formatMessage(message, { gender: null }) // Get free
'{gender, select, female {perfume} male {cologne} other {fragrance}}'
formatMessage(message, { gender: 'female' }) // perfume
formatMessage(message, { gender: 'male' }) // cologne
formatMessage(message, { gender: null }) // fragrance
A message can contain react components. To render them as components but not strings <Message /> component should be used
import Icon from 'components/Icon/Icon'
import Link from 'components/Link/Link'
const message = {
en: 'Read our <Icon /> <Link to="{docsLink}">docs</Link>',
values: { docsLink: '/docs' },
components: { Icon, Link },
}
return (
<Message value={message} />
)
FAQs
This is lightweight copycat of `react-intl` package with minimal functionality
The npm package @locmod/intl receives a total of 91 weekly downloads. As such, @locmod/intl popularity was classified as not popular.
We found that @locmod/intl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.