Skip to content

ngettext() shouldn't be used to pluralize formally in some cases #6796

Description

@MichaelChirico

Thank you very much for collecting these!

One more typo (extra ) at the end):

Rprintf(_("RHS for item %d has been duplicated because MAYBE_REFERENCED==%d MAYBE_SHARED==%d, but then is being plonked. length(values)==%d; length(cols)==%d)\n"),

I would also like to replace the use of ngettext for strings that don't format the count as a number because that prevents proper translation with plurals in some languages, but that can be a separate issue. For your example, that would be

stop_msg = if (length(tt) == 1) {
  gettext("The item in the 'by' or 'keyby' list is length %s. Each must be length %d; the same length as there are rows in x (after subsetting if i is provided).")
} else {
  gettext("The items in the 'by' or 'keyby' list have lengths %s. Each must be length %d; the same length as there are rows in x (after subsetting if i is provided).")
}
stopf(stop_msg, brackify(tt),  xnrow, domain = NA)

Originally posted by @aitap in #6787

See this discussion in #6786. There's a proposed patch there but it needs to be paired with some improvements to {potools}, I think. Tabling for now until after release.

Activity

  1. added this to the 1.18.0 milestone on Feb 4, 2025
  2. venom1204 commented on Feb 5, 2025

    @venom1204
    Contributor

    Hi

    Can I proceed with making the changes for Issue #6796 now, or would you prefer to revisit this after the release?
    I’d like to work on replacing ngettext() with gettext() where necessary to ensure correct pluralization. Specifically, I will:

    1. Identify and change occurrences of ngettext() where the count is not explicitly formatted as a number (e.g., in error
      messages).
    2. Replace these with gettext() and manually handle pluralization.

    Files I will modify:
    R/utils.R ,R/fmelt.R ,R/data.table.R
    These files use ngettext() incorrectly and need manual pluralization adjustments.

    Files I will NOT modify:
    R/bmerge.R ,R/setops.R ,R/fread.R ,R/print.data.table.R ,R/test.data.table.R ,R/data.table.R

    These files already use ngettext() correctly, as they properly format the count using %d.
    Let me know your preference. Thanks!

  3. MichaelChirico commented on Feb 5, 2025

    @MichaelChirico
    MemberAuthor

    Thanks @venom1204. This will definitely happen after release. Actually, the most important work for this issue needs to happen not in {data.table}, but in {potools}:

    MichaelChirico/potools#317 (comment)

    The linked PR here on {data.table} has a patch that will do the bulk of the work on our side; what remains is to ensure that this patch works well with the related tooling (i.e., {potools})

  4. modified the milestones: 1.18.0, 1.19.0 on Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    translationissues/PRs related to message translation projects

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions