How to use the @lingui/macro.plural function in @lingui/macro

To help you get started, we’ve selected a few @lingui/macro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / lingui__macro / lingui__macro-tests.tsx View on Github external
} from '@lingui/macro';

// JS
const age = 12;
const templateResult: MessageDescriptor = t`${age} years old`;
const templateIdResult: MessageDescriptor = t('templateId')`${age} years old`;

const count = 42;

const pluralResult: MessageDescriptor = plural({
    value: count,
    0: 'no books',
    one: '# book',
    other: '# books'
});
const pluralIdResult: MessageDescriptor = plural('pluralId', {
    value: count,
    0: 'no books',
    one: '# book',
    other: '# books'
});

const selectOrdinalResult: MessageDescriptor = selectOrdinal({
    value: count,
    0: 'Zeroth book',
    one: '#st book',
    two: '#nd book',
    few: '#rd book',
    other: '#th book'
});
const selectOrdinalIdResult: MessageDescriptor = selectOrdinal('selectOrdinalId', {
    value: count,
github DefinitelyTyped / DefinitelyTyped / types / lingui__macro / lingui__macro-tests.tsx View on Github external
Trans,
    Plural,
    Select,
    SelectOrdinal,
    DateFormat,
    NumberFormat
} from '@lingui/macro';

// JS
const age = 12;
const templateResult: MessageDescriptor = t`${age} years old`;
const templateIdResult: MessageDescriptor = t('templateId')`${age} years old`;

const count = 42;

const pluralResult: MessageDescriptor = plural({
    value: count,
    0: 'no books',
    one: '# book',
    other: '# books'
});
const pluralIdResult: MessageDescriptor = plural('pluralId', {
    value: count,
    0: 'no books',
    one: '# book',
    other: '# books'
});

const selectOrdinalResult: MessageDescriptor = selectOrdinal({
    value: count,
    0: 'Zeroth book',
    one: '#st book',
github DefinitelyTyped / DefinitelyTyped / types / lingui__macro / lingui__macro-tests.tsx View on Github external
const selectOrdinalIdResult: MessageDescriptor = selectOrdinal('selectOrdinalId', {
    value: count,
    0: 'Zeroth book',
    one: '#st book',
    two: '#nd book',
    few: '#rd book',
    other: '#th book'
});

const gender = 'female';
const numOfGuests = 2;
const host = 'Amy';
const guest = 'Bob';
const selectResult = select({
    value: gender,
    female: plural({
        value: numOfGuests,
        offset: 1,
        0: `${host} does not give a party.`,
        1: `${host} invites ${guest} to her party.`,
        2: `${host} invites ${guest} and one other person to her party.`,
        other: `${host} invites ${guest} and # other people to her party.`
    }),
    male: 'male',
    other: 'other'
});

const selectIdResult = select('selectId', {
    value: gender,
    female: 'female',
    male: 'male',
    other: 'other'
github lingui / js-lingui / examples / vanilla-js / src / ids.js View on Github external
export function getPlural(value) {
  return i18n._(
    t("plural")`There are ${plural({
      value,
      one: "# bottle",
      other: "# bottles"
    })} hanging on the wall`
  )
}
github lingui / js-lingui / examples / vanilla-js / src / messages.js View on Github external
export function getPlural(value) {
  return i18n._(
    t`There are ${plural({
      value,
      one: "# bottle",
      other: "# bottles"
    })} hanging on the wall`
  )
}

@lingui/macro

Macro for generating messages in ICU MessageFormat syntax

MIT
Latest version published 17 days ago

Package Health Score

98 / 100
Full package analysis