<commit_before>import i18next from 'i18next'
import t from './t'

// Formats a pluralized string
const tPlural = (singular, plural, options = {}) => {
  if (!Number.isInteger(options.count)) {
    console.error('[react-globe] tPlural expects a integer "count" option')
    return null
  }

  // Manually generate english pluralisation based on gettext style
  if (i18next.language === 'en') {
    return englishPlural(singular, plural, options)
  }

  // The translation function figures out plurals for us
  return t(singular, options)
}

const englishPlural = (singular, plural, options) => {
  if (options.count === 1) {
    return t(singular, options)
  }

  return t(plural, options)
}

export default tPlural<commit_msg>Cleaner pluralisation<commit_after>import i18next from 'i18next'
import t from './t'

// Formats a pluralized string
const tPlural = (messages, options = {}) => {
  if (!Number.isInteger(options.count)) {
    console.error('[react-globe] tPlural requires a integer "count" option')
    return null
  }

  if (!messages.one || !messages.many) {
    console.error('[react-globe] tPlural requires a "one" and "many" strings')
    return null
  }

  // Manually generate english pluralisation based on gettext style
  if (i18next.language === 'en') {
    return englishPlural(messages, options)
  }

  // Return an extra string for 0 counts
  if (options.count === 0) {
    return t(messages.zero || messages.one, options)
  }

  // The translation function figures out plurals for us
  return t(messages.one, options)
}

const englishPlural = (messages, options) => {
  if (options.count === 0) {
    return t(messages.zero || messages.many, options)
  }

  if (options.count === 1) {
    return t(messages.one, options)
  }

  return t(messages.many, options)
}

export default tPlural
{'fraction_non_alphanumeric': 0.12493090105030404, 'fraction_numerical': 0.009397457158651189, 'mean_word_length': 3.6770025839793283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2704541', 'n_tokens_mistral': 589, 'n_tokens_neox': 557, 'n_words': 173}