Skip to content

CLDR-18215 Add examples for light-second#4523

Merged
macchiati merged 4 commits intomainfrom
CLDR-18215-Add-examples-for-light-speed
Mar 24, 2025
Merged

CLDR-18215 Add examples for light-second#4523
macchiati merged 4 commits intomainfrom
CLDR-18215-Add-examples-for-light-speed

Conversation

@macchiati
Copy link
Member

And so on.

CLDR-18215

Aside from adding to the example generate handler for unit formats:

  • Adds convenience constructor for example generator
  • Refactors a bit

tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFileOverride.java

  • adds an easy way to override a CLDRFile for testing

tools/cldr-code/src/main/java/org/unicode/cldr/util/UnitConverter.java

  • deletes a hack, because we can now format all parts

tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java

  • adds a test case.

  • This PR completes the ticket.

ALLOW_MANY_COMMITS=true

@macchiati macchiati marked this pull request as ready for review March 24, 2025 03:51
@macchiati
Copy link
Member Author

I noticed a glitch (https://unicode-org.atlassian.net/issues/CLDR-18449?filter=10033) which I believe is unconnected, where the ExampleGenerator doesn't change an example when the value changes. Not a showstopper for submission, but something we should look at.

btangmu
btangmu previously approved these changes Mar 24, 2025

if (amount != null) {
addFormattedUnits(examples, parts, unitPattern, shortUnitId, amount);
if (shortUnitId.equals("light-speed")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this added code should go in a subroutine. It should be possible to view an entire function on the screen without scrolling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree for very long functions. But this does fit on a page.

"inch-ofhg");
// "liter-per-100-kilometer",
// "millimeter-ofhg",
// "inch-ofhg"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep the commented-out code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is easier to see what changed during development, but I can remove that.

cldrFileOverride, examples, parts, "light-speed-week", amount);
addFormattedUnitsConstructed(
cldrFileOverride, examples, parts, "light-speed-month", amount);
examples.add("Compare with:");
Copy link
Member

@btangmu btangmu Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this "Compare with:" (and "Used as a fallback in the following:" above) get displayed appropriately on the front end?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@macchiati macchiati requested a review from btangmu March 24, 2025 15:46
@macchiati macchiati merged commit 271eb5d into main Mar 24, 2025
16 checks passed
@macchiati macchiati deleted the CLDR-18215-Add-examples-for-light-speed branch March 24, 2025 16:18
Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged 5 minutes before I reviewed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprising. did this get deleted automatically?

Comment on lines +9 to +17
public class CLDRFileOverride extends CLDRFile {

/**
* Overrides the values of the sourceFile. The keys of the overrides must already be in the
* XMLSource source
*/
public CLDRFileOverride(CLDRFile sourceFile, Map<String, String> valueOverrides) {
super(new XMLSourceMapOverride(sourceFile.dataSource, valueOverrides));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the value for this being a CLDRFile subclass, since there's only a call to the constructor.

I think better would be to just make the XMLSourceMapOverride public (and the top level class) and add (if even needed) a convenience factory function:

    public static final CLDRFile forFile(CLDRFile sourceFile, Map<String, String> valueOverrides) {
         return new CLDRFile(new XMLSourceMapOverride(sourceFile.dataSource, valueOverrides));
     }

but this isn't fundamentally a new kind of CLDRFile, so I don't think the subclass is warranted.

Comment on lines +32 to +38
overrides.keySet().stream()
.forEach(
x -> {
if (source.getValueAtDPath(x) == null) {
throw new IllegalArgumentException();
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could perhaps be a subclass, ensureNoNulls

.forEach(
x -> {
if (source.getValueAtDPath(x) == null) {
throw new IllegalArgumentException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new IllegalArgumentException();
throw new IllegalArgumentException("Null DPath "+x+" found in the source.");

* same, since it provides for the map.
*/
public static class XMLSourceMapOverride extends XMLSource {
private XMLSource delegate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps DelegateXMLSource should be modified so that this could be a subclass of it instead of largely duplicate?

Comment on lines +153 to +156
// TODO (if needed)
// call delegate.getPathsWithValue(valueToMatch, pathPrefix, result);
// remove the items that collide with the map
// then look through the map to see if any matches there need to be added
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO with a ticket #?

}
}

public void testLightSpeed() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be a great parameterized junit test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants