react-polyglot-hooks
Advanced tools
Comparing version 0.3.0-0 to 0.3.0
@@ -5,2 +5,4 @@ # Changelog | ||
## [0.3.0](https://github.com/pmmmwh/react-polyglot-hooks/compare/v0.3.0-0...v0.3.0) (2019-09-05) | ||
## [0.3.0-0](https://github.com/pmmmwh/react-polyglot-hooks/compare/v0.2.0...v0.3.0-0) (2019-09-02) | ||
@@ -7,0 +9,0 @@ |
import Polyglot from 'node-polyglot'; | ||
import enhanceT from './enhanceT'; | ||
/** | ||
* The original t function from Polyglot.js. | ||
*/ | ||
export declare type PolyglotT = typeof Polyglot.prototype.t; | ||
/** | ||
* The t function for translation. | ||
*/ | ||
export declare type tFunction = ReturnType<typeof enhanceT>; | ||
export declare const NO_NUMBER_INTERPOLATIONS: string; | ||
export declare const NO_POLYGLOT_CONTEXT: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// TODO: Remove after deprecation of number from interpolations in v0.3.0 | ||
// TODO: Remove after deprecation of number from interpolations in v0.4.0 | ||
exports.NO_NUMBER_INTERPOLATIONS = [ | ||
@@ -5,0 +5,0 @@ 'Warning:', |
@@ -1,5 +0,10 @@ | ||
/// <reference path="../src/vendors.d.ts" /> | ||
/// <reference types="node-polyglot" /> | ||
import { ReactElement } from 'react'; | ||
/** | ||
* An function to enhance Polyglot.js to allow React component interpolations. | ||
* | ||
* @param originalT The original t function from Polyglot.js. | ||
* @returns The enhanced t function. | ||
*/ | ||
declare const enhanceT: (originalT: (phrase: string, options?: number | import("node-polyglot").InterpolationOptions | undefined) => string) => (key: string, interpolations?: number | import("node-polyglot").InterpolationOptions | undefined) => ReactElement<any, string | ((props: any) => ReactElement<any, string | any | (new (props: any) => import("react").Component<any, any, any>)> | null) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
export default enhanceT; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
// A pseudo-JSX string interpolation identifier | ||
/** | ||
* A pseudo-JSX string interpolation identifier. | ||
*/ | ||
var IDENTIFIER = /<(\d+)\/>/; | ||
/** | ||
* An function to enhance Polyglot.js to allow React component interpolations. | ||
* | ||
* @param originalT The original t function from Polyglot.js. | ||
* @returns The enhanced t function. | ||
*/ | ||
var enhanceT = function (originalT) { | ||
@@ -7,0 +15,0 @@ // We use a named function here to aid debugging |
import * as React from 'react'; | ||
import { PolyglotOptions } from 'node-polyglot'; | ||
/** | ||
* Props accepted by the I18n component. | ||
*/ | ||
export interface I18nProps extends PolyglotOptions { | ||
/** The current locale. */ | ||
locale: string; | ||
/** The current key-value map of phrases. */ | ||
phrases: object; | ||
} | ||
/** | ||
* A component to allow consumption of i18n props from any nested children. | ||
*/ | ||
declare const I18n: React.FC<I18nProps>; | ||
export default I18n; |
@@ -17,2 +17,5 @@ "use strict"; | ||
var i18nContext_1 = __importDefault(require("./i18nContext")); | ||
/** | ||
* A component to allow consumption of i18n props from any nested children. | ||
*/ | ||
var I18n = function (_a) { | ||
@@ -19,0 +22,0 @@ var children = _a.children, locale = _a.locale, phrases = _a.phrases, allowMissing = _a.allowMissing, onMissingKey = _a.onMissingKey, interpolation = _a.interpolation; |
/// <reference types="react" /> | ||
import { tFunction } from './constants'; | ||
/** | ||
* The props provided by I18nContext. | ||
*/ | ||
export interface I18nContextProps { | ||
@@ -7,3 +10,6 @@ locale: string | undefined; | ||
} | ||
/** | ||
* The central store for i18n related components. | ||
*/ | ||
declare const I18nContext: import("react").Context<I18nContextProps>; | ||
export default I18nContext; |
@@ -16,2 +16,5 @@ "use strict"; | ||
} | ||
/** | ||
* The central store for i18n related components. | ||
*/ | ||
var I18nContext = react_1.createContext({ | ||
@@ -18,0 +21,0 @@ locale: undefined, |
import * as React from 'react'; | ||
import { InterpolationOptions } from 'node-polyglot'; | ||
/** | ||
* Props accepted by the T component. | ||
*/ | ||
export interface TProps { | ||
/** A count used for pluralization. */ | ||
count?: number; | ||
/** A fallback phrase to render when the provided key does not resolve. */ | ||
fallback?: string; | ||
/** A key-value map of components or strings to be interpolated. */ | ||
interpolations?: number | InterpolationOptions; | ||
/** The key of the phrase to render. */ | ||
phrase: string; | ||
} | ||
/** | ||
* A component to render a translated string. | ||
*/ | ||
declare const T: React.FC<TProps>; | ||
export default T; |
@@ -19,2 +19,5 @@ "use strict"; | ||
var useT_1 = __importDefault(require("./useT")); | ||
/** | ||
* A component to render a translated string. | ||
*/ | ||
var T = function (_a) { | ||
@@ -28,3 +31,3 @@ var count = _a.count, fallback = _a.fallback, interpolations = _a.interpolations, phrase = _a.phrase; | ||
else { | ||
// TODO: Deprecate number from interpolations in v0.3.0 | ||
// TODO: Deprecate number from interpolations in v0.4.0 | ||
// Handles number interpolation | ||
@@ -31,0 +34,0 @@ cleanInterpolations = { smart_count: interpolations }; |
@@ -0,2 +1,7 @@ | ||
/** | ||
* A hook to consume the current locale. | ||
* | ||
* @returns The current locale. | ||
*/ | ||
declare const useLocale: () => string | undefined; | ||
export default useLocale; |
@@ -8,2 +8,7 @@ "use strict"; | ||
var i18nContext_1 = __importDefault(require("./i18nContext")); | ||
/** | ||
* A hook to consume the current locale. | ||
* | ||
* @returns The current locale. | ||
*/ | ||
var useLocale = function () { | ||
@@ -10,0 +15,0 @@ var locale = react_1.useContext(i18nContext_1.default).locale; |
@@ -1,5 +0,9 @@ | ||
/// <reference path="../src/vendors.d.ts" /> | ||
/// <reference types="node-polyglot" /> | ||
/// <reference types="react" /> | ||
/** | ||
* A hook to consume the t function. | ||
* | ||
* @returns The t function. | ||
*/ | ||
declare const useT: () => (key: string, interpolations?: number | import("node-polyglot").InterpolationOptions | undefined) => import("react").ReactElement<any, string | ((props: any) => import("react").ReactElement<any, string | any | (new (props: any) => import("react").Component<any, any, any>)> | null) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
export default useT; |
@@ -8,2 +8,7 @@ "use strict"; | ||
var i18nContext_1 = __importDefault(require("./i18nContext")); | ||
/** | ||
* A hook to consume the t function. | ||
* | ||
* @returns The t function. | ||
*/ | ||
var useT = function () { | ||
@@ -10,0 +15,0 @@ var t = react_1.useContext(i18nContext_1.default).t; |
{ | ||
"name": "react-polyglot-hooks", | ||
"version": "0.3.0-0", | ||
"version": "0.3.0", | ||
"description": "Hooks for using Polyglot.js with React.", | ||
@@ -60,3 +60,3 @@ "keywords": [ | ||
"@types/node": "^12.7.2", | ||
"@types/node-polyglot": "^0.4.33", | ||
"@types/node-polyglot": "^0.4.34", | ||
"@types/react": "^16.9.0", | ||
@@ -63,0 +63,0 @@ "@types/react-dom": "^16.9.0", |
@@ -85,3 +85,3 @@ # React Polyglot Hooks | ||
That's it! | ||
That's it! For more in-depth examples, check out the [examples](/examples) directory. | ||
@@ -96,3 +96,3 @@ ### Usage with TypeScript | ||
Provides i18n context to the hooks. Accepts all options supported by [Polyglot.js](https://airbnb.io/polyglot.js). | ||
Provides i18n context to the T component and the hooks. Accepts all options supported by [Polyglot.js](https://airbnb.io/polyglot.js). | ||
@@ -116,7 +116,8 @@ #### Props | ||
| Props | Type | Required | Description | | ||
| ---------------- | --------------------------------------- | -------- | --------------------------------------------------- | | ||
| `phrase` | `string` | ✅ | Key of the needed phrase. | | ||
| `fallback` | `string` | ❌ | A fallback to be rendered if the phrase is missing. | | ||
| `interpolations` | `number` or `{ [key: string]: string }` | ❌ | See `InterpolationOptions` below. | | ||
| Props | Type | Required | Description | | ||
| ---------------- | ---------------------- | -------- | --------------------------------------------------- | | ||
| `phrase` | `string` | ✅ | Key of the needed phrase. | | ||
| `count` | `number` | ❌ | A number to be interpolated with `smart_count`. | | ||
| `fallback` | `string` | ❌ | A fallback to be rendered if the phrase is missing. | | ||
| `interpolations` | `InterpolationOptions` | ❌ | See `InterpolationOptions` below. | | ||
@@ -133,6 +134,6 @@ ### `useLocale` | ||
| Param | Type | Required | Description | | ||
| ---------------------- | --------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------- | | ||
| `phrase` | `string` | ✅ | Key of the needed phrase. | | ||
| `InterpolationOptions` | `number` or `{ [key: string]: string }` | ❌ | A number to be interpolated with `smart_count`, or a key-value pair to interpolate values into the phrase. | | ||
| Param | Type | Required | Description | | ||
| ---------------------- | ------------------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------- | | ||
| `phrase` | `string` | ✅ | Key of the needed phrase. | | ||
| `InterpolationOptions` | `number` or `{ [key: string]: ReactNode }` | ❌ | A number to be interpolated with `smart_count`, or a key-value pair to interpolate values into the phrase. | | ||
@@ -152,2 +153,2 @@ For more details, please visit the [documentation](https://airbnb.io/polyglot.js) of Polyglot.js. | ||
This project is a wrapper to ease the use of [Polyglot.js](https://airbnb.io/polyglot.js) within [React](https://reactjs.org/), and is highly influenced by [`react-polyglot`](https://github.com/nayaabkhan/react-polyglot). | ||
This project is developed to ease the use of [Polyglot.js](https://airbnb.io/polyglot.js) within [React](https://reactjs.org/), and is highly influenced by [`react-polyglot`](https://github.com/nayaabkhan/react-polyglot). |
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
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
27688
321
150