proposal for ICU4C RuleBasedNumberFormat localization

Doug Felt <[email protected]> Mon, 4 Oct 2004 14:19:51 -0700
Newsgroups gmane.comp.lib.icu.general
Message-ID <OF4A53A437.005B3710-ON88256F23.0074F927-88256F23.007518A1@us.ibm.com>
Please reply by Oct. 11th.

The following APIs are proposed for supporting localization of rule names 
in RuleBasedNumberFormat in ICU4C

// This is a convenience API that mirrors the existing ICU4J API that 
constructs
// from rules only.

    /**
     * Creates a RuleBasedNumberFormat that behaves according to the 
description
     * passed in.  The formatter uses the default locale.
     * @param rules A description of the formatter's desired behavior.
     * See the class documentation for a complete explanation of the 
description
     * syntax.
     * @param perror The parse error if an error was encountered.
     * @param status The status indicating whether the constructor 
succeeded.
     * @draft ICU 3.2
     */
    RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, 
UErrorCode& status);

// New API for localization.
// This is parallel in functionality to proposed API for ICU4J.  But ICU4J 
uses a more direct implementation
// using arrays of arrays of String.  Such structures are natural to 
create in code in Java, but difficult in
// C/C++.  So instead, the ICU4C version uses a text description of the 
information, and internally parses
// it into such a structure see syntax for the localization data below). 

// The first constructor simply supplies the default Locale to the second 
constructor.

    /**
     * Creates a RuleBasedNumberFormat that behaves according to the 
description
     * passed in.  The formatter uses the default locale. 
     * <p>
     * The localizations data provides information about the public
     * rule sets and their localized display names for different
     * locales. See the class documentation for a complete explanation of 
     * the description syntax.
     * @param localizations the localization information.
     * names in the description.  These will be copied by the constructor.
     * @param perror The parse error if an error was encountered.
     * @param status The status indicating whether the constructor 
succeeded.
     * @draft ICU 3.2
     */
    RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& 
localizations,
                        UParseError& perror, UErrorCode& status);

    /**
     * Creates a RuleBasedNumberFormat that behaves according to the 
description
     * passed in.  The formatter uses the default locale. 
     * <p>
     * The localizations data provides information about the public
     * rule sets and their localized display names for different
     * locales.
     * @param rules A description of the formatter's desired behavior.
     * See the class documentation for a complete explanation of the 
description
     * syntax.
     * @param localizations the localization information. See the class 
     * documentation for a complete explanation of the localization 
syntax.
     * @param locale A locale that governs which characters are used for
     * formatting values in numerals and which characters are equivalent 
in
     * lenient parsing.
     * @param perror The parse error if an error was encountered.
     * @param status The status indicating whether the constructor 
succeeded.
     * @draft ICU 3.2
     */
    RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& 
localizations,
                        const Locale& locale, UParseError& perror, 
UErrorCode& status);


// The following APIs provide access to the localization information.  The 
structure of the
// APIs (apis to return a count, and then return by index) parallel the 
existing APIs for
// getting the (unlocalized) rule set names.  The Java APIs return arrays 
of String; 
// this avoids the ownership/caching issues associated with such an API 
that arise
// in C/C++

  /**
   * Return the number of locales for which we have localized rule set 
display names.
   * @return the number of locales for which we have localized rule set 
display names.
   * @draft ICU 3.2
   */
  virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;

  /**
   * Return the index'th display name locale.
   * @param index the index of the locale
   * @param return the locale
   * @see #getNumberOfRuleSetDisplayNameLocales
   * @draft ICU 3.2
   */
  virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& 
status) const;

    /**
     * Return the rule set display names for the provided locale.  These 
are in the same order
     * as those returned by getRuleSetName.  The locale is matched against 
the locales for
     * which there is display name data, using normal fallback rules.  If 
no locale matches, 
     * the default display names are returned.  (These are the internal 
rule set names minus
     * the leading '%'.)
     * @param index the index of the rule set
     * @param locale the locale (returned by getRuleSetDisplayNameLocale) 
for which the localized
     * display name is desired
     * @return the display name for the given index, which might be bogus 
if there is an error
     * @see #getRuleSetName
     * @draft ICU 3.2
     */
  virtual UnicodeString getRuleSetDisplayName(int32_t index, 
                                              const Locale& locale = 
LocalegetDefault());

    /**
     * Return the rule set display name for the provided rule set and 
locale. 
     * The locale is matched against the locales for which there is 
display name data, using
     * normal fallback rules.  If no locale matches, the default display 
name is returned.
     * @return the display name for the rule set
     * @draft ICU 3.2
     * @see #getRuleSetDisplayName(int32_t, const Locale&)
     */
  virtual UnicodeString getRuleSetDisplayName(const UnicodeString& 
ruleSetName, 
                                              const Locale& locale = 
LocalegetDefault());


// Rule syntax description

 * <p><b>Localizations</b></p>
 * <p>Constructors are available that allow the specification of 
localizations for the
 * public rule sets (and also allow more control over what public rule 
sets are available).
 * This information is represented as a UnicodeString.  The description 
represents
 * an array of arrays of string.  The first element is an array of the 
public rule set names;
 * each of these must be one of the public rule set names that appear in 
the rules.  Only
 * names in this array will be treated as public rule set names by the 
API, and the first
 * name in the array will be the initial default rule set.  Each 
subsequent
 * element is an array of localizations of these names.  The first element 
of one of these
 * subarrays is the locale name, and the remaining elements are 
localizations of the
 * public rule set names, in the same order as they were listed in the 
first arrray.</p>
 * <p>In the syntax, angle brackets '<', '>' are used to delimit the 
arrays, and comma ',' is used
 * to separate elements of an array.  Whitespace is ignored, unless 
quoted.</p>
 * <p>For example<blockquote>
 * < < %foo, %bar, %baz >, 
 *   < en, Foo, Bar, Baz >, 
 *   < fr, 'le Foo', 'le Bar', 'le Baz' > 
 *   < zh, \u7532, \u4e59, \u4e19 > >
 * </blockquote></p>