Comments: Fixed pointer display, Fixed translation test
Some checks failed
test-js / build (push) Has been cancelled
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-migrations / build (8.4) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
test-php / build (8.4) (push) Has been cancelled

This commit is contained in:
Dan Brown
2025-05-13 12:03:15 +01:00
parent 8f92b6f21b
commit 32b29fcdfc
4 changed files with 16 additions and 13 deletions

View File

@ -58,6 +58,11 @@ describe('Translations Service', () => {
expect(caseB).toEqual('an orange angry big dinosaur');
});
test('it provides count as a replacement by default', () => {
const caseA = $trans.choice(`:count cats|:count dogs`, 4);
expect(caseA).toEqual('4 dogs');
});
test('not provided replacements are left as-is', () => {
const caseA = $trans.choice(`An :a dog`, 5, {});
expect(caseA).toEqual('An :a dog');

View File

@ -10,7 +10,7 @@ export class Translator {
* to use. Similar format at Laravel's 'trans_choice' helper.
*/
choice(translation: string, count: number, replacements: Record<string, string> = {}): string {
replacements = Object.assign({}, replacements, {count: String(count)});
replacements = Object.assign({}, {count: String(count)}, replacements);
const splitText = translation.split('|');
const exactCountRegex = /^{([0-9]+)}/;
const rangeRegex = /^\[([0-9]+),([0-9*]+)]/;