mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adds skeleton of NumberFormat
This commit is contained in:
parent
1443dc2f55
commit
dabc92b290
|
@ -64,6 +64,13 @@ public class CLDRHelper {
|
||||||
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
||||||
private static native ResourceMap<ResourceArray<StringResource>> getShortMonthMap();
|
private static native ResourceMap<ResourceArray<StringResource>> getShortMonthMap();
|
||||||
|
|
||||||
|
public static String[] resolveWeekdays(String language, String country) {
|
||||||
|
return resolveDateFormatSymbols(getWeekdayMap(), language, country);
|
||||||
|
}
|
||||||
|
|
||||||
|
@MetadataProvider(DateSymbolsMetadataGenerator.class)
|
||||||
|
private static native ResourceMap<ResourceArray<StringResource>> getWeekdayMap();
|
||||||
|
|
||||||
public static String[] resolveShortWeekdays(String language, String country) {
|
public static String[] resolveShortWeekdays(String language, String country) {
|
||||||
return resolveDateFormatSymbols(getShortWeekdayMap(), language, country);
|
return resolveDateFormatSymbols(getShortWeekdayMap(), language, country);
|
||||||
}
|
}
|
||||||
|
@ -100,4 +107,38 @@ public class CLDRHelper {
|
||||||
|
|
||||||
@MetadataProvider(FirstDayOfWeekMetadataGenerator.class)
|
@MetadataProvider(FirstDayOfWeekMetadataGenerator.class)
|
||||||
public static native ResourceMap<IntResource> getFirstDayOfWeek();
|
public static native ResourceMap<IntResource> getFirstDayOfWeek();
|
||||||
|
|
||||||
|
public static String resolveNumberFormat(String language, String country) {
|
||||||
|
return resolveFormatSymbols(getNumberFormatMap(), language, country);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native ResourceMap<StringResource> getNumberFormatMap();
|
||||||
|
|
||||||
|
public static String resolveDecimalFormat(String language, String country) {
|
||||||
|
return resolveFormatSymbols(getDecimalFormatMap(), language, country);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native ResourceMap<StringResource> getDecimalFormatMap();
|
||||||
|
|
||||||
|
public static String resolvePercentFormat(String language, String country) {
|
||||||
|
return resolveFormatSymbols(getPercentFormatMap(), language, country);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native ResourceMap<StringResource> getPercentFormatMap();
|
||||||
|
|
||||||
|
private static String resolveFormatSymbols(ResourceMap<StringResource> map, String language, String country) {
|
||||||
|
String localeCode = getCode(language, country);
|
||||||
|
StringResource res = map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) :
|
||||||
|
map.get("root");
|
||||||
|
return res.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CLDRDecimalData resolveDecimalData(String language, String country) {
|
||||||
|
ResourceMap<CLDRDecimalData> map = getDecimalDataMap();
|
||||||
|
String localeCode = getCode(language, country);
|
||||||
|
return map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) :
|
||||||
|
map.get("root");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native ResourceMap<CLDRDecimalData> getDecimalDataMap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class CLDRLocale {
|
||||||
String[] dayPeriods;
|
String[] dayPeriods;
|
||||||
String[] months;
|
String[] months;
|
||||||
String[] shortMonths;
|
String[] shortMonths;
|
||||||
|
String[] weekdays;
|
||||||
String[] shortWeekdays;
|
String[] shortWeekdays;
|
||||||
|
|
||||||
public Map<String, String> getLanguages() {
|
public Map<String, String> getLanguages() {
|
||||||
|
@ -57,6 +58,10 @@ public class CLDRLocale {
|
||||||
return Arrays.copyOf(shortMonths, shortMonths.length);
|
return Arrays.copyOf(shortMonths, shortMonths.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getWeekdays() {
|
||||||
|
return Arrays.copyOf(weekdays, weekdays.length);
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getShortWeekdays() {
|
public String[] getShortWeekdays() {
|
||||||
return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
|
return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ public class CLDRReader {
|
||||||
readAmPms(localeName, localeInfo, root);
|
readAmPms(localeName, localeInfo, root);
|
||||||
readMonths(localeName, localeInfo, root);
|
readMonths(localeName, localeInfo, root);
|
||||||
readShortMonths(localeName, localeInfo, root);
|
readShortMonths(localeName, localeInfo, root);
|
||||||
|
readWeekdays(localeName, localeInfo, root);
|
||||||
readShortWeekdays(localeName, localeInfo, root);
|
readShortWeekdays(localeName, localeInfo, root);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +164,7 @@ public class CLDRReader {
|
||||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
||||||
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
||||||
.get("stand-alone").getAsJsonObject().get("wide").getAsJsonObject();
|
.get("format").getAsJsonObject().get("wide").getAsJsonObject();
|
||||||
locale.months = new String[12];
|
locale.months = new String[12];
|
||||||
for (int i = 0; i < 12; ++i) {
|
for (int i = 0; i < 12; ++i) {
|
||||||
locale.months[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
locale.months[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
||||||
|
@ -174,18 +175,29 @@ public class CLDRReader {
|
||||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
||||||
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
.get("gregorian").getAsJsonObject().get("months").getAsJsonObject()
|
||||||
.get("stand-alone").getAsJsonObject().get("abbreviated").getAsJsonObject();
|
.get("format").getAsJsonObject().get("abbreviated").getAsJsonObject();
|
||||||
locale.shortMonths = new String[12];
|
locale.shortMonths = new String[12];
|
||||||
for (int i = 0; i < 12; ++i) {
|
for (int i = 0; i < 12; ++i) {
|
||||||
locale.shortMonths[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
locale.shortMonths[i] = monthsJson.get(String.valueOf(i + 1)).getAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readWeekdays(String localeCode, CLDRLocale locale, JsonObject root) {
|
||||||
|
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||||
|
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
||||||
|
.get("gregorian").getAsJsonObject().get("days").getAsJsonObject()
|
||||||
|
.get("format").getAsJsonObject().get("wide").getAsJsonObject();
|
||||||
|
locale.weekdays = new String[7];
|
||||||
|
for (int i = 0; i < 7; ++i) {
|
||||||
|
locale.weekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void readShortWeekdays(String localeCode, CLDRLocale locale, JsonObject root) {
|
private void readShortWeekdays(String localeCode, CLDRLocale locale, JsonObject root) {
|
||||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||||
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
.get("dates").getAsJsonObject().get("calendars").getAsJsonObject()
|
||||||
.get("gregorian").getAsJsonObject().get("days").getAsJsonObject()
|
.get("gregorian").getAsJsonObject().get("days").getAsJsonObject()
|
||||||
.get("stand-alone").getAsJsonObject().get("short").getAsJsonObject();
|
.get("format").getAsJsonObject().get("short").getAsJsonObject();
|
||||||
locale.shortWeekdays = new String[7];
|
locale.shortWeekdays = new String[7];
|
||||||
for (int i = 0; i < 7; ++i) {
|
for (int i = 0; i < 7; ++i) {
|
||||||
locale.shortWeekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString();
|
locale.shortWeekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString();
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator {
|
||||||
return generateSymbols(context, new ResourceExtractor() {
|
return generateSymbols(context, new ResourceExtractor() {
|
||||||
@Override public String[] extract(CLDRLocale locale) { return locale.getShortMonths(); }
|
@Override public String[] extract(CLDRLocale locale) { return locale.getShortMonths(); }
|
||||||
});
|
});
|
||||||
|
case "getWeekdayMap":
|
||||||
|
return generateSymbols(context, new ResourceExtractor() {
|
||||||
|
@Override public String[] extract(CLDRLocale locale) { return locale.getWeekdays(); }
|
||||||
|
});
|
||||||
case "getShortWeekdayMap":
|
case "getShortWeekdayMap":
|
||||||
return generateSymbols(context, new ResourceExtractor() {
|
return generateSymbols(context, new ResourceExtractor() {
|
||||||
@Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); }
|
@Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); }
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.teavm.classlib.java.text;
|
package org.teavm.classlib.java.text;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -161,10 +160,16 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getWeekdays() {
|
public String[] getWeekdays() {
|
||||||
|
if (weekdays == null) {
|
||||||
|
weekdays = CLDRHelper.resolveWeekdays(locale.getLanguage(), locale.getCountry());
|
||||||
|
}
|
||||||
return weekdays.clone();
|
return weekdays.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[][] getZoneStrings() {
|
public String[][] getZoneStrings() {
|
||||||
|
if (zoneStrings == null) {
|
||||||
|
return new String[0][];
|
||||||
|
}
|
||||||
String[][] clone = new String[zoneStrings.length][];
|
String[][] clone = new String[zoneStrings.length][];
|
||||||
for (int i = zoneStrings.length; --i >= 0;) {
|
for (int i = zoneStrings.length; --i >= 0;) {
|
||||||
clone[i] = zoneStrings[i].clone();
|
clone[i] = zoneStrings[i].clone();
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class DateTime {
|
||||||
text = symbols.getMonths()[value] + "/" + symbols.getShortMonths()[value];
|
text = symbols.getMonths()[value] + "/" + symbols.getShortMonths()[value];
|
||||||
break;
|
break;
|
||||||
case Calendar.DAY_OF_WEEK:
|
case Calendar.DAY_OF_WEEK:
|
||||||
text = symbols.getShortWeekdays()[value - 1];
|
text = symbols.getWeekdays()[value - 1] + "/" + symbols.getShortWeekdays()[value - 1];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
text = "";
|
text = "";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user