diff --git a/packages/i18n/src/__tests__/utils.test.ts b/packages/i18n/src/__tests__/utils.test.ts index 21477224..e3ef657e 100644 --- a/packages/i18n/src/__tests__/utils.test.ts +++ b/packages/i18n/src/__tests__/utils.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; import { ChromeMessage } from '../build'; -import { applyChromeMessagePlaceholders, getSubstitionCount } from '../utils'; +import { applyChromeMessagePlaceholders, getSubstitutionCount } from '../utils'; describe('Utils', () => { describe('applyChromeMessagePlaceholders', () => { @@ -38,26 +38,26 @@ describe('Utils', () => { }); }); - describe('getSubstitionCount', () => { + describe('getSubstitutionCount', () => { it('should return the last substution present in the message', () => { - expect(getSubstitionCount('I like $1, but I like $2 better')).toBe(2); + expect(getSubstitutionCount('I like $1, but I like $2 better')).toBe(2); }); it('should return 0 when no substitutions are present', () => { - expect(getSubstitionCount('test')).toBe(0); + expect(getSubstitutionCount('test')).toBe(0); }); it('should ignore escaped dollar signs', () => { - expect(getSubstitionCount('buy $1 now for $$2 dollars')).toBe(1); + expect(getSubstitutionCount('buy $1 now for $$2 dollars')).toBe(1); }); it('should return the highest substitution when skipping numbers', () => { - expect(getSubstitionCount('I like $1, but I like $8 better')).toBe(8); + expect(getSubstitutionCount('I like $1, but I like $8 better')).toBe(8); }); it('should only allow up to 9 substitutions', () => { - expect(getSubstitionCount('Hello $9')).toBe(9); - expect(getSubstitionCount('Hello $10')).toBe(1); + expect(getSubstitutionCount('Hello $9')).toBe(9); + expect(getSubstitutionCount('Hello $10')).toBe(1); }); }); }); diff --git a/packages/i18n/src/build.ts b/packages/i18n/src/build.ts index 7510c452..7ad7aef8 100644 --- a/packages/i18n/src/build.ts +++ b/packages/i18n/src/build.ts @@ -8,7 +8,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { parseYAML, parseJSON5, parseTOML } from 'confbox'; import { dirname, extname } from 'node:path'; -import { applyChromeMessagePlaceholders, getSubstitionCount } from './utils'; +import { applyChromeMessagePlaceholders, getSubstitutionCount } from './utils'; // // TYPES @@ -155,7 +155,7 @@ function _parseMessagesObject( case 'number': case 'symbol': { const message = String(object); - const substitutions = getSubstitionCount(message); + const substitutions = getSubstitutionCount(message); return [ { type: 'simple', @@ -177,7 +177,7 @@ function _parseMessagesObject( ); if (isPluralMessage(object)) { const message = Object.values(object).join('|'); - const substitutions = getSubstitionCount(message); + const substitutions = getSubstitutionCount(message); return [ { type: 'plural', @@ -189,7 +189,7 @@ function _parseMessagesObject( } if (depth === 1 && isChromeMessage(object)) { const message = applyChromeMessagePlaceholders(object); - const substitutions = getSubstitionCount(message); + const substitutions = getSubstitutionCount(message); return [ { type: 'chrome', diff --git a/packages/i18n/src/utils.ts b/packages/i18n/src/utils.ts index 905aa1c0..cb9b9634 100644 --- a/packages/i18n/src/utils.ts +++ b/packages/i18n/src/utils.ts @@ -11,7 +11,7 @@ export function applyChromeMessagePlaceholders(message: ChromeMessage): string { ); } -export function getSubstitionCount(message: string): number { +export function getSubstitutionCount(message: string): number { return ( 1 + Array.from({ length: MAX_SUBSTITUTIONS }).findLastIndex((_, i) =>