Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-16939 add unit prefixes to data #3457

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion common/dtd/ldmlSupplemental.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: Unicode-DFS-2016
CLDR data files are interpreted according to the LDML specification (http://unicode.org/reports/tr35/)
-->

<!ELEMENT supplementalData ( version, generation?, cldrVersion?, currencyData?, territoryContainment?, subdivisionContainment?, languageData?, territoryInfo?, postalCodeData?, calendarData?, calendarPreferenceData?, weekData?, timeData?, measurementData?, unitIdComponents?, unitConstants*, unitQuantities*, convertUnits*, unitPreferenceData?, timezoneData?, characters?, transforms?, metadata?, codeMappings?, parentLocales*, personNamesDefaults?, likelySubtags?, metazoneInfo?, plurals?, telephoneCodeData?, numberingSystems?, bcp47KeywordMappings?, gender?, references?, languageMatching?, dayPeriodRuleSet*, metaZones?, primaryZones?, windowsZones?, coverageLevels?, idValidity?, rgScope?, languageGroups?, grammaticalData? ) >
<!ELEMENT supplementalData ( version, generation?, cldrVersion?, currencyData?, territoryContainment?, subdivisionContainment?, languageData?, territoryInfo?, postalCodeData?, calendarData?, calendarPreferenceData?, weekData?, timeData?, measurementData?, unitIdComponents?, unitPrefixes?, unitConstants*, unitQuantities*, convertUnits*, unitPreferenceData?, timezoneData?, characters?, transforms?, metadata?, codeMappings?, parentLocales*, personNamesDefaults?, likelySubtags?, metazoneInfo?, plurals?, telephoneCodeData?, numberingSystems?, bcp47KeywordMappings?, gender?, references?, languageMatching?, dayPeriodRuleSet*, metaZones?, primaryZones?, windowsZones?, coverageLevels?, idValidity?, rgScope?, languageGroups?, grammaticalData? ) >

<!ELEMENT version EMPTY >
<!--@METADATA-->
Expand Down Expand Up @@ -388,6 +388,25 @@ CLDR data files are interpreted according to the LDML specification (http://unic
<!--@MATCH:set/regex/[a-z]+[0-9]*-->
<!--@VALUE-->


<!ELEMENT unitPrefixes ( unitPrefix* ) >

<!ELEMENT unitPrefix EMPTY >
<!-- <unitPrefix type='quecto' symbol='q' power10='-30'>
<unitPrefix type='kibi' symbol='Ki' power2='10'>
-->
<!ATTLIST unitPrefix type NMTOKEN #REQUIRED >
<!--@MATCH:regex/[A-Za-z]{3,6}-->
<!ATTLIST unitPrefix symbol NMTOKEN #REQUIRED >
<!--@MATCH:regex/[a-zA-Zμ]{1,2}-->
<!--@VALUE-->
<!ATTLIST unitPrefix power10 NMTOKEN #IMPLIED >
<!--@MATCH:regex/-?[0-9]{1,2}-->
<!--@VALUE-->
<!ATTLIST unitPrefix power2 NMTOKEN #IMPLIED >
<!--@MATCH:regex/[0-9]0-->
<!--@VALUE-->

<!ELEMENT unitConstants ( unitConstant* ) >

<!ELEMENT unitConstant EMPTY >
Expand Down
34 changes: 34 additions & 0 deletions common/supplemental/units.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,40 @@ For terms of use, see http://www.unicode.org/copyright.html
<unitIdComponent type="and" values="and"/>
<unitIdComponent type="per" values="per"/>
</unitIdComponents>
<unitPrefixes>
<unitPrefix type='quecto' symbol='q' power10='-30'/>
<unitPrefix type='ronto' symbol='r' power10='-27'/>
<unitPrefix type='yocto' symbol='y' power10='-24'/>
<unitPrefix type='zepto' symbol='z' power10='-21'/>
<unitPrefix type='atto' symbol='a' power10='-18'/>
<unitPrefix type='femto' symbol='f' power10='-15'/>
<unitPrefix type='pico' symbol='p' power10='-12'/>
<unitPrefix type='nano' symbol='n' power10='-9'/>
<unitPrefix type='micro' symbol='μ' power10='-6'/>
<unitPrefix type='milli' symbol='m' power10='-3'/>
<unitPrefix type='centi' symbol='c' power10='-2'/>
<unitPrefix type='deci' symbol='d' power10='-1'/>
<unitPrefix type='deka' symbol='da' power10='1'/>
<unitPrefix type='hecto' symbol='h' power10='2'/>
<unitPrefix type='kilo' symbol='k' power10='3'/>
<unitPrefix type='mega' symbol='M' power10='6'/>
<unitPrefix type='giga' symbol='G' power10='9'/>
<unitPrefix type='tera' symbol='T' power10='12'/>
<unitPrefix type='peta' symbol='P' power10='15'/>
<unitPrefix type='exa' symbol='E' power10='18'/>
<unitPrefix type='zetta' symbol='Z' power10='21'/>
<unitPrefix type='yotta' symbol='Y' power10='24'/>
<unitPrefix type='ronna' symbol='R' power10='27'/>
<unitPrefix type='quetta' symbol='Q' power10='30'/>
<unitPrefix type='kibi' symbol='Ki' power2='10'/>
<unitPrefix type='mebi' symbol='Mi' power2='20'/>
<unitPrefix type='gibi' symbol='Gi' power2='30'/>
<unitPrefix type='tebi' symbol='Ti' power2='40'/>
<unitPrefix type='pebi' symbol='Pi' power2='50'/>
<unitPrefix type='exbi' symbol='Ei' power2='60'/>
<unitPrefix type='zebi' symbol='Zi' power2='70'/>
<unitPrefix type='yobi' symbol='Yi' power2='80'/>
</unitPrefixes>
<unitConstants>
<unitConstant constant="lb_to_kg" value="0.45359237"/>
<unitConstant constant="ft_to_m" value="0.3048"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ public String toShortId() {
}
}

public class UnitPrefixInfo {
final String abbreviation;
final int base;
final int power;

public UnitPrefixInfo(String abbreviation, int base, int power) {
this.abbreviation = abbreviation;
this.base = base;
this.power = power;
}

@Override
public String toString() {
return String.format(
"%s\t%s", abbreviation, String.valueOf(base) + "^" + String.valueOf(power));
}
}

/** Official status of languages */
public enum OfficialStatus {
unknown("U", 1),
Expand Down Expand Up @@ -977,6 +995,8 @@ public enum RBNFGroup {

private Map<String, UnitIdComponentType> unitIdComponentType = new TreeMap<>();

private Map<String, UnitPrefixInfo> unitPrefixInfo = new TreeMap<>();

public Map<String, GrammarInfo> grammarLocaleToTargetToFeatureToValues = new TreeMap<>();
public Map<String, GrammarDerivation> localeToGrammarDerivation = new TreeMap<>();

Expand Down Expand Up @@ -1233,6 +1253,8 @@ private void makeStuffSafe() {

unitIdComponentType = CldrUtility.protectCollection(unitIdComponentType);

unitPrefixInfo = CldrUtility.protectCollection(unitPrefixInfo);

timeData = CldrUtility.protectCollection(timeData);

validityInfo = CldrUtility.protectCollection(validityInfo);
Expand Down Expand Up @@ -1386,6 +1408,10 @@ public void handlePathValue(String path, String value) {
if (handleUnitUnitIdComponents(parts)) {
return;
}
} else if (level1.equals("unitPrefixes")) {
if (handleUnitPrefix(parts)) {
return;
}
} else if (level1.equals("unitConstants")) {
if (handleUnitConstants(parts)) {
return;
Expand Down Expand Up @@ -1439,6 +1465,22 @@ public void handlePathValue(String path, String value) {
}
}

private boolean handleUnitPrefix(XPathParts parts) {
// <unitPrefix type='quecto' symbol='q' power10='-30'/>
String power10 = parts.getAttributeValue(-1, "power10");
String power2 = parts.getAttributeValue(-1, "power2");
if ((power10 != null) == (power2 != null)) {
throw new IllegalArgumentException("Must have exactly one @power2 or @power10");
}
unitPrefixInfo.put(
parts.getAttributeValue(-1, "type"),
new UnitPrefixInfo(
parts.getAttributeValue(-1, "symbol"),
power10 != null ? 10 : 2,
Integer.parseInt(power10 != null ? power10 : power2)));
return true;
}

private boolean handlePersonNamesDefaults(String value, XPathParts parts) {
personNameOrder.putAll(
Order.from(parts.getAttributeValue(-1, "order")), split_space.split(value));
Expand Down Expand Up @@ -5053,4 +5095,12 @@ public GrammarDerivation getGrammarDerivation(String locale) {
public Multimap<Order, String> getPersonNameOrder() {
return personNameOrder;
}

public UnitPrefixInfo getUnitPrefixInfo(String prefix) {
return unitPrefixInfo.get(prefix);
}

public Set<String> getUnitPrefixes() {
return unitPrefixInfo.keySet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@


//supplementalData/unitIdComponents/unitIdComponent[@type="%A"]/_values ; Supplemental ; Units ; IdComponent ; $1-values ; HIDE
//supplementalData/unitPrefixes/unitPrefix[@type="%A"]/_symbol ; Supplemental ; Units ; Prefix ; $1-symbol ; HIDE
//supplementalData/unitPrefixes/unitPrefix[@type="%A"]/_power10 ; Supplemental ; Units ; Prefix ; $1-power10 ; HIDE
//supplementalData/unitPrefixes/unitPrefix[@type="%A"]/_power2 ; Supplemental ; Units ; Prefix ; $1-power2 ; HIDE
//supplementalData/unitConstants/unitConstant[@constant="%A"]/_value ; Supplemental ; Units ; Constant ; $1-value ; HIDE
//supplementalData/unitConstants/unitConstant[@constant="%A"]/_status ; Supplemental ; Units ; Constant ; $1-status ; HIDE
//supplementalData/unitQuantities/unitQuantity[@baseUnit="%A"]/_quantity ; Supplemental ; Units ; Quantity ; $1-value ; HIDE
Expand Down
Loading