parameters: ()
return_statement: return localesMapping, rules
docstring: Fetch plural rules data directly from unicode.org website:
docstring_summary: Fetch plural rules data directly from unicode.org website:
docstring_tokens: Fetch plural rules data directly from unicode . org website :
function: def computeRules():
      """
      Fetch plural rules data directly from unicode.org website:
      """
      url = UNICODE_ORG_XML_URL
      f = urllib2.urlopen(url)
      doc = xml.dom.minidom.parse(f)
  
      # Read XML document and extract locale to rules mapping
      localesMapping = {}
      algorithms = {}
      for index,pluralRules in enumerate(doc.getElementsByTagName("pluralRules")):
          if not index in algorithms:
              algorithms[index] = {}
          for locale in pluralRules.getAttribute("locales").split():
              localesMapping[locale] = index
          for rule in pluralRules.childNodes:
              if rule.nodeType != rule.ELEMENT_NODE or rule.tagName != "pluralRule":
                  continue
              pluralForm = rule.getAttribute("count")
              algorithm = rule.firstChild.nodeValue
              algorithms[index][pluralForm] = algorithm
  
      # Go through all rules and compute a Javascript code for each of them
      rules = {}
      for index,rule in algorithms.iteritems():
          lines = []
          for pluralForm in rule:
              condition = rule[pluralForm]
              originalCondition = str(condition)
  
              # Convert pseudo language to JS code
              condition = rule[pluralForm].lower()
              condition = re.sub(CONDITION_RE, parseCondition, condition)
              condition = re.sub(r'or', "||", condition)
              condition = re.sub(r'and', "&&", condition)
  
              # Prints original condition in unicode.org pseudo language
              if PRINT_CONDITIONS_IN_COMMENTS:
                  lines.append( '// %s' % originalCondition )
  
              lines.append( 'if (%s)' % condition )
              lines.append( '  return "%s";' % pluralForm )
              
          rules[index] = "\n    ".join(lines)
      return localesMapping, rules
function_tokens: def computeRules ( ) : url = UNICODE_ORG_XML_URL f = urllib2 . urlopen ( url ) doc = xml . dom . minidom . parse ( f ) # Read XML document and extract locale to rules mapping localesMapping = { } algorithms = { } for index , pluralRules in enumerate ( doc . getElementsByTagName ( "pluralRules" ) ) : if not index in algorithms : algorithms [ index ] = { } for locale in pluralRules . getAttribute ( "locales" ) . split ( ) : localesMapping [ locale ] = index for rule in pluralRules . childNodes : if rule . nodeType != rule . ELEMENT_NODE or rule . tagName != "pluralRule" : continue pluralForm = rule . getAttribute ( "count" ) algorithm = rule . firstChild . nodeValue algorithms [ index ] [ pluralForm ] = algorithm # Go through all rules and compute a Javascript code for each of them rules = { } for index , rule in algorithms . iteritems ( ) : lines = [ ] for pluralForm in rule : condition = rule [ pluralForm ] originalCondition = str ( condition ) # Convert pseudo language to JS code condition = rule [ pluralForm ] . lower ( ) condition = re . sub ( CONDITION_RE , parseCondition , condition ) condition = re . sub ( r'or' , "||" , condition ) condition = re . sub ( r'and' , "&&" , condition ) # Prints original condition in unicode.org pseudo language if PRINT_CONDITIONS_IN_COMMENTS : lines . append ( '// %s' % originalCondition ) lines . append ( 'if (%s)' % condition ) lines . append ( '  return "%s";' % pluralForm ) rules [ index ] = "\n    " . join ( lines ) return localesMapping , rules