JDK-6609703 : (fmt) Errors in Hungarian locale-specific formatting
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
JDK 1.5.0_04 (javac)
JRE 1.5.0_06 (java)

A DESCRIPTION OF THE PROBLEM :
The i18n API (java.util.Formatter, java.text.DecimalFormat) returns incorrect output in some cases for Hungarian. I have found two such cases:

1. When formatting with a Hungarian locale (HU_hu or HU), and java.util.Formatter puts the morning/afternoon marker after the time for 'tr'. The documentation states that "The location of the morning or afternoon marker ('%Tp') may be locale-dependent.". In Hungarian, we put this marker before the hour, so for example "du. 2" instead of  "2 du". As for the inclusion of '.' after de/du   , it depends; however, I think the "correct" way is to include it.

2. If a number is formatted with CurrencyFormat in the HU_hu locale, it will return 'Ft<number>'. However, in Hungarian, the currency should come after the number, with a space between them: '<number> Ft'.

Moreover, CurrencyFormat returns an asterisk-like character ('����') when the locale HU is used. The default locale on my computer is Locale.US, so I think it should return either 'Ft' or '$', but not '����'.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please refer to the source code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
DU. 04:55:59-kor 1 234 567 Ft-ot k����lt����ttem el.
 
ACTUAL -
04:55:59 DU-kor ���� 1 234 567,00-ot k����lt����ttem el.
04:55:59 DU-kor Ft1 234 567-ot k����lt����ttem el.
 

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.*;

public class FormatErrorProof {
	public static void main(String[] args) {
		Locale l1 = new Locale("HU");
		Locale l2 = new Locale("HU", "hu");
		
		NumberFormat nf1 = NumberFormat.getCurrencyInstance(l1);
		NumberFormat nf2 = NumberFormat.getCurrencyInstance(l2);
		String curr1 = nf1.format(1234567);
		String curr2 = nf2.format(1234567);
		
		Date d = new Date();
		
		String proof1 = String.format(l1, "%tr-kor %s-ot k����lt����ttem el.%n", d, curr1);
		String proof2 = String.format(l2, "%tr-kor %s-ot k����lt����ttem el.%n", d, curr2);
		
		JFrame frame = new JFrame("Format error in Hungarian");
		
		Font f = Font.getFont("Times New Roman");
		JLabel lbl1 = new JLabel(proof1);
		JLabel lbl2 = new JLabel(proof2);
		lbl1.setFont(f);
		lbl2.setFont(f);
		
		frame.getContentPane().setLayout(new FlowLayout());
		frame.add(lbl1);
		frame.add(lbl2);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
For the error of the Formatter, instead of %tr, "%tp. %tI:%tM:%tS" should be used (uppercase morning/afternoon markers are not used much in Hungarian, anyway).

For the other error, NumberFormatter can be used and the "Ft" can be added manually.

However, as these classes are mostly used for i18n, these workarounds result in a very cluttered code instead of having the same code for all languages.

Comments
EVALUATION Currently, there's no information in locale data on where to put AM/PM. This is one of the reasons why I filed 6378417.
23-01-2008

EVALUATION Like Hungarian, Formatter's "%tr" returns wrong result also for Japanese and Korean. The morning or afternoon marker should be placed before "%tI:%tM:%tS".
23-01-2008

EVALUATION >>> 2. If a number is formatted with CurrencyFormat in the HU_hu locale, it will >>> return 'Ft<number>'. However, in Hungarian, the currency should come after >>> the number, with a space between them: '<number> Ft'. This will be fixed as a localization bug, 6645405. >>> Moreover, CurrencyFormat returns an asterisk-like character ('??') when the >>> locale HU is used. The default locale on my computer is Locale.US, so I think >>> it should return either 'Ft' or '$', but not '??'. Locale class has three public constructors. Locale(String language) Locale(String language, String country) Locale(String language, String country, String variant) The language argument should be the lower-case, two-letter codes, and the country argument should be upper-case, two-letter codes. I'm not sure which one the submitter wanted to mean by new Locale("HU"), new Locale("", "HU") or new Locale("hu"). In either case, new Locale("HU") doesn't have the valid country information. It's natural that nf1.format(1234567) returns an asterisk-like character (= the default currency sign (\u00a4)) because the formatter cannot find any valid currency code which depends on a country. Please use one of the following codes if the submitter would like to get '$' or "Ft". NumberFormat.getCurrencyInstance() --- '$' is used on en_US locale. NumberFormat.getCurrencyInstance(new Locale("hu", "HU")) --- "Ft" is used.
16-01-2008

EVALUATION I filed 6645405 for the second problem. Please use this bug report for the first problem.
26-12-2007