ICU-21349 Add update instructions for unitConstants. Plus minor fixes.

See #1480
This commit is contained in:
Hugo van der Merwe 2020-11-20 14:55:26 +01:00
parent 9c73048681
commit 14c1c0861c
2 changed files with 28 additions and 5 deletions

View file

@ -1,6 +1,11 @@
<!--
© 2020 and later: Unicode, Inc. and others.
License & terms of use: http://www.unicode.org/copyright.html
-->
# Updating Measure Unit with new CLDR data
This document explains how to update the C and JAVA version of the MeasureUnit
This document explains how to update the C++ and Java version of the MeasureUnit
class with new CLDR data.
Code is generated by running MeasureUnitTest.java unit tests, which writes
@ -80,9 +85,6 @@ that you are updating the MeasureUnit clases for ICU 68.
`// End generated code for measunit.cpp`
* Replace all the generated code in between with the contents of the clipboard
\# Update measfmt.cpp -- Update the value for `MEAS_UNIT_COUNT` - no longer
necessary
### Run C++ tests
* Run `./intltest format/MeasureFormatTest` from `test/intltest` to ensure new
@ -109,3 +111,23 @@ will be considered new for the next release too.
**Important:** what you are copying are just the new functions for the current
ICU version, in this case 68. Therefore append, do not replace.
## Updating units.txt and unitConstants
The standard ldml2icu process is used to update ICU's resource files (see
[cldr-icu-readme.txt](../../../../icu4c/source/data/cldr-icu-readme.txt)).
CLDR's units.xml defines conversion rates in terms of some constants defined in
`unitConstants`.
For efficiency and simplicity, ICU does not read `unitConstants` from the
resource file. If any new constants are added, some code changes would be
needed. This would be caught by `testUnitConstantFreshness` unit test in
`units_test.cpp`.
They are hard-coded:
* Java: `UnitConverter.java` has the constant names in
`UnitConverter.Factor.addEntity()` and constant values in
`UnitConverter.Factor.getConversionRate()`.
* C++: `units_converter.cpp` has the constant names in
`addSingleFactorConstant()`, with the constant values in `double
constantsValues[]` in the `units_converter.h` header file.

View file

@ -87,7 +87,8 @@ void UnitsTest::testUnitConstantFreshness() {
if (status.errDataIfFailureAndReset(
"addSingleFactorConstant(<%s>, ...).\n\n"
"If U_INVALID_FORMAT_ERROR, please check that \"icu4c/source/i18n/units_converter.cpp\" "
"has all constants? Is \"%s\" a new constant?\n",
"has all constants? Is \"%s\" a new constant?\n"
"See docs/processes/release/tasks/updating-measure-unit.md for more information.\n",
constant, constant)) {
continue;
}