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

Fix for issue 348 #648

Open
wants to merge 11 commits into
base: 1.19.x
Choose a base branch
from
Open
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
36 changes: 32 additions & 4 deletions Xplat/src/main/java/vazkii/patchouli/common/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<suffix>", 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 <base>.<units>).
- 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<suffix>" (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() {
Expand Down
25 changes: 24 additions & 1 deletion Xplat/src/main/resources/assets/patchouli/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down