angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

getPlural with strings defined elsewhere

Open cmalard opened this issue 8 years ago • 1 comments

Hi @rubenv ,

I would like to declare singular and plural strings outside gettextCatalog.getPlural. Case :

// js file where gettext cannot be injected
const objects = [
  { key: OBJECT1, singular: '', plural: '', ... },
  { key: OBJECT2, singular: '', plural: '', ... },
]

// usage :
gettextCatalog.getPlural(n, object.singular, object.plural);

If I declare a gettext() function to tag the strings, getPlural never links with the plural string because the strings needs to be linked together as :

msgid "singular"
msgid_plural "plural"
msgstr[0] "..."
msgstr[1] "..."

How can I do that without getPlural ? (when objects is created the code does not know n)

cmalard avatar Feb 28 '17 23:02 cmalard

I found this solution with getPlural... not sure I'll use it:

// js file where gettext cannot be injected
const gettextCatalog = { getPlural(n, singular, plural) {
  return { singular, plural };
} };

const objects = [
  {
    key: OBJECT1,
    label: gettextCatalog.getPlural(0, 'singular', 'plural'),
  },
]

// usage :
gettextCatalog.getPlural(n, object.label.singular, object.label.plural);

cmalard avatar Mar 04 '17 02:03 cmalard