Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 189165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:08:59+00:00 2026-05-11T16:08:59+00:00

Given a gettext Plural-Forms line, general a few example values for each n .

  • 0

Given a gettext Plural-Forms line, general a few example values for each n. I’d like this feature for the web interface for my site’s translators, so that they know which plural form to put where. For example, given:

"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%"
"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

… I want the first text field to be labeled “1, 21..”, then “2, 3, 4…”, then “5, 6…” (not sure if this is exactly right, but you get the idea.)

Right now the best thing I can come up with is to parse the expression somehow, then iterate x from 0 to 100 and see what n it produces. This isn’t guaranteed to work (what if the lowest x is over 100 for some language?) but it’s probably good enough. Any better ideas or existing Python code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:08:59+00:00Added an answer on May 11, 2026 at 4:08 pm

    Given that it’s late, I’ll bite.

    The following solution is hacky, and relies on converting your plural form to python code that can be evaluated (basically converting the x ? y : z statements to the python x and y or z equivalent, and changing &&/|| to and/or)

    I’m not sure if your plural form rule is a contrived example, and I don’t understand what you mean with your first text field, but I’m sure you’ll get where I’m going with my example solution:

    # -*- Mode: Python -*-
    # vi:si:et:sw=4:sts=4:ts=4
    
    p = "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
    
    # extract rule
    import re
    matcher = re.compile('plural=(.*);')
    match = matcher.search(p)
    rule = match.expand("\\1")
    
    # convert rule to python syntax
    oldrule = None
    while oldrule != rule:
        oldrule = rule
        rule = re.sub('(.*)\?(.*):(.*)', r'(\1) and (\2) or (\3)', oldrule)
    
    rule = re.sub('&&', 'and', rule)
    rule = re.sub('\|\|', 'or', rule)
    
    for n in range(40):
        code = "n = %d" % n
        print n, eval(rule)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 137k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think the best way is to draw a rectangle… May 12, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer The numeric character reference "&#5;" is not legal in valid… May 12, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer Printf is buffered. You can force printf to 'flush' its… May 12, 2026 at 7:19 am

Related Questions

Complete C++ i18n gettext() hello world example has C++ code that works for a
I have the following problem, maybe someone can help me (or explain, where my
I'm trying to implement a custom TableRenderer as described in this tutorial . I'd
Well I tried to figure out is this possible in any way. Here is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.