RFR: 8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB [v4]
Andy Goryachev
duke at openjdk.org
Thu Jul 14 15:31:46 UTC 2022
On Wed, 13 Jul 2022 16:54:48 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> I would like to emphasize that this issue is complicated. Plural rules vary from language to language, adding plural strings to resource bundles adds costs in terms of translation and testing.
>>
>> If we were to support proper plurals, one may use ChoiceFormat, though it seems to fail for Polish, see
>> https://stuartgunter.wordpress.com/2011/08/09/java-i18n-pluralisation-using-choiceformat/
>>
>> Another solution is to pull in ICU4J library, see
>> https://stuartgunter.wordpress.com/2011/08/14/even-better-java-i18n-pluralisation-using-icu4j/
>>
>> Yet another solution is to drop the words altogether and simply show a number (of bytes in this case). Alternatively, use a common suffix such as "B", but this may not look standard.
>
> True plurals (as in LDML) is not yet fully supported in the JDK. (`CompactNumberFormat` does for its own purpose (https://bugs.openjdk.org/browse/JDK-8222756), but not for general use) For this case, I think `ChoiceFormat` is the mid-ground solution, as Swing is only localized in a handful of languages.
Upon further consideration, and after discussing the state of plural forms support in JDK with @naotoj I realized that we cannot use ChoiceFormat here at all. The numeric choices, and their corresponding resource strings are locale-specific, and in some cases simply cannot be coded as a finite array (see Arabic example above).
One possible solution would be to add proper support for plural forms to MessageFormat (which is definitely out of scope for this bug), or perhaps - if showing sizes 0...999 as numbers is not acceptable - to simply fix the 0 bytes case using KB format. That is,
0 - "0 KB"
1 - "1 KB"
...
(i.e. handle the 0 bytes case separately):
long len = ((Long) value);
if(len == 0) {
// shows "0 KB" for 0 bytes
text = MessageFormat.format(kiloByteString, 0);
} else {
// retain existing logic
len /= 1024L;
if (listViewWindowsStyle) {
text = MessageFormat.format(kiloByteString, len + 1);
} else if (len < 1024L) {
text = MessageFormat.format(kiloByteString, (len == 0L) ? 1L : len);
} else {
len /= 1024L;
if (len < 1024L) {
text = MessageFormat.format(megaByteString, len);
} else {
len /= 1024L;
text = MessageFormat.format(gigaByteString, len);
}
}
and revert the new resource string.
-------------
PR: https://git.openjdk.org/jdk/pull/9327
More information about the client-libs-dev
mailing list