diff --git a/Xplat/src/main/java/vazkii/patchouli/common/book/Book.java b/Xplat/src/main/java/vazkii/patchouli/common/book/Book.java index a84a2302..8efa3397 100644 --- a/Xplat/src/main/java/vazkii/patchouli/common/book/Book.java +++ b/Xplat/src/main/java/vazkii/patchouli/common/book/Book.java @@ -263,11 +263,13 @@ public MutableComponent getSubtitle() { int ver = Integer.parseInt(version); if (ver == 0) { return Component.translatable(subtitle); + } else if (ver < 0) { + return Component.translatable("patchouli.gui.lexicon.dev_edition"); } - editionStr = Component.literal(numberToOrdinal(ver)); + editionStr = numberToOrdinal(ver); } catch (NumberFormatException e) { - editionStr = Component.translatable("patchouli.gui.lexicon.dev_edition"); + return Component.translatable("patchouli.gui.lexicon.dev_edition"); } return Component.translatable("patchouli.gui.lexicon.edition_str", editionStr); @@ -281,8 +283,34 @@ public BookIcon getIcon() { } } - private static String numberToOrdinal(int i) { - return i % 100 == 11 || i % 100 == 12 || i % 100 == 13 ? i + "th" : i + ORDINAL_SUFFIXES[i % 10]; + private static Component numberToOrdinal(int i) { + int units = i % 10; + int tens = i % 100 - units; + String base = "patchouli.gui.lexicon.edition_str.ord"; + if (i % 1000 >= 100 && tens == 0) {tens = 100;} + String i_str = Integer.toString(i); + String units_str = Integer.toString(units); + String tens_str = tens == 0 ? (i < 10 ? "uu" : "00") : Integer.toString(tens); + /* + The translation key is first picked based on the number's tens. + - If the translation is "%1$s", then that suffix will be used for all numbers with those tens. + - If the translation is "%2$s", then for all the numbers with those tens + it will pick a suffix based on the units alone (the translation of .). + - If the translation is "%3$s", then for all the numbers with those tens + it will pick a translation based on both units AND tens. This translation can be: + - "%1$s" (a special suffix) + - "%2$s" (default units suffix) + If the tens of a number are equal to 0, 'tens' can have three possible values: + - "uu" if the number is less than 10 (1, 2, 3, ...) + - "00" if the number is greater than 10 and number's hundreds are equal to 0 (1001, 2002, 3003, ...) + - "100" if the number's hundreds are not equal to 0 (101, 202, 3303, ...) + */ + return Component.translatable(String.join(".", base, tens_str), i_str, + Component.translatable(String.join(".", base, units_str), i_str), + Component.translatable(String.join(".", base, tens_str, units_str), i_str, + Component.translatable(String.join(".", base, units_str), i_str) + ) + ); } public BookContents getContents() { diff --git a/Xplat/src/main/resources/assets/patchouli/lang/en_us.json b/Xplat/src/main/resources/assets/patchouli/lang/en_us.json index b9475fc4..77fc9aa6 100644 --- a/Xplat/src/main/resources/assets/patchouli/lang/en_us.json +++ b/Xplat/src/main/resources/assets/patchouli/lang/en_us.json @@ -62,7 +62,7 @@ "patchouli.gui.lexicon.loading_error": "Loading error!", "patchouli.gui.lexicon.loading_error_hover": "(Hover for info)", "patchouli.gui.lexicon.loading_error_log": "Check your log for more", - "patchouli.gui.lexicon.dev_edition": "Writer's", + "patchouli.gui.lexicon.dev_edition": "Writer's Edition", "patchouli.gui.lexicon.edition_str": "%s Edition", "patchouli.gui.lexicon.added_by": "Added by %s", "patchouli.gui.lexicon.sneak": "Sneak to view", @@ -75,6 +75,29 @@ "patchouli.gui.lexicon.mark_complete": "Mark Complete", "patchouli.gui.lexicon.mark_incomplete": "Mark Incomplete", + "patchouli.gui.lexicon.edition_str.ord.0":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.1":"%1$sst", + "patchouli.gui.lexicon.edition_str.ord.2":"%1$snd", + "patchouli.gui.lexicon.edition_str.ord.3":"%1$srd", + "patchouli.gui.lexicon.edition_str.ord.4":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.5":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.6":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.7":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.8":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.9":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.uu":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.00":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.10":"%1$sth", + "patchouli.gui.lexicon.edition_str.ord.20":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.30":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.40":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.50":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.60":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.70":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.80":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.90":"%2$s", + "patchouli.gui.lexicon.edition_str.ord.100":"%2$s", + "patchouli.gui.lexicon.button.prev_page": "Previous", "patchouli.gui.lexicon.button.next_page": "Next", "patchouli.gui.lexicon.button.back": "Back",