@connectedcars/react-i18n
Advanced tools
Comparing version 0.1.10 to 2.0.0
#!/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() | ||
@@ -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>> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
67039
5
78
1587
0
85
10
2
+ Addedcommander@6.2.1(transitive)
+ Addedgettext-parser@1.4.02.0.0(transitive)
+ Addedgettext-to-messageformat@0.3.1(transitive)
+ Addedpo2json@1.0.0-beta-3(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
- Removed@types/use-sync-external-store@0.0.3(transitive)
- Removedansi-styles@1.0.0(transitive)
- Removedchalk@0.4.0(transitive)
- Removedgettext-parser@1.1.0(transitive)
- Removedhas-color@0.1.7(transitive)
- Removednomnom@1.8.1(transitive)
- Removedpo2json@0.4.5(transitive)
- Removedreact-redux@9.1.2(transitive)
- Removedredux@5.0.1(transitive)
- Removedstrip-ansi@0.1.1(transitive)
- Removedunderscore@1.6.0(transitive)
- Removeduse-sync-external-store@1.2.2(transitive)
Updatedgettext-extractor@^3.4.2
Updatedpo2json@^1.0.0-alpha