+<!--
+© 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
`// 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
**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.
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;
}