Skip to content

numberFormat helper Javadoc suggests named locale, but it's not supported #1160

Open
@LeoFuso

Description

@LeoFuso

🐞 Problem

The numberFormat Handlebars helper's Javadoc suggests that locale can be passed as a named parameter:

/**
 * Usage:
 *
 * <pre>
 *    {{numberFormat number ["format"] [locale=default]}}
 * </pre>
 */

This locale=default syntax strongly implies that named parameters like locale="fr" should be supported.

However, in practice, only positional parameters are supported:

{{numberFormat 3.14 "currency" "fr"}}       ✅ works
{{numberFormat 3.14 format="currency"}}     ❌ ignored
{{numberFormat 3.14 locale="fr"}}           ❌ ignored

🔍 Root Cause

In the implementation, only options.param(...) is used:

String format = options.param(0);
String localeStr = options.param(1, Locale.getDefault().toString());

Named parameters such as options.hash("locale") are never checked.


✅ Suggested Improvement

Adopt the same pattern used in the dateFormat helper, which supports both positional and named parameters for format and locale.

Suggested change:

String format = options.param(0, options.hash("format"));
String localeStr = options.param(1, options.hash("locale", Locale.getDefault().toString()))
Locale locale = LocaleUtils.toLocale(localeStr);

This would enable:

{{numberFormat 3.14 "currency" "fr"}}                <!-- positional -->
{{numberFormat 3.14 format="currency" locale="fr"}}  <!-- named -->

🔄 Alternatives

If named parameters are not intended to be supported, the Javadoc should be clarified to remove the implication of named usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions