Skip to content

Commit

Permalink
✔ Weblate!
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Jan 28, 2024
1 parent caf755b commit 978ea09
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 117 deletions.
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ task setupFiles() {
System.out.println("Mod Menu: " + rootProject.mod_menu_version)
System.out.println("Architectury: " + rootProject.architectury_version)

download {
src "https://weblate.ziyuesinicization.site/api/components/tianjin-metro/en-us-json/file/"
dest "lang.zip"
overwrite true
retries -1
}
copy {
outputs.upToDateWhen { false }
from(zipTree("lang.zip"))
into "temp_lang"
}
copy {
outputs.upToDateWhen { false }
from "temp_lang/tianjin-metro/en-us-json/"
into "/"
}
delete("lang.zip", "temp_lang")

copy {
outputs.upToDateWhen { false }
from "checkouts/mtr-fabric.jar"
Expand Down
7 changes: 4 additions & 3 deletions common/src/main/java/ziyue/tjmetro/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public void set(Boolean value) {

protected static final Path CONFIG_FILE_PATH = Minecraft.getInstance().gameDirectory.toPath().resolve("config").resolve("tjmetro.json");
public static final List<Supplier<MutableComponent>> FOOTERS = Arrays.asList(
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.sources"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.GITHUB_REPO).applyTo(style)),
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.contributors"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.CONTRIBUTORS).applyTo(style)),
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.forum"), style -> IDrawingExtends.LINK_STYLE.apply(Reference.FORUM).applyTo(style).withColor(TextColor.fromRgb(15946322)))
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.sources"), IDrawingExtends.LINK_STYLE.apply(Reference.GITHUB_REPO)),
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.contributors"), IDrawingExtends.LINK_STYLE.apply(Reference.CONTRIBUTORS)),
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.forum"), IDrawingExtends.LINK_STYLE.apply(Reference.FORUM).withColor(TextColor.fromRgb(15946322))),
() -> IDrawingExtends.format(Text.translatable("footer.tjmetro.weblate"), IDrawingExtends.LINK_STYLE.apply(Reference.WEBLATE))
);

public static Screen getConfigScreen() {
Expand Down
22 changes: 12 additions & 10 deletions common/src/main/java/ziyue/tjmetro/IDrawingExtends.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,40 +230,42 @@ static List<Component> addHoldShiftTooltip(List<Component> list, MutableComponen
}

/**
* Formatting the component with specific styles.
* A valid format-able string should like this: {@code Hello! <1>This is an example!</>}
* A simple formatter for formatting the component with specific styles. Not compatible with tag-nesting.
* A valid format-able string should be like this: {@code Hello! <1>This is an example!</>}
*
* @author ZiYueCommentary
* @since beta-1
*/
static MutableComponent format(Component component, Style... styles) {
Style componentStyle = component.getStyle();
MutableComponent result = new TextComponent("");
String contents = component.getString();
int firstTagBegin = contents.indexOf('<');
StringBuilder contents = new StringBuilder(component.getString());
int firstTagBegin = contents.indexOf("<");
while (firstTagBegin != -1) {
if (firstTagBegin != 0) {
result.append(Text.literal(contents.substring(0, firstTagBegin)).withStyle(componentStyle));
contents = contents.substring(firstTagBegin);
contents.delete(0, firstTagBegin);
} else {
int firstTagEnd = contents.indexOf('>');
int firstTagEnd = contents.indexOf(">");
int tagId = Integer.parseInt(contents.substring(firstTagBegin + 1, firstTagEnd));
contents = contents.substring(firstTagEnd + 1);
contents.delete(0, firstTagEnd + 1);
int lastTagBegin = contents.indexOf("</>");
result.append(Text.literal(contents.substring(0, lastTagBegin)).withStyle(styles[tagId - 1]));
contents = contents.substring(lastTagBegin + 3);
contents.delete(0, lastTagBegin + 3);
}
firstTagBegin = contents.indexOf('<');
firstTagBegin = contents.indexOf("<");
}
result.append(Text.literal(contents).withStyle(componentStyle));
result.append(Text.literal(contents.toString()).withStyle(componentStyle));
return result;
}

/**
* @author ZiYueCommentary
* @see #format(Component, Style...)
* @since beta-1
* @deprecated
*/
@Deprecated
@SafeVarargs
static MutableComponent format(Component component, UnaryOperator<Style>... styles) {
List<Style> styleList = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/ziyue/tjmetro/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface Reference
String GITHUB_REPO = "https://github.com/ZiYueCommentary/Tianjin-Metro";
String CONTRIBUTORS = "https://github.com/ZiYueCommentary/Tianjin-Metro/graphs/contributors";
String FORUM = "https://forum.ziyuesinicization.site/t/tianjin-metro";
String WEBLATE = "https://weblate.ziyuesinicization.site/engage/tianjin-metro/";
}
1 change: 1 addition & 0 deletions common/src/main/resources/assets/tjmetro/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"footer.tjmetro.sources": "Wanna see source code? <1>Click here!</>",
"footer.tjmetro.contributors": "Tianjin Metro is a community work, <1>click here</> to see contributors!",
"footer.tjmetro.forum": "Would you like to visit our <1>forum</>?",
"footer.tjmetro.weblate": "<1>Get involved in Tianjin Metro!</>",

"filter.tjmetro.roadblocks": "Roadblocks",
"filter.tjmetro.building": "Buildings",
Expand Down
104 changes: 0 additions & 104 deletions common/src/main/resources/assets/tjmetro/lang/zh_cn.json

This file was deleted.

0 comments on commit 978ea09

Please sign in to comment.