Skip to content

Commit

Permalink
CLDR-13979 Fix pointers to infohub (unicode-org#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati authored Jul 23, 2020
1 parent cbe0bb0 commit 4c75ea4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public void TestTestCache() {

private static final boolean DEBUG = true;

static final Factory cldrFactory = CLDRConfig.getInstance().getCldrFactory();

public void testPlaceholderSamples() {
final Factory cldrFactory = CLDRConfig.getInstance().getCldrFactory();
CLDRFile root = cldrFactory.make("root", true);
String[][] tests = {
// test edge cases
Expand Down Expand Up @@ -221,22 +222,12 @@ public void testPlaceholderSamples() {
for (int i = 3; i < row.length; ++i) {
expected.add(Subtype.valueOf(row[i]));
}

XMLSource localeSource = new SimpleXMLSource(localeId);
localeSource.putValueAtPath(path, value);

TestFactory currFactory = makeTestFactory(root, localeSource);
CLDRFile cldrFile = currFactory.make(localeSource.getLocaleID(), true);
CheckForExemplars check = new CheckForExemplars(currFactory);

Options options = new Options();
List<CheckStatus> possibleErrors = new ArrayList<>();
check.setCldrFileToCheck(cldrFile , options, possibleErrors);
check.handleCheck(path, path, value, options, possibleErrors);
checkPathValue(root, localeId, path, value, possibleErrors);
Set<Subtype> actual = new TreeSet<>();
for (CheckStatus item : possibleErrors) {
if (PatternPlaceholders.PLACEHOLDER_SUBTYPES.contains(item.getSubtype())) {
actual.add(item.getSubtype());
actual .add(item.getSubtype());
}
}
if (!assertEquals(Arrays.asList(row).toString(), expected, actual)) {
Expand All @@ -245,6 +236,19 @@ public void testPlaceholderSamples() {
}
}

public void checkPathValue(CLDRFile root, String localeId, String path, String value, List<CheckStatus> possibleErrors) {
XMLSource localeSource = new SimpleXMLSource(localeId);
localeSource.putValueAtPath(path, value);

TestFactory currFactory = makeTestFactory(root, localeSource);
CLDRFile cldrFile = currFactory.make(localeSource.getLocaleID(), true);
CheckForExemplars check = new CheckForExemplars(currFactory);

Options options = new Options();
check.setCldrFileToCheck(cldrFile , options, possibleErrors);
check.handleCheck(path, path, value, options, possibleErrors);
}

public void TestPlaceholders() {
CheckCLDR.setDisplayInformation(english);
checkPlaceholders(english);
Expand Down Expand Up @@ -977,4 +981,28 @@ public void TestALLOWED_IN_LIMITED_PATHS() {
// TODO enhance to check more conditions
// like old: assertFalse("vo, !engSame, !isError, !isMissing", SubmissionLocales.allowEvenIfLimited("vo", pathNotSameValue, false, false));
}

public void TestInfohubLinks13979() {
CLDRFile root = cldrFactory.make("root", true);
List<CheckStatus> possibleErrors = new ArrayList<>();
String[][] tests = {
// test edge cases
// locale, path, value, expected
{"fr", "//ldml/numbers/minimalPairs/genderMinimalPairs[@gender=\"feminine\"]", "de genre féminin",
"Need at least 1 placeholder(s), but only have 0. Placeholders are: {{0}={GENDER}, e.g. “‹noun phrase in this gender›”}; see <a href='http://cldr.unicode.org/translation/error-codes#missingPlaceholders' target='cldr_error_codes'>missing placeholders</a>."},
};
for (String[] row : tests) {
String localeId = row[0];
String path = row[1];
String value = row[2];
String expected = row[3];

checkPathValue(root, localeId, path,value, possibleErrors);
for (CheckStatus error : possibleErrors) {
if (error.getSubtype() == Subtype.missingPlaceholders) {
assertEquals("message", expected, error.getMessage());
}
}
}
}
}
16 changes: 14 additions & 2 deletions tools/java/org/unicode/cldr/test/CheckCLDR.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -43,6 +42,7 @@
import org.unicode.cldr.util.VoteResolver;
import org.unicode.cldr.util.VoteResolver.Status;

import com.google.common.collect.ImmutableSet;
import com.ibm.icu.dev.util.ElapsedTimer;
import com.ibm.icu.impl.Row.R3;
import com.ibm.icu.text.ListFormatter;
Expand Down Expand Up @@ -731,7 +731,7 @@ public String toString() {
/**
* These error don't prevent entry during submission, since they become valid if a different row is changed.
*/
public static EnumSet<Subtype> crossCheckSubtypes = EnumSet.of(
public static Set<Subtype> crossCheckSubtypes = ImmutableSet.of(
Subtype.dateSymbolCollision,
Subtype.displayCollision,
Subtype.inconsistentDraftStatus,
Expand All @@ -741,6 +741,15 @@ public String toString() {
Subtype.narrowDateFieldTooWide,
Subtype.coverageLevel);

public static Set<Subtype> errorCodesPath = ImmutableSet.of(
Subtype.duplicatePlaceholders,
Subtype.extraPlaceholders,
Subtype.gapsInPlaceholderNumbers,
Subtype.invalidPlaceHolder,
Subtype.missingPlaceholders,
Subtype.shouldntHavePlaceholders);


private Type type;
private Subtype subtype = Subtype.none;
private String messageFormat;
Expand Down Expand Up @@ -778,6 +787,9 @@ public String getMessage() {
String fixedApos = MessageFormat.autoQuoteApostrophe(messageFormat);
MessageFormat format = new MessageFormat(fixedApos);
message = format.format(parameters);
if (errorCodesPath.contains(subtype)) {
message += "; see <a href='http://cldr.unicode.org/translation/error-codes#" + subtype.name() + "' target='cldr_error_codes'>" + subtype + "</a>.";
}
} catch (Exception e) {
message = messageFormat;
System.err.println("MessageFormat Failure: " + subtype + "; " + messageFormat + "; "
Expand Down
7 changes: 4 additions & 3 deletions tools/java/org/unicode/cldr/test/CheckForExemplars.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ private String checkAndReplacePlaceholders(String path, String value, List<Check
}
}

// TODO: move these tests to CheckPlaceholder

// Now see what is there, and see if they match
Matcher matcher = patternMatcher.reset(value);
Multiset<String> matchList = TreeMultiset.create(); // Look for duplicate values.
Expand Down Expand Up @@ -537,16 +539,15 @@ private String checkAndReplacePlaceholders(String path, String value, List<Check

// Now see if the number we have is within bounds


if (countDistinctPlaceholders < minimum) {
result.add(new CheckStatus().setCause(this).setMainType(statusType)
.setSubtype(Subtype.missingPlaceholders)
.setMessage("Need at least {0} placeholder(s); only have {1}. Placeholders are: {2}", minimum, countDistinctPlaceholders, placeholderInfo));
.setMessage("Need at least {0} placeholder(s), but only have {1}. Placeholders are: {2}", minimum, countDistinctPlaceholders, placeholderInfo));
} else {
if (countDistinctPlaceholders > maximum) {
result.add(new CheckStatus().setCause(this).setMainType(statusType)
.setSubtype(Subtype.extraPlaceholders)
.setMessage("Need no more than {0} placeholders; have too many with {1}.", countDistinctPlaceholders, minimum));
.setMessage("Need no more than {0} placeholders, but have too many with {1}.", countDistinctPlaceholders, minimum));
}
}
// Return the pattern with placeholders replaced
Expand Down
4 changes: 2 additions & 2 deletions tools/java/org/unicode/cldr/util/data/PathDescription.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@

^//ldml/numbers/minimalPairs/ordinalMinimalPairs\[@ordinal="([^"]*)"] ; Minimal pairs for ordinals. For more information, please see http://cldr.org/translation/getting-started/plurals#TOC-Minimal-Pairs.
^//ldml/numbers/minimalPairs/pluralMinimalPairs\[@count="([^"]*)"] ; Minimal pairs for plurals (cardinals). For more information, please see http://cldr.org/translation/getting-started/plurals#TOC-Minimal-Pairs.
^//ldml/numbers/minimalPairs/caseMinimalPairs\[@case="([^"]*)"] ; Minimal pairs for cases used in the language. For more information, please see http://cldr.org/translation/getting-started/plurals#TOC-Minimal-Pairs.
^//ldml/numbers/minimalPairs/genderMinimalPairs\[@gender="([^"]*)"] ; Minimal pairs for genders. For more information, please see http://cldr.org/translation/getting-started/plurals#TOC-Minimal-Pairs.
^//ldml/numbers/minimalPairs/caseMinimalPairs\[@case="([^"]*)"] ; Minimal pairs for cases used in the language. For more information, please see http://cldr.unicode.org/translation/grammatical-inflection.
^//ldml/numbers/minimalPairs/genderMinimalPairs\[@gender="([^"]*)"] ; Minimal pairs for genders. For more information, please see http://cldr.unicode.org/translation/grammatical-inflection .

^//ldml/numbers/([a-z]*)Formats(\[@numberSystem="([^"]*)"])?/\1FormatLength/\1Format\[@type="standard"]/pattern\[@type="standard"]$ ; Special pattern used to compose {1} numbers. Note: before translating, be sure to read http://cldr.org/translation/numbers-currency/number-patterns.
^//ldml/numbers/currencyFormats\[@numberSystem="([^"]*)"]/currencyFormatLength/currencyFormat\[@type="accounting"]/pattern ; Special pattern used to compose currency values for accounting purposes. Note: before translating, be sure to read http://cldr.org/translation/numbers-currency/number-patterns.
Expand Down
4 changes: 2 additions & 2 deletions tools/java/org/unicode/cldr/util/data/Placeholders.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@

^//ldml/numbers/minimalPairs/ordinalMinimalPairs[@ordinal="%A"] ; multiple ; {0}=COUNT 3
^//ldml/numbers/minimalPairs/pluralMinimalPairs[@count="%A"] ; multiple ; {0}=COUNT 3
^//ldml/numbers/minimalPairs/caseMinimalPairs[@case="%A"] ; {0}=CASE <noun in this case>
^//ldml/numbers/minimalPairs/genderMinimalPairs[@gender="%A"] ; {0}=GENDER <noun in this gender>
^//ldml/numbers/minimalPairs/caseMinimalPairs[@case="%A"] ; {0}=CASE noun phrase in this case
^//ldml/numbers/minimalPairs/genderMinimalPairs[@gender="%A"] ; {0}=GENDER noun phrase in this gender

# Warning: the longer match must come first
^//ldml/units/unitLength\[@type="%L"]/compoundUnit\[@type="%A"]/compoundUnitPattern1 ; {0}=POWER UNIT meters
Expand Down

0 comments on commit 4c75ea4

Please sign in to comment.