1 package org.unicode.cldr.test; 2 3 import java.util.List; 4 5 import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype; 6 import org.unicode.cldr.util.LogicalGrouping; 7 import org.unicode.cldr.util.XPathParts; 8 9 public class CheckMetazones extends CheckCLDR { 10 // remember to add this class to the list in CheckCLDR.getCheckAll 11 // to run just this test, on just locales starting with 'nl', use CheckCLDR with -fnl.* -t.*Metazones.* 12 13 // If you don't need any file initialization or postprocessing, you only need this one routine handleCheck(String path, String fullPath, String value, Options options, List<CheckStatus> result)14 public CheckCLDR handleCheck(String path, String fullPath, String value, Options options, 15 List<CheckStatus> result) { 16 // it helps performance to have a quick reject of most paths 17 if (fullPath == null) return this; // skip paths that we don't have 18 if (value == null) return this; // skip empty values 19 if (path.indexOf("/metazone") < 0) return this; 20 21 // we're simply going to test to make sure that metazone values don't contain any digits 22 if (value.matches(".*\\p{Nd}.*")) { 23 if (!getCldrFileToCheck().getSourceLocaleID(path, null).equals(getCldrFileToCheck().getLocaleID())) { // skip 24 // if 25 // inherited 26 // -- 27 // we 28 // only 29 // need 30 // parent 31 // instance 32 return this; 33 } 34 // the following is how you signal an error or warning (or add a demo....) 35 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType) 36 .setSubtype(Subtype.metazoneContainsDigit) // typically warningType or errorType 37 .setMessage("Metazone name contains digits - translate only the name")); // the message; can be 38 // MessageFormat with arguments 39 } 40 41 if (path.indexOf("/long") >= 0) { 42 XPathParts parts = XPathParts.getFrozenInstance(path); 43 String metazoneName = parts.getAttributeValue(3, "type"); 44 if (!metazoneUsesDST(metazoneName) && path.indexOf("/standard") < 0) { 45 result.add(new CheckStatus().setCause(this).setMainType(CheckStatus.errorType) 46 .setSubtype(Subtype.extraMetazoneString) // typically warningType or errorType 47 .setMessage("Extra metazone string - should only contain standard value for a non-DST metazone")); 48 // the message can be MessageFormat with arguments 49 } 50 } 51 return this; 52 } 53 metazoneUsesDST(String name)54 private boolean metazoneUsesDST(String name) { 55 return LogicalGrouping.metazonesDSTSet.contains(name); 56 } 57 } 58