mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -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)
|
||||
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) {
|
||||
return resolveDateFormatSymbols(getShortWeekdayMap(), language, country);
|
||||
}
|
||||
|
@ -100,4 +107,38 @@ public class CLDRHelper {
|
|||
|
||||
@MetadataProvider(FirstDayOfWeekMetadataGenerator.class)
|
||||
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[] months;
|
||||
String[] shortMonths;
|
||||
String[] weekdays;
|
||||
String[] shortWeekdays;
|
||||
|
||||
public Map<String, String> getLanguages() {
|
||||
|
@ -57,6 +58,10 @@ public class CLDRLocale {
|
|||
return Arrays.copyOf(shortMonths, shortMonths.length);
|
||||
}
|
||||
|
||||
public String[] getWeekdays() {
|
||||
return Arrays.copyOf(weekdays, weekdays.length);
|
||||
}
|
||||
|
||||
public String[] getShortWeekdays() {
|
||||
return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ public class CLDRReader {
|
|||
readAmPms(localeName, localeInfo, root);
|
||||
readMonths(localeName, localeInfo, root);
|
||||
readShortMonths(localeName, localeInfo, root);
|
||||
readWeekdays(localeName, localeInfo, root);
|
||||
readShortWeekdays(localeName, localeInfo, root);
|
||||
break;
|
||||
}
|
||||
|
@ -163,7 +164,7 @@ public class CLDRReader {
|
|||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||
.get("dates").getAsJsonObject().get("calendars").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];
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
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()
|
||||
.get("dates").getAsJsonObject().get("calendars").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];
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
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) {
|
||||
JsonObject monthsJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
|
||||
.get("dates").getAsJsonObject().get("calendars").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];
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
locale.shortWeekdays[i] = monthsJson.get(weekdayKeys[i]).getAsString();
|
||||
|
|
|
@ -43,6 +43,10 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator {
|
|||
return generateSymbols(context, new ResourceExtractor() {
|
||||
@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":
|
||||
return generateSymbols(context, new ResourceExtractor() {
|
||||
@Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); }
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.teavm.classlib.java.text;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -161,10 +160,16 @@ public class TDateFormatSymbols implements TSerializable, TCloneable {
|
|||
}
|
||||
|
||||
public String[] getWeekdays() {
|
||||
if (weekdays == null) {
|
||||
weekdays = CLDRHelper.resolveWeekdays(locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
return weekdays.clone();
|
||||
}
|
||||
|
||||
public String[][] getZoneStrings() {
|
||||
if (zoneStrings == null) {
|
||||
return new String[0][];
|
||||
}
|
||||
String[][] clone = new String[zoneStrings.length][];
|
||||
for (int i = zoneStrings.length; --i >= 0;) {
|
||||
clone[i] = zoneStrings[i].clone();
|
||||
|
|
|
@ -173,7 +173,7 @@ public class DateTime {
|
|||
text = symbols.getMonths()[value] + "/" + symbols.getShortMonths()[value];
|
||||
break;
|
||||
case Calendar.DAY_OF_WEEK:
|
||||
text = symbols.getShortWeekdays()[value - 1];
|
||||
text = symbols.getWeekdays()[value - 1] + "/" + symbols.getShortWeekdays()[value - 1];
|
||||
break;
|
||||
default:
|
||||
text = "";
|
||||
|
|
Loading…
Reference in New Issue
Block a user