Socket
Book a DemoInstallSign in
Socket

@kaliber/i18n

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kaliber/i18n - npm Package Compare versions

Comparing version

to
1.1.0

15

index.js
const i18nContext = React.createContext(null)
const defaultLogMissingTranslation = ({ language, path }) => {
console.warn(`Missing translation (${language}): ${path}`)
}
export function useI18n(...i18nPathSegments) {
const context = React.useContext(i18nContext)
if (context === null) throwMissingContextError()
const { value, language } = context
const { value, language, logMissingTranslation } = context

@@ -13,3 +17,3 @@ return (...pathSegments) => {

if (process.env.NODE_ENV !== 'production' && typeof result === 'undefined') {
console.warn(`Missing translation (${language}): %c${path}`, 'font-weight: bold;')
logMissingTranslation({ language, path })
}

@@ -27,4 +31,7 @@

export function I18nProvider({ value, language, children }) {
const providerValue = React.useMemo(() => ({ value, language }), [value, language])
export function I18nProvider({ value, language, logMissingTranslation = defaultLogMissingTranslation, children }) {
const providerValue = React.useMemo(
() => ({ value, language, logMissingTranslation }),
[value, language, logMissingTranslation]
)

@@ -31,0 +38,0 @@ return (

{
"name": "@kaliber/i18n",
"version": "1.0.1",
"version": "1.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "sideEffects": false,

@@ -149,2 +149,3 @@ # i18n

| `language` | _Optional._ <br />When a language is given, normalization will be attempted at the leave nodes. E.g.: given the language `en` this means a leafnode with the shape `{ en: 'countries', nl: 'landen' }` will be normalized to just `'countries'`. |
| `logMissingTranslation` | _Optional._ (default: `console.warn`)<br />If you want to change how missing translations are logged, you can provide your own `logMissingTranslation` function. This function is called with an object of the shape: `{ language, path }`. |

@@ -151,0 +152,0 @@ The provided i18n object may be a deeply nested object, optionally containing arrays. Values don't have to be strings, you can also provide numbers, functions or React elements (see the example i18n object under [usage](#usage))

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.