From e3a6ed1ecc8e633f1f159cb198167f9cbe1d419c Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Mon, 7 Oct 2024 15:46:51 +0500 Subject: [PATCH 1/8] fix: fix logging in i18n v4 --- CHANGELOG.md | 8 +++++ package.json | 2 +- src/core/prelude/CHANGELOG.md | 7 ++++ src/core/prelude/i18n/helpers.ts | 57 ++++++++++++++++++------------ src/core/prelude/i18n/interface.ts | 5 +++ src/core/prelude/i18n/spec.ts | 11 ++++++ 6 files changed, 67 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b575ba3a..7d01ef31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ Changelog _Note: Gaps between patch versions are faulty, broken or test releases._ +## v4.0.0-alpha.48.speedup (2024-10-07) + +#### :bug: Bug Fix + +* `core/prelude/i18n/helpers` + * Fix logging bug in `pluralizeText`. + * Add logging info in i18n helpers. + ## v4.0.0-alpha.47.speedup (2024-10-01) #### :boom: Breaking Change diff --git a/package.json b/package.json index 79ba37eed..0f5465669 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/core/index.js", "typings": "index.d.ts", "license": "MIT", - "version": "4.0.0-alpha.47.speedup", + "version": "4.0.0-alpha.48.speedup", "author": "kobezzza (https://github.com/kobezzza)", "repository": { "type": "git", diff --git a/src/core/prelude/CHANGELOG.md b/src/core/prelude/CHANGELOG.md index 096c16542..19a14b5f4 100644 --- a/src/core/prelude/CHANGELOG.md +++ b/src/core/prelude/CHANGELOG.md @@ -9,6 +9,13 @@ Changelog > - :house: [Internal] > - :nail_care: [Polish] +## v4.0.0-alpha.48.speedup (2024-10-07) + +#### :bug: Bug Fix + +* Fix logging bug in `pluralizeText`. +* Add logging info in i18n helpers. + ## v4.0.0-alpha.47.speedup (2024-10-01) #### :rocket: New Feature diff --git a/src/core/prelude/i18n/helpers.ts b/src/core/prelude/i18n/helpers.ts index 2d125642d..e5ef79980 100644 --- a/src/core/prelude/i18n/helpers.ts +++ b/src/core/prelude/i18n/helpers.ts @@ -11,7 +11,7 @@ import log from 'core/log'; import langPacs, { Translation, PluralTranslation } from 'lang'; import { locale } from 'core/prelude/i18n/const'; -import type { I18nOpts, PluralizationCount } from 'core/prelude/i18n/interface'; +import type { I18nOpts, PluralizationCount, I18nMeta } from 'core/prelude/i18n/interface'; const logger = log.namespace('i18n'); @@ -50,18 +50,19 @@ export function i18nFactory( const key = Object.isString(value) ? value : value[0], correctKeyset = keysetNames.find((keysetName) => langPacs[resolvedLocale]?.[keysetName]?.[key]), - translateValue = langPacs[resolvedLocale]?.[correctKeyset ?? '']?.[key]; + translateValue = langPacs[resolvedLocale]?.[correctKeyset ?? '']?.[key], + meta: I18nMeta = {language: resolvedLocale, keysets: keysetNames.join(', ')}; if (translateValue != null && translateValue !== '') { - return resolveTemplate(translateValue, params, {pluralRules}); + return resolveTemplate(translateValue, params, {pluralRules}, meta); } logger.error( 'Translation for the given key is not found', - `Key: ${key}, KeysetNames: ${keysetNames.join(', ')}, LocaleName: ${resolvedLocale}, available locales: ${Object.keys(langPacs).join(', ')}` + `Key: ${key}, KeysetNames: ${meta.keysets}, LocaleName: ${resolvedLocale}, available locales: ${Object.keys(langPacs).join(', ')}` ); - return resolveTemplate(key, params, {pluralRules}); + return resolveTemplate(key, params, {pluralRules}, meta); }; } @@ -70,6 +71,8 @@ export function i18nFactory( * * @param value - a string for the default case, or an array of strings for the plural case * @param params - a dictionary with parameters for internationalization + * @params [opts] = I18n options for current translation + * @param [meta] - I18n meta information about current translation * * @example * ```typescript @@ -77,19 +80,19 @@ export function i18nFactory( * * console.log(example); // 'My name is John, I live in Denver' * - * const examplePluralize = resolveTemplate([ - * {count} product, // One - * {count} products, // Some - * {count} products, // Many - * {count} products, // None - * ], {count: 5}); + * const examplePluralize = resolveTemplate({ + * one: {count} product, + * few: {count} products, + * many: {count} products, + * zero: {count} products, + * }, {count: 5}); * * console.log(examplePluralize); // '5 products' * ``` */ -export function resolveTemplate(value: Translation, params?: I18nParams, opts: I18nOpts = {}): string { +export function resolveTemplate(value: Translation, params?: I18nParams, opts: I18nOpts = {}, meta?: I18nMeta): string { const - template = Object.isPlainObject(value) ? pluralizeText(value, params?.count, opts.pluralRules) : value; + template = Object.isPlainObject(value) ? pluralizeText(value, params?.count, opts.pluralRules, meta) : value; return template.replace(/{([^}]+)}/g, (_, key) => { if (params?.[key] == null) { @@ -109,12 +112,13 @@ export function resolveTemplate(value: Translation, params?: I18nParams, opts: I * * @example * ```typescript - * const result = pluralizeText([ - * {count} product, // One - * {count} products, // Some - * {count} products, // Many - * {count} products, // None - * ], 5); + * const result = pluralizeText({ + * one: {count} product, + * few: {count} products, + * many: {count} products, + * zero: {count} products, + * other: {count} products, + * }, 5, new Intl.PluralRulse('en')); * * console.log(result); // '{count} products' * ``` @@ -122,7 +126,8 @@ export function resolveTemplate(value: Translation, params?: I18nParams, opts: I export function pluralizeText( pluralTranslation: PluralTranslation, count: CanUndef, - rules: CanUndef + rules: CanUndef, + meta?: I18nMeta ): string { let normalizedCount; @@ -138,7 +143,11 @@ export function pluralizeText( } if (normalizedCount == null) { - logger.error('Invalid value of the `count` parameter for string pluralization', `String: ${pluralTranslation[0]}`); + logger.error( + 'Invalid value of the `count` parameter for string pluralization', + `String: ${pluralTranslation.one}, Keysets: ${meta?.keysets}, Language: ${meta?.language}` + ); + normalizedCount = 1; } @@ -147,7 +156,11 @@ export function pluralizeText( translation = pluralTranslation[pluralFormName]; if (translation == null) { - logger.error(`Plural form ${pluralFormName} doesn't exist.`, `String: ${pluralTranslation[0]}`); + logger.error( + 'Invalid value of the `count` parameter for string pluralization', + `String: ${pluralTranslation.one}, Keysets: ${meta?.keysets}, Language: ${meta?.language}` + ); + return pluralTranslation.one; } diff --git a/src/core/prelude/i18n/interface.ts b/src/core/prelude/i18n/interface.ts index 9981d87ae..64de75e53 100644 --- a/src/core/prelude/i18n/interface.ts +++ b/src/core/prelude/i18n/interface.ts @@ -46,3 +46,8 @@ export type PluralizationCount = StringPluralizationForms | number; export interface I18nOpts { pluralRules?: Intl.PluralRules; } + +export interface I18nMeta { + language: string; + keysets: string; +} diff --git a/src/core/prelude/i18n/spec.ts b/src/core/prelude/i18n/spec.ts index 69cd3b5cb..7a77e3c7e 100644 --- a/src/core/prelude/i18n/spec.ts +++ b/src/core/prelude/i18n/spec.ts @@ -56,6 +56,17 @@ describe('core/prelude/i18n', () => { expect(pluralizeText(input.forms, input.count[index], rules)).toBe(form); }); }); + + it('return one form if correct form does not exists', () => { + const input = { + forms, + count: [1, 2, 100, 0] + }; + + [forms.one, forms.one, forms.one, forms.one].forEach((form, index) => { + expect(pluralizeText({one: input.forms.one}, input.count[index], rules)).toBe(form); + }); + }); }); describe('substitution of variables and pluralization forms in a template', () => { From 5bb16d7f710ce57ff36c365b9c8a607f5d984047 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Mon, 7 Oct 2024 17:00:47 +0500 Subject: [PATCH 2/8] change logging info --- src/core/prelude/i18n/helpers.ts | 10 +++++----- src/core/prelude/i18n/interface.ts | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/prelude/i18n/helpers.ts b/src/core/prelude/i18n/helpers.ts index e5ef79980..6922e9058 100644 --- a/src/core/prelude/i18n/helpers.ts +++ b/src/core/prelude/i18n/helpers.ts @@ -51,7 +51,7 @@ export function i18nFactory( key = Object.isString(value) ? value : value[0], correctKeyset = keysetNames.find((keysetName) => langPacs[resolvedLocale]?.[keysetName]?.[key]), translateValue = langPacs[resolvedLocale]?.[correctKeyset ?? '']?.[key], - meta: I18nMeta = {language: resolvedLocale, keysets: keysetNames.join(', ')}; + meta: I18nMeta = {language: resolvedLocale, keyset: correctKeyset, key}; if (translateValue != null && translateValue !== '') { return resolveTemplate(translateValue, params, {pluralRules}, meta); @@ -59,7 +59,7 @@ export function i18nFactory( logger.error( 'Translation for the given key is not found', - `Key: ${key}, KeysetNames: ${meta.keysets}, LocaleName: ${resolvedLocale}, available locales: ${Object.keys(langPacs).join(', ')}` + `Key: ${key}, KeysetNames: ${keysetNames.join(', ')}, LocaleName: ${resolvedLocale}, available locales: ${Object.keys(langPacs).join(', ')}` ); return resolveTemplate(key, params, {pluralRules}, meta); @@ -145,7 +145,7 @@ export function pluralizeText( if (normalizedCount == null) { logger.error( 'Invalid value of the `count` parameter for string pluralization', - `String: ${pluralTranslation.one}, Keysets: ${meta?.keysets}, Language: ${meta?.language}` + `Count: ${count}, Key: ${meta?.key}, Language: ${meta?.language}, Keyset: ${meta?.keyset}` ); normalizedCount = 1; @@ -157,8 +157,8 @@ export function pluralizeText( if (translation == null) { logger.error( - 'Invalid value of the `count` parameter for string pluralization', - `String: ${pluralTranslation.one}, Keysets: ${meta?.keysets}, Language: ${meta?.language}` + `Plural form ${pluralFormName} doesn't exist.`, + `Key: ${meta?.key}, Language: ${meta?.language}, Keyset: ${meta?.keyset}` ); return pluralTranslation.one; diff --git a/src/core/prelude/i18n/interface.ts b/src/core/prelude/i18n/interface.ts index 64de75e53..d7a8e484f 100644 --- a/src/core/prelude/i18n/interface.ts +++ b/src/core/prelude/i18n/interface.ts @@ -49,5 +49,6 @@ export interface I18nOpts { export interface I18nMeta { language: string; - keysets: string; + key: string; + keyset?: string; } From b7c8a832dae6a3bb3b396369a3dc0ec5eb33e6b9 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Tue, 8 Oct 2024 14:46:27 +0500 Subject: [PATCH 3/8] refactor i18n helpers --- src/core/prelude/i18n/helpers.ts | 21 +++++++++++---------- src/core/prelude/i18n/interface.ts | 10 ++++++---- src/core/prelude/i18n/spec.ts | 6 +++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/core/prelude/i18n/helpers.ts b/src/core/prelude/i18n/helpers.ts index 6922e9058..f7edbfc52 100644 --- a/src/core/prelude/i18n/helpers.ts +++ b/src/core/prelude/i18n/helpers.ts @@ -54,7 +54,7 @@ export function i18nFactory( meta: I18nMeta = {language: resolvedLocale, keyset: correctKeyset, key}; if (translateValue != null && translateValue !== '') { - return resolveTemplate(translateValue, params, {pluralRules}, meta); + return resolveTemplate(translateValue, params, {pluralRules, meta}); } logger.error( @@ -62,7 +62,7 @@ export function i18nFactory( `Key: ${key}, KeysetNames: ${keysetNames.join(', ')}, LocaleName: ${resolvedLocale}, available locales: ${Object.keys(langPacs).join(', ')}` ); - return resolveTemplate(key, params, {pluralRules}, meta); + return resolveTemplate(key, params, {pluralRules, meta}); }; } @@ -71,8 +71,7 @@ export function i18nFactory( * * @param value - a string for the default case, or an array of strings for the plural case * @param params - a dictionary with parameters for internationalization - * @params [opts] = I18n options for current translation - * @param [meta] - I18n meta information about current translation + * @params [opts] - additional options for current translation * * @example * ```typescript @@ -90,9 +89,9 @@ export function i18nFactory( * console.log(examplePluralize); // '5 products' * ``` */ -export function resolveTemplate(value: Translation, params?: I18nParams, opts: I18nOpts = {}, meta?: I18nMeta): string { +export function resolveTemplate(value: Translation, params?: I18nParams, opts: I18nOpts = {}): string { const - template = Object.isPlainObject(value) ? pluralizeText(value, params?.count, opts.pluralRules, meta) : value; + template = Object.isPlainObject(value) ? pluralizeText(value, params?.count, opts) : value; return template.replace(/{([^}]+)}/g, (_, key) => { if (params?.[key] == null) { @@ -109,6 +108,7 @@ export function resolveTemplate(value: Translation, params?: I18nParams, opts: I * * @param pluralTranslation - list of translation variants * @param count - the value on the basis of which the form of pluralization will be selected + * @params [opts] - additional options for current translation * * @example * ```typescript @@ -118,7 +118,7 @@ export function resolveTemplate(value: Translation, params?: I18nParams, opts: I * many: {count} products, * zero: {count} products, * other: {count} products, - * }, 5, new Intl.PluralRulse('en')); + * }, 5, {pluralRules: new Intl.PluralRulse('en')}); * * console.log(result); // '{count} products' * ``` @@ -126,9 +126,10 @@ export function resolveTemplate(value: Translation, params?: I18nParams, opts: I export function pluralizeText( pluralTranslation: PluralTranslation, count: CanUndef, - rules: CanUndef, - meta?: I18nMeta + opts: I18nOpts = {} ): string { + const {pluralRules, meta} = opts; + let normalizedCount; if (Object.isNumber(count)) { @@ -152,7 +153,7 @@ export function pluralizeText( } const - pluralFormName = getPluralFormName(normalizedCount, rules), + pluralFormName = getPluralFormName(normalizedCount, pluralRules), translation = pluralTranslation[pluralFormName]; if (translation == null) { diff --git a/src/core/prelude/i18n/interface.ts b/src/core/prelude/i18n/interface.ts index d7a8e484f..fe97cbd39 100644 --- a/src/core/prelude/i18n/interface.ts +++ b/src/core/prelude/i18n/interface.ts @@ -43,12 +43,14 @@ export interface LocaleKVStorage { export type PluralizationCount = StringPluralizationForms | number; -export interface I18nOpts { - pluralRules?: Intl.PluralRules; -} - export interface I18nMeta { language: string; key: string; keyset?: string; } + +export interface I18nOpts { + pluralRules?: Intl.PluralRules; + meta?: I18nMeta; +} + diff --git a/src/core/prelude/i18n/spec.ts b/src/core/prelude/i18n/spec.ts index 7a77e3c7e..8383f926b 100644 --- a/src/core/prelude/i18n/spec.ts +++ b/src/core/prelude/i18n/spec.ts @@ -42,7 +42,7 @@ describe('core/prelude/i18n', () => { describe('text pluralization', () => { it('using pluralization constants to choose the right form', () => { formNames.forEach((form) => { - expect(pluralizeText(forms, form, rules)).toBe(forms[form]); + expect(pluralizeText(forms, form, {pluralRules: rules})).toBe(forms[form]); }); }); @@ -53,7 +53,7 @@ describe('core/prelude/i18n', () => { }; [forms.one, forms.other, forms.other, forms.other].forEach((form, index) => { - expect(pluralizeText(input.forms, input.count[index], rules)).toBe(form); + expect(pluralizeText(input.forms, input.count[index], {pluralRules: rules})).toBe(form); }); }); @@ -64,7 +64,7 @@ describe('core/prelude/i18n', () => { }; [forms.one, forms.one, forms.one, forms.one].forEach((form, index) => { - expect(pluralizeText({one: input.forms.one}, input.count[index], rules)).toBe(form); + expect(pluralizeText({one: input.forms.one}, input.count[index], {pluralRules: rules})).toBe(form); }); }); }); From 3c32716785c4dbbf89fbc51482cbd28a39cf13db Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Thu, 10 Oct 2024 15:44:04 +0500 Subject: [PATCH 4/8] add test and change readme --- src/core/prelude/i18n/README.md | 28 +++++++++++++++------------- src/core/prelude/i18n/spec.ts | 10 ++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/core/prelude/i18n/README.md b/src/core/prelude/i18n/README.md index 25443469c..48bc24b0d 100644 --- a/src/core/prelude/i18n/README.md +++ b/src/core/prelude/i18n/README.md @@ -89,30 +89,32 @@ i18n('my-component')('My name is {name}', {name: 'John'}); ## Pluralization of translations Some keys may have multiple translations depending on some numeric value. For example, "1 apple" or "5 apples". -To specify such translations, a special macro `{count}` is used, and translations are specified as a tuple `[one, some, many, none]`. +To specify such translations, a special macro `{count}` is used, and translations are specified as a tuple `[zero, one, two, few, many, other]`. ```js export default { ru: { "my-component": { "time": "время", - "{count} product": [ - "{count} продукт", - "{count} продукта", - "{count} продуктов", - "{count} продуктов" - ] + "{count} product": { + "one": "{count} product", + "few": "{count} products", + "many": "{count} products", + "zero": "{count} products", + "other": "{count} products", + } } }, en: { "my-component": { - "{count} product": [ - "{count} product", - "{count} products", - "{count} products", - "{count} products" - ] + "{count} product": { + "one": "{count} product", + "few": "{count} products", + "many": "{count} products", + "zero": "{count} products", + "other": "{count} products", + } } } }; diff --git a/src/core/prelude/i18n/spec.ts b/src/core/prelude/i18n/spec.ts index 8383f926b..aa0602f0d 100644 --- a/src/core/prelude/i18n/spec.ts +++ b/src/core/prelude/i18n/spec.ts @@ -67,6 +67,16 @@ describe('core/prelude/i18n', () => { expect(pluralizeText({one: input.forms.one}, input.count[index], {pluralRules: rules})).toBe(form); }); }); + + it('return one form if incorrect count was passed', () => { + const input = { + forms + }; + + [forms.one, forms.one, forms.one, forms.one].forEach((form) => { + expect(pluralizeText({one: input.forms.one}, undefined, {pluralRules: rules})).toBe(form); + }); + }); }); describe('substitution of variables and pluralization forms in a template', () => { From 214cd2e21d0eec76fe183a59079af3f7adb41ff2 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Thu, 10 Oct 2024 16:27:04 +0500 Subject: [PATCH 5/8] changelog --- CHANGELOG.md | 8 ++++++++ src/core/prelude/CHANGELOG.md | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d01ef31a..acae802ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ Changelog _Note: Gaps between patch versions are faulty, broken or test releases._ +## v4.0.0-alpha.??.speedup (2024-10-??) + +#### :bug: Bug Fix + +* `core/prelude/i18n/helpers` + * Fix logging bug in `pluralizeText`. + * Add logging info in i18n helpers. + ## v4.0.0-alpha.48.speedup (2024-10-07) #### :bug: Bug Fix diff --git a/src/core/prelude/CHANGELOG.md b/src/core/prelude/CHANGELOG.md index 19a14b5f4..3effd2a66 100644 --- a/src/core/prelude/CHANGELOG.md +++ b/src/core/prelude/CHANGELOG.md @@ -9,6 +9,13 @@ Changelog > - :house: [Internal] > - :nail_care: [Polish] +## v4.0.0-alpha.??.speedup (2024-10-??) + +#### :bug: Bug Fix + +* Fix logging bug in `pluralizeText`. +* Add logging info in i18n helpers. + ## v4.0.0-alpha.48.speedup (2024-10-07) #### :bug: Bug Fix From b109d8f11aa99b0c014c16d8cc7d54216fe06682 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Thu, 10 Oct 2024 16:28:18 +0500 Subject: [PATCH 6/8] changelog --- CHANGELOG.md | 8 -------- src/core/prelude/CHANGELOG.md | 7 ------- 2 files changed, 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acae802ab..100f91d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,14 +15,6 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ #### :bug: Bug Fix -* `core/prelude/i18n/helpers` - * Fix logging bug in `pluralizeText`. - * Add logging info in i18n helpers. - -## v4.0.0-alpha.48.speedup (2024-10-07) - -#### :bug: Bug Fix - * `core/prelude/i18n/helpers` * Fix logging bug in `pluralizeText`. * Add logging info in i18n helpers. diff --git a/src/core/prelude/CHANGELOG.md b/src/core/prelude/CHANGELOG.md index 3effd2a66..aec67fb69 100644 --- a/src/core/prelude/CHANGELOG.md +++ b/src/core/prelude/CHANGELOG.md @@ -16,13 +16,6 @@ Changelog * Fix logging bug in `pluralizeText`. * Add logging info in i18n helpers. -## v4.0.0-alpha.48.speedup (2024-10-07) - -#### :bug: Bug Fix - -* Fix logging bug in `pluralizeText`. -* Add logging info in i18n helpers. - ## v4.0.0-alpha.47.speedup (2024-10-01) #### :rocket: New Feature From 4e93f073a9b6157675c5fd496bc4da04b18f5e70 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Mon, 28 Oct 2024 12:19:31 +0500 Subject: [PATCH 7/8] fix review --- CHANGELOG.md | 2 +- package.json | 2 +- src/core/prelude/CHANGELOG.md | 2 +- src/core/prelude/i18n/README.md | 2 +- src/core/prelude/i18n/spec.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 100f91d0f..3aa25f38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Changelog _Note: Gaps between patch versions are faulty, broken or test releases._ -## v4.0.0-alpha.??.speedup (2024-10-??) +## v4.0.0-alpha.?? (2024-10-??) #### :bug: Bug Fix diff --git a/package.json b/package.json index 0f5465669..1d7a0dee0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/core/index.js", "typings": "index.d.ts", "license": "MIT", - "version": "4.0.0-alpha.48.speedup", + "version": "4.0.0-alpha.48", "author": "kobezzza (https://github.com/kobezzza)", "repository": { "type": "git", diff --git a/src/core/prelude/CHANGELOG.md b/src/core/prelude/CHANGELOG.md index aec67fb69..a4abb8b7a 100644 --- a/src/core/prelude/CHANGELOG.md +++ b/src/core/prelude/CHANGELOG.md @@ -9,7 +9,7 @@ Changelog > - :house: [Internal] > - :nail_care: [Polish] -## v4.0.0-alpha.??.speedup (2024-10-??) +## v4.0.0-alpha.?? (2024-10-??) #### :bug: Bug Fix diff --git a/src/core/prelude/i18n/README.md b/src/core/prelude/i18n/README.md index 48bc24b0d..ff58239f8 100644 --- a/src/core/prelude/i18n/README.md +++ b/src/core/prelude/i18n/README.md @@ -89,7 +89,7 @@ i18n('my-component')('My name is {name}', {name: 'John'}); ## Pluralization of translations Some keys may have multiple translations depending on some numeric value. For example, "1 apple" or "5 apples". -To specify such translations, a special macro `{count}` is used, and translations are specified as a tuple `[zero, one, two, few, many, other]`. +To specify such translations, a special macro `{count}` is used, and translations are specified as a dictionary `{zero, one, two, few, many, other}`. ```js export default { diff --git a/src/core/prelude/i18n/spec.ts b/src/core/prelude/i18n/spec.ts index aa0602f0d..07caa75f8 100644 --- a/src/core/prelude/i18n/spec.ts +++ b/src/core/prelude/i18n/spec.ts @@ -57,7 +57,7 @@ describe('core/prelude/i18n', () => { }); }); - it('return one form if correct form does not exists', () => { + it('returns "one" form when required plural form is missing', () => { const input = { forms, count: [1, 2, 100, 0] From 03c79762926a82678ff727d0cb6abb5d266bc892 Mon Sep 17 00:00:00 2001 From: Maksim Sinelnikov Date: Tue, 29 Oct 2024 23:37:09 +0500 Subject: [PATCH 8/8] rename test --- CHANGELOG.md | 2 +- src/core/prelude/CHANGELOG.md | 2 +- src/core/prelude/i18n/spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aa25f38a..857b9f825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Changelog _Note: Gaps between patch versions are faulty, broken or test releases._ -## v4.0.0-alpha.?? (2024-10-??) +## v4.0.0-alpha.48 (2024-10-??) #### :bug: Bug Fix diff --git a/src/core/prelude/CHANGELOG.md b/src/core/prelude/CHANGELOG.md index a4abb8b7a..834fbe47a 100644 --- a/src/core/prelude/CHANGELOG.md +++ b/src/core/prelude/CHANGELOG.md @@ -9,7 +9,7 @@ Changelog > - :house: [Internal] > - :nail_care: [Polish] -## v4.0.0-alpha.?? (2024-10-??) +## v4.0.0-alpha.48 (2024-10-??) #### :bug: Bug Fix diff --git a/src/core/prelude/i18n/spec.ts b/src/core/prelude/i18n/spec.ts index 07caa75f8..e28c1bb8e 100644 --- a/src/core/prelude/i18n/spec.ts +++ b/src/core/prelude/i18n/spec.ts @@ -68,7 +68,7 @@ describe('core/prelude/i18n', () => { }); }); - it('return one form if incorrect count was passed', () => { + it('returns "one" form when count is invalid', () => { const input = { forms };