@lingui/macro
Advanced tools
Comparing version 3.11.1 to 3.12.0
160
global.d.ts
@@ -1,3 +0,3 @@ | ||
declare module '@lingui/macro' { | ||
import type { MessageDescriptor } from "@lingui/core" | ||
declare module "@lingui/macro" { | ||
import type { MessageDescriptor, I18n } from "@lingui/core" | ||
@@ -9,7 +9,62 @@ export type BasicType = { | ||
/** | ||
* Translates a message descriptor | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t({ | ||
* id: "msg.hello", | ||
* comment: "Greetings at the homepage", | ||
* message: `Hello ${name}`, | ||
* }); | ||
* ``` | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t({ | ||
* id: "msg.plural", | ||
* message: plural(value, { one: "...", other: "..." }), | ||
* }); | ||
* ``` | ||
* | ||
* @param messageDescriptior The descriptor to translate | ||
*/ | ||
export function t(messageDescriptior: MessageDescriptor): string | ||
/** | ||
* Translates a template string using the global I18n instance | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t`Hello ${name}`; | ||
* ``` | ||
*/ | ||
export function t( | ||
literals: TemplateStringsArray | MessageDescriptor, | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): string | ||
/** | ||
* Translates a template string using a given I18n instance | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* import { I18n } from "@lingui/core"; | ||
* const i18n = new I18n({ | ||
* locale: "nl", | ||
* messages: { "Hello {0}": "Hallo {0}" }, | ||
* }); | ||
* const message = t(i18n)`Hello ${name}`; | ||
* ``` | ||
*/ | ||
export function t( | ||
i18n: I18n, | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): string | ||
export type UnderscoreDigit<T = string> = { [digit: string]: T } | ||
@@ -25,16 +80,103 @@ export type ChoiceOptions<T = string> = { | ||
export function plural(arg: number | string, options: ChoiceOptions & BasicType): string | ||
/** | ||
* Pluralize a message | ||
* | ||
* @example | ||
* ``` | ||
* import { plural } from "@lingui/macro"; | ||
* const message = plural(count, { | ||
* one: "# Book", | ||
* other: "# Books", | ||
* }); | ||
* ``` | ||
* | ||
* @param value Determines the plural form | ||
* @param options Object with available plural forms | ||
*/ | ||
export function plural( | ||
value: number | string, | ||
options: ChoiceOptions & BasicType | ||
): string | ||
/** | ||
* Pluralize a message using ordinal forms | ||
* | ||
* Similar to `plural` but instead of using cardinal plural forms, | ||
* it uses ordinal forms. | ||
* | ||
* @example | ||
* ``` | ||
* import { selectOrdinal } from "@lingui/macro"; | ||
* const message = selectOrdinal(count, { | ||
* one: "1st", | ||
* two: "2nd", | ||
* few: "3rd", | ||
* other: "#th", | ||
* }); | ||
* ``` | ||
* | ||
* @param value Determines the plural form | ||
* @param options Object with available plural forms | ||
*/ | ||
export function selectOrdinal( | ||
arg: number | string, | ||
value: number | string, | ||
options: ChoiceOptions & BasicType | ||
): string | ||
export function select(arg: string, choices: Record<string, string> & BasicType): string | ||
/** | ||
* Selects a translation based on a value | ||
* | ||
* Select works like a switch statement. It will | ||
* select one of the forms in `options` object which | ||
* key matches exactly `value`. | ||
* | ||
* @example | ||
* ``` | ||
* import { select } from "@lingui/macro"; | ||
* const message = select(gender, { | ||
* male: "he", | ||
* female: "she", | ||
* other: "they", | ||
* }); | ||
* ``` | ||
* | ||
* @param value The key of choices to use | ||
* @param choices | ||
*/ | ||
export function select( | ||
value: string, | ||
choices: Record<string, string> & BasicType | ||
): string | ||
/** | ||
* Defines multiple messages for extraction | ||
*/ | ||
export function defineMessages<M extends Record<string, MessageDescriptor>>( | ||
messages: M | ||
): M | ||
export function defineMessage(descriptor: MessageDescriptor): MessageDescriptor | ||
/** | ||
* Define a message for later use | ||
* | ||
* `defineMessage` can be used to add comments for translators, | ||
* or to override the message ID. | ||
* | ||
* @example | ||
* ``` | ||
* import { defineMessage } from "@lingui/macro"; | ||
* const message = defineMessage({ | ||
* comment: "Greetings on the welcome page", | ||
* message: `Welcome, ${name}!`, | ||
* }); | ||
* ``` | ||
* | ||
* @param descriptor The message descriptor | ||
*/ | ||
export function defineMessage( | ||
descriptor: MessageDescriptor | ||
): MessageDescriptor | ||
export type ChoiceProps = { | ||
value?: string | number | ||
} & ChoiceOptions<string> | ||
} & ChoiceOptions<string> | ||
@@ -65,2 +207,2 @@ /** | ||
export const SelectOrdinal: any | ||
} | ||
} |
154
index.d.ts
import type { ReactElement, ComponentType, ReactNode } from "react" | ||
import type { MessageDescriptor } from "@lingui/core" | ||
import type { MessageDescriptor, I18n } from "@lingui/core" | ||
import type { TransRenderProps } from "@lingui/react" | ||
export function t( | ||
literals: TemplateStringsArray | MessageDescriptor, | ||
...placeholders: any[] | ||
): string | ||
export type UnderscoreDigit<T = string> = { [digit: string]: T } | ||
@@ -20,11 +15,152 @@ export type ChoiceOptions<T = string> = { | ||
export function plural(arg: number | string, options: ChoiceOptions): string | ||
/** | ||
* Translates a message descriptor | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t({ | ||
* id: "msg.hello", | ||
* comment: "Greetings at the homepage", | ||
* message: `Hello ${name}`, | ||
* }); | ||
* ``` | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t({ | ||
* id: "msg.plural", | ||
* message: plural(value, { one: "...", other: "..." }), | ||
* }); | ||
* ``` | ||
* | ||
* @param messageDescriptior The descriptor to translate | ||
*/ | ||
export function t(messageDescriptior: MessageDescriptor): string | ||
/** | ||
* Translates a template string using the global I18n instance | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* const message = t`Hello ${name}`; | ||
* ``` | ||
*/ | ||
export function t( | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): string | ||
/** | ||
* Translates a template string using a given I18n instance | ||
* | ||
* @example | ||
* ``` | ||
* import { t } from "@lingui/macro"; | ||
* import { I18n } from "@lingui/core"; | ||
* const i18n = new I18n({ | ||
* locale: "nl", | ||
* messages: { "Hello {0}": "Hallo {0}" }, | ||
* }); | ||
* const message = t(i18n)`Hello ${name}`; | ||
* ``` | ||
*/ | ||
export function t( | ||
i18n: I18n, | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): string | ||
/** | ||
* Pluralize a message | ||
* | ||
* @example | ||
* ``` | ||
* import { plural } from "@lingui/macro"; | ||
* const message = plural(count, { | ||
* one: "# Book", | ||
* other: "# Books", | ||
* }); | ||
* ``` | ||
* | ||
* @param value Determines the plural form | ||
* @param options Object with available plural forms | ||
*/ | ||
export function plural(value: number | string, options: ChoiceOptions): string | ||
/** | ||
* Pluralize a message using ordinal forms | ||
* | ||
* Similar to `plural` but instead of using cardinal plural forms, | ||
* it uses ordinal forms. | ||
* | ||
* @example | ||
* ``` | ||
* import { selectOrdinal } from "@lingui/macro"; | ||
* const message = selectOrdinal(count, { | ||
* one: "1st", | ||
* two: "2nd", | ||
* few: "3rd", | ||
* other: "#th", | ||
* }); | ||
* ``` | ||
* | ||
* @param value Determines the plural form | ||
* @param options Object with available plural forms | ||
*/ | ||
export function selectOrdinal( | ||
arg: number | string, | ||
value: number | string, | ||
options: ChoiceOptions | ||
): string | ||
export function select(arg: string, choices: Record<string, string>): string | ||
/** | ||
* Selects a translation based on a value | ||
* | ||
* Select works like a switch statement. It will | ||
* select one of the forms in `options` object which | ||
* key matches exactly `value`. | ||
* | ||
* @example | ||
* ``` | ||
* import { select } from "@lingui/macro"; | ||
* const message = select(gender, { | ||
* male: "he", | ||
* female: "she", | ||
* other: "they", | ||
* }); | ||
* ``` | ||
* | ||
* @param value The key of choices to use | ||
* @param choices | ||
*/ | ||
export function select(value: string, choices: ChoiceOptions): string | ||
/** | ||
* Defines multiple messages for extraction | ||
* | ||
* @see {@link defineMessage} for more details | ||
*/ | ||
export function defineMessages<M extends Record<string, MessageDescriptor>>( | ||
messages: M | ||
): M | ||
/** | ||
* Define a message for later use | ||
* | ||
* `defineMessage` can be used to add comments for translators, | ||
* or to override the message ID. | ||
* | ||
* @example | ||
* ``` | ||
* import { defineMessage } from "@lingui/macro"; | ||
* const message = defineMessage({ | ||
* comment: "Greetings on the welcome page", | ||
* message: `Welcome, ${name}!`, | ||
* }); | ||
* ``` | ||
* | ||
* @param descriptor The message descriptor | ||
*/ | ||
export function defineMessage(descriptor: MessageDescriptor): MessageDescriptor | ||
@@ -31,0 +167,0 @@ |
@@ -58,2 +58,3 @@ "use strict"; | ||
var jsNodes = []; | ||
var needsI18nImport = false; | ||
Object.keys(references).forEach(function (tagName) { | ||
@@ -83,3 +84,3 @@ var nodes = references[tagName]; | ||
}); | ||
macro.replacePath(path); | ||
if (macro.replacePath(path)) needsI18nImport = true; | ||
}); | ||
@@ -92,3 +93,3 @@ jsxNodes.filter(isRootPath(jsxNodes)).forEach(function (path) { | ||
if (jsNodes.length) { | ||
if (needsI18nImport) { | ||
addImport(babel, state, i18nImportModule, i18nImportName); | ||
@@ -95,0 +96,0 @@ } |
@@ -56,3 +56,3 @@ "use strict"; | ||
(0, _defineProperty2.default)(this, "_expressionIndex", void 0); | ||
(0, _defineProperty2.default)(this, "replacePathWithMessage", function (path, _ref3) { | ||
(0, _defineProperty2.default)(this, "replacePathWithMessage", function (path, _ref3, linguiInstance) { | ||
var id = _ref3.id, | ||
@@ -91,3 +91,3 @@ message = _ref3.message, | ||
var newNode = _this.types.callExpression(_this.types.memberExpression(_this.types.identifier(_this.i18nImportName), _this.types.identifier("_")), args); // preserve line number | ||
var newNode = _this.types.callExpression(_this.types.memberExpression(linguiInstance !== null && linguiInstance !== void 0 ? linguiInstance : _this.types.identifier(_this.i18nImportName), _this.types.identifier("_")), args); // preserve line number | ||
@@ -107,3 +107,30 @@ | ||
return; | ||
return true; | ||
} // t(i18nInstance)`Message` -> i18nInstance._('Message') | ||
if (_this.types.isCallExpression(path.node) && _this.types.isTaggedTemplateExpression(path.parentPath.node) && _this.types.isIdentifier(path.node.arguments[0]) && _this.isIdentifier(path.node.callee, "t")) { | ||
// Use the first argument as i18n instance instead of the default i18n instance | ||
var i18nInstance = path.node.arguments[0]; | ||
var _tokens = _this.tokenizeNode(path.parentPath.node); | ||
var _messageFormat = new _icu.default(); | ||
var _messageFormat$fromTo = _messageFormat.fromTokens(_tokens), | ||
_messageRaw = _messageFormat$fromTo.message, | ||
_values = _messageFormat$fromTo.values, | ||
_id = _messageFormat$fromTo.id, | ||
_comment = _messageFormat$fromTo.comment; | ||
var _message = normalizeWhitespace(_messageRaw); | ||
_this.replacePathWithMessage(path.parentPath, { | ||
id: _id, | ||
message: _message, | ||
values: _values, | ||
comment: _comment | ||
}, i18nInstance); | ||
return false; | ||
} | ||
@@ -114,3 +141,3 @@ | ||
return; | ||
return true; | ||
} | ||
@@ -122,7 +149,7 @@ | ||
var _messageFormat$fromTo = messageFormat.fromTokens(tokens), | ||
messageRaw = _messageFormat$fromTo.message, | ||
values = _messageFormat$fromTo.values, | ||
id = _messageFormat$fromTo.id, | ||
comment = _messageFormat$fromTo.comment; | ||
var _messageFormat$fromTo2 = messageFormat.fromTokens(tokens), | ||
messageRaw = _messageFormat$fromTo2.message, | ||
values = _messageFormat$fromTo2.values, | ||
id = _messageFormat$fromTo2.id, | ||
comment = _messageFormat$fromTo2.comment; | ||
@@ -137,2 +164,4 @@ var message = normalizeWhitespace(messageRaw); | ||
}); | ||
return true; | ||
}); | ||
@@ -175,5 +204,5 @@ (0, _defineProperty2.default)(this, "replaceDefineMessage", function (path) { | ||
var _messageFormat$fromTo2 = messageFormat.fromTokens(tokens), | ||
messageRaw = _messageFormat$fromTo2.message, | ||
values = _messageFormat$fromTo2.values; | ||
var _messageFormat$fromTo3 = messageFormat.fromTokens(tokens), | ||
messageRaw = _messageFormat$fromTo3.message, | ||
values = _messageFormat$fromTo3.values; | ||
@@ -180,0 +209,0 @@ var message = normalizeWhitespace(messageRaw); |
{ | ||
"name": "@lingui/macro", | ||
"version": "3.11.1", | ||
"version": "3.12.0", | ||
"description": "Macro for generating messages in ICU MessageFormat syntax", | ||
@@ -33,3 +33,3 @@ "main": "index.js", | ||
"@babel/runtime": "^7.11.2", | ||
"@lingui/conf": "^3.11.1", | ||
"@lingui/conf": "^3.12.0", | ||
"ramda": "^0.27.1" | ||
@@ -36,0 +36,0 @@ }, |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
54588
1259
5
Updated@lingui/conf@^3.12.0