Socket
Socket
Sign inDemoInstall

@connectedcars/react-i18n

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@connectedcars/react-i18n - npm Package Compare versions

Comparing version 0.1.10 to 2.0.0

dist/consumer.d.ts

38

bin/export.js
#!/usr/bin/env node
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor')
const { GettextExtractor, JsExtractors } = require('gettext-extractor')
let extractor = new GettextExtractor()
const content = {
trimWhiteSpace: true,
preserveIndentation: false
}
extractor

@@ -12,4 +17,5 @@ .createJsParser([

// data
context: 2
}
context: 2,
},
content,
}),

@@ -23,4 +29,25 @@

// data
context: 4
}
context: 4,
},
content,
}),
JsExtractors.callExpression(['tx', 'props.tx', '[this].context.tx'], {
arguments: {
text: 0,
// data
context: 2,
},
content,
}),
JsExtractors.callExpression(['tnx', 'props.tnx', '[this].context.tnx'], {
arguments: {
// count
text: 1,
textPlural: 2,
// data
context: 4,
},
content,
})

@@ -33,2 +60,1 @@ ])

extractor.printStats()

13

dist/index.d.ts

@@ -1,6 +0,7 @@

export { ReduxProvider as default, ReduxProvider } from './components/ReduxProvider';
export { Provider, ProviderProps } from './components/Provider';
export { withTranslate, WithTranslateProps } from './hoc/withTranslate';
export { setLanguage } from './redux/actions';
export { i18nReducer, I18nState } from './redux/reducer';
export { TranslateFunc, TranslatePluralFunc } from './types';
export * from './context';
export * from './provider';
export * from './consumer';
export * from './hoc';
export * from './store';
export * from './types';
//# sourceMappingURL=index.d.ts.map
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var ReduxProvider_1 = require("./components/ReduxProvider");
exports.default = ReduxProvider_1.ReduxProvider;
exports.ReduxProvider = ReduxProvider_1.ReduxProvider;
var Provider_1 = require("./components/Provider");
exports.Provider = Provider_1.Provider;
var withTranslate_1 = require("./hoc/withTranslate");
exports.withTranslate = withTranslate_1.withTranslate;
var actions_1 = require("./redux/actions");
exports.setLanguage = actions_1.setLanguage;
var reducer_1 = require("./redux/reducer");
exports.i18nReducer = reducer_1.i18nReducer;
__export(require("./context"));
__export(require("./provider"));
__export(require("./consumer"));
__export(require("./hoc"));
__export(require("./store"));

@@ -1,2 +0,25 @@

export declare type TranslateFunc = (text: string, data?: Object, context?: string) => string;
export declare type TranslatePluralFunc = (n: number, text: string, textPlural: string, data?: Object, context?: string | null) => string;
import { ReactNode } from 'react';
export interface Translations {
[locale: string]: TranslationSet;
}
export interface TranslationSet extends Record<string, string[]> {
}
declare type BasicTypes = boolean | string | number | null | undefined;
export declare type TranslateData = Record<string, BasicTypes> | null;
export declare type TranslateDataWithJSX = Record<string, ((children: React.ReactNode, attributes?: string) => React.ReactNode) | BasicTypes> | null;
export interface TranslationOptions {
strict?: boolean;
jsxWhitelist?: TranslateDataWithJSX;
content?: {
trimWhiteSpace?: boolean;
preserveIndentation?: boolean;
replaceNewLines?: false | string;
};
}
export declare type TranslateFunc = (message: string, data?: TranslateData, context?: string) => string;
export declare type TranslateJsxFunc = (message: string, data?: TranslateDataWithJSX, context?: string) => ReactNode;
export declare type TranslatePluralFunc = (n: number, singular: string, plural: string, data?: TranslateData, context?: string) => string;
export declare type TranslatePluralJsxFunc = (n: number, singular: string, plural: string, data?: TranslateDataWithJSX, context?: string) => ReactNode;
export declare type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export {};
//# sourceMappingURL=types.d.ts.map
{
"name": "@connectedcars/react-i18n",
"author": "Connected Cars <oss@connectedcars.io>",
"version": "0.1.10",
"version": "2.0.0",
"description": "Translations!",

@@ -24,3 +24,5 @@ "license": "MIT",

"watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"test:watch": "jest --watch",
"build": "tsc",
"prepublishOnly": "rm -rf dist/ && tsc"

@@ -39,3 +41,3 @@ },

"reactjs",
"redux",
"context",
"po",

@@ -46,23 +48,22 @@ "poedit",

"dependencies": {
"gettext-extractor": "^3.3.2",
"po2json": "^0.4.5",
"gettext-extractor": "^3.4.2",
"po2json": "^1.0.0-alpha",
"prop-types": "^15.6.2"
},
"devDependencies": {
"@types/prop-types": "^15.5.3",
"@types/react": "^16.4.6",
"@types/react-dom": "^16.0.6",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-redux": "^5.0.7",
"redux": "^3.7.2",
"tslint": "^5.11.0",
"typescript": "^2.9.2"
"@types/jest": "^23.3.13",
"@types/prop-types": "^15.5.8",
"@types/react": "^16.7.22",
"@types/react-dom": "^16.0.11",
"jest": "^23.6.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5",
"tslint": "^5.12.1",
"typescript": "^3.2.4"
},
"peerDependencies": {
"redux": ">=3.0.0",
"react": ">=15.0.0",
"react-dom": ">=15.0.0",
"react-redux": ">=4.0.0"
"react": "*",
"react-dom": "*"
}
}
# @connectedcars/react-i18n
Work in progress.
## Todo
- [ ] fuzzy translations
- [ ] improve documentation
## Installation

@@ -31,2 +25,38 @@

Translate plurals (`n` is injected into the data object, but can be overwritten):
`tn(count, '{n} time', '{n} times')`
Multiple lines are also supported using template strings (however, **DO NOT** use `${}` variables!):
```
t(`Foo
bar
baz`)
```
*Please note, however, that these translations will not be rendered on multiple lines in HTML!*
Translate with React:
```
// Use `tnx` for plurals with JSX!
tx(`
<p>Hello, <strong>{name}</strong><p>
<p>Today is {day}</p>
`, {
p: content => <p>{content}</p>,
strong: content => <strong>{content}</strong>,
name: 'John Doe',
day: 'Monday'
})
```
*Please note, by default translations are in strict mode which means an error will be thrown on undefined types*
*Please note, it is possible to add a whitelist/default by setting `jsxWhitelist` on the `I18nPovider`.*
You can also add a context to your translations:
`t('Hello', null, 'context here')`
## Import and Export

@@ -45,2 +75,3 @@

```
Then you can run the following commands:

@@ -55,2 +86,2 @@ * `npm run export` creates a POT file with the extracted translations in `./locales/template.pot`

"ci-translation": "i18n-translation-status"
```
```

@@ -1,6 +0,6 @@

export { ReduxProvider as default, ReduxProvider } from './components/ReduxProvider'
export { Provider, ProviderProps } from './components/Provider'
export { withTranslate, WithTranslateProps } from './hoc/withTranslate'
export { setLanguage } from './redux/actions'
export { i18nReducer, I18nState } from './redux/reducer'
export { TranslateFunc, TranslatePluralFunc } from './types'
export * from './context'
export * from './provider'
export * from './consumer'
export * from './hoc'
export * from './store'
export * from './types'

@@ -1,2 +0,58 @@

export type TranslateFunc = (text: string, data?: Object, context?: string) => string
export type TranslatePluralFunc = (n: number, text: string, textPlural: string, data?: Object, context?: string | null) => string
import { ReactNode } from 'react'
export interface Translations {
[locale: string]: TranslationSet
}
export interface TranslationSet extends Record<string, string[]> {}
type BasicTypes = boolean | string | number | null | undefined
export type TranslateData = Record<string, BasicTypes> | null
export type TranslateDataWithJSX = Record<
string,
| ((children: React.ReactNode, attributes?: string) => React.ReactNode)
| BasicTypes
> | null
export interface TranslationOptions {
strict?: boolean
jsxWhitelist?: TranslateDataWithJSX
content?: {
trimWhiteSpace?: boolean
preserveIndentation?: boolean
replaceNewLines?: false | string
}
}
export type TranslateFunc = (
message: string,
data?: TranslateData,
context?: string
) => string
export type TranslateJsxFunc = (
message: string,
data?: TranslateDataWithJSX,
context?: string
) => ReactNode
export type TranslatePluralFunc = (
n: number,
singular: string,
plural: string,
data?: TranslateData,
context?: string
) => string
export type TranslatePluralJsxFunc = (
n: number,
singular: string,
plural: string,
data?: TranslateDataWithJSX,
context?: string
) => ReactNode
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc