def select_message(message, number, locale):
parts = message.split("<STR_LIT:|>")<EOL>explicit_rules = OrderedDict()<EOL>standard_rules = []<EOL>for part in parts:<EOL><INDENT>part = part.strip()<EOL>match_interval = INTERVAL_MESSAGE_REGEX.match(part)<EOL>match_standard = STANDARD_RULES_REGEX.match(part)<EOL>if match_interval:<EOL><INDENT>explicit_rules[match_interval.group('<STR_LIT>')] = match_interval.group('<STR_LIT:message>')<EOL><DEDENT>elif match_standard:<EOL><INDENT>standard_rules.append(match_standard.groups()[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>standard_rules.append(part)<EOL><DEDENT><DEDENT>for interval, m in list(explicit_rules.items()):<EOL><INDENT>if test_interval(number, interval):<EOL><INDENT>return m<EOL><DEDENT><DEDENT>position = PluralizationRules.get(number, locale)<EOL>if len(standard_rules) <= position:<EOL><INDENT>if len(parts) == <NUM_LIT:1> and len(standard_rules) > <NUM_LIT:0>:<EOL><INDENT>return standard_rules[<NUM_LIT:0>]<EOL><DEDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (message, locale, number))<EOL><DEDENT>return standard_rules[position]<EOL>
Given a message with different plural translations separated by a
pipe (|), this method returns the correct portion of the message based
on the given number, locale and the pluralization rules in the message
itself.

The message supports two different types of pluralization rules:

interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples
indexed:  There is one apple|There are %count% apples

The indexed solution can also contain labels (e.g. one: There is one apple).
This is purely for making the translations more clear - it does not
affect the functionality.

The two methods can also be mixed:
    {0} There are no apples|one: There is one apple|more: There are %count% apples

@type message: str
@param message: The message being translated

@type number: int
@param number: The number of items represented for the message

@type locale: st
@param locale: The locale to use for choosing

@rtype: str
@raises: ValueError