Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Add custom fmj field parsing #24

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a50ae42
update to work with 20w49a
gbl Dec 5, 2020
2a108c4
Merge branch 'master' into fabric_1_17
gbl Dec 5, 2020
8e3c84a
add another call for mod developers
gbl Dec 5, 2020
cc0b1f1
document having several mod translations in the same crowdin project
gbl Dec 5, 2020
3d48afa
fix header word wrap in README
gbl Dec 5, 2020
589b154
Update DownloadTask.java
Hugman76 Jun 4, 2021
3b639a7
Merge pull request #7 from Hugman76/gradle_7
gbl Jun 4, 2021
b955d26
temporary version, creates wrong dependency
gbl Jun 4, 2021
d95fdcd
update to 1.17-pre5
gbl Jun 4, 2021
b1fc62a
update to 1.17
gbl Jun 8, 2021
d98f167
better .gitignore
Sep 9, 2021
8daf49c
support for all MC languages
Sep 9, 2021
2d1e84a
Merge pull request #8 from Flourick/fabric_1_17
gbl Sep 9, 2021
05c1fdf
update to 1.18-pre1, add a lot of languages, and allow several "sourc…
gbl Nov 21, 2021
0b4c070
1.18-pre5
gbl Nov 21, 2021
19869d0
Add support for new SLF4J logger
triphora Jan 21, 2022
c7d8a42
Make the mod a 'library' in modmenu
MeeniMc Feb 9, 2022
0823ebe
Update to 1.18.2
triphora Mar 11, 2022
053b83c
update to 1.18, should have commited this long ago
gbl Mar 13, 2022
941ce7f
Merge branch 'pr12' into fabric_1_18
gbl Mar 13, 2022
0668032
1.18.2
gbl Mar 13, 2022
2f30b5f
Added Shakespearean English, Pirate Speak and Upside Down English + a…
oliviathevampire Apr 15, 2022
6cbdef0
Update CrowdinTranslate.java
oliviathevampire Apr 15, 2022
e72caf3
Merge pull request #16 from oliviathevampire/patch-1
gbl May 24, 2022
41f01f7
Update CrowdinTranslate.java
OliverDeBrisbane Oct 2, 2021
79e4482
1.19-pre2
gbl May 24, 2022
8e3a271
1.19
gbl Jun 12, 2022
c2bb9c8
22w45a
gbl Nov 12, 2022
de7ab50
1.19.3, finally commit what should have been committed half a year ago
gbl Jul 11, 2023
6cba935
Update to 1.21
Luncaaa Jun 15, 2024
4f8964d
implemented entrypoint
supersaiyansubtlety Jun 18, 2024
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
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# gradle

.gradle/
build/
out/
classes/

# eclipse

*.launch

# idea

.idea/
*.iml
*.ipr
*.iws

# vscode

.settings/
.vscode/
.vs/
bin/
.classpath
.project

# macos

*.DS_Store

# fabric

run/
remappedSrc/
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ In your build.gradle, at the very top (before `plugins`), add this:
```
buildscript {
dependencies {
classpath 'de.guntram.mcmod:crowdin-translate:1.2'
classpath 'de.guntram.mcmod:crowdin-translate:1.5+1.21'
}
repositories {
maven {
Expand All @@ -53,7 +53,7 @@ buildscript {
}
```

and somewhere later (after plugins) add:
Then, somewhere later (after plugins) add:

```
apply plugin: 'de.guntram.mcmod.crowdin-translate'
Expand Down Expand Up @@ -91,8 +91,8 @@ repositories {
}
}
dependencies {
modImplementation "de.guntram.mcmod:crowdin-translate:1.2"
include "de.guntram.mcmod:crowdin-translate:1.2"
modImplementation "de.guntram.mcmod:crowdin-translate:1.5+1.21"
include "de.guntram.mcmod:crowdin-translate:1.5+1.21"
}
```

Expand Down Expand Up @@ -126,20 +126,31 @@ This will download the translations from
`https://crowdin.com/project/projectname`
to `assets/modid/lang`.

### What if I have the translation files for several mods in the same crowdin project?

Since version 1.3, you can override the translation source name that
crowdin-translate checks for. So, if your mods are named foo, bar, and baz,
you can have one single crowdin project that has them all, and have file names
`foo.json`, `bar.json` and `thisisnotbaz.json` for your source.

### Getting started
(this needs some redoing)
- Create an account on CrowdIn (https://crowdin.com)
- Optional but recommended: apply for a open source membership so you can start multiple projects, for free
- Create a project. This will ask for a project name, and a project address.
If possible, select your address so the identifier matches your mod id
(the mod `foobar` should have `https://crowdin.com/project/foobar`).
- Switch the source language from English to English, United States. This is not
100% neccesary, but will make things easier, especially if your original json
file is named `en_us.json`.
- Add the target languages you want to use. (In a future version of CrowdinTranslate,
there will be an easy way to consistently set the languages for a collection
of mods)
- Once your project is created, upload your en_us.json. Then, do some translations,
or get people to do that for you.
Assuming your crowdin project name is `allmymods`,
adjust the above use cases like this:

* manual usage:
```
java -jar crowdintranslate-<version>.jar allmymods foo foo
java -jar crowdintranslate-<version>.jar allmymods bar bar
java -jar crowdintranslate-<version>.jar allmymods baz thisisnotbaz
```

* usage in gradle: add a 'jsonSourceName' parameter

```
crowdintranslate.jsonSourceName = 'thisisnotbaz'
```

* usage in your `ClientModInitializer`: use the 3 argument call:

```
CrowdinTranslate.downloadTranslations("allmymods", "baz", "thisisnotbaz");
```
55 changes: 27 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'fabric-loom' version '1.6.+'
id 'java-gradle-plugin'
id 'maven-publish'
}

apply plugin: 'maven'

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 21
targetCompatibility = 21

archivesBaseName = "crowdin-translate"
version = "1.3-pre1-hugman"
version = "1.5+1.21"

minecraft {
refmapName = "crowdin-translate-refmap.json";
loom {
mixin.defaultRefmapName = "crowdin-translate-refmap.json"
}

processResources {
inputs.property "version", project.version
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

// These are, actually, not even used in this project.
// They are only included to make loom happy.
// Use old versions intentionally to make this work with a broad range of MCs.
dependencies {
minecraft "com.mojang:minecraft:1.15.2"
mappings "net.fabricmc:yarn:1.15.2+build.7:v2"
modImplementation "net.fabricmc:fabric-loader:0.7.2+build.174"
minecraft "com.mojang:minecraft:1.21"
mappings "net.fabricmc:yarn:1.21+build.2"
modImplementation "net.fabricmc:fabric-loader:0.15.11"
modRuntimeOnly fabricApi.module("fabric-resource-loader-v0", "0.100.1+1.21")
}


// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
java {
withSourcesJar()
}

jar {
from "LICENSE"
from "LICENSE"
manifest {
attributes(
'Main-Class': 'de.guntram.mcmod.crowdintranslate.CrowdinTranslate'
)
}

}

gradlePlugin {
Expand All @@ -65,14 +59,19 @@ gradlePlugin {
}

group = "de.guntram.mcmod"
uploadArchives {
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenDeployer {
repository(url: "file://localhost/tmp/mymavenrepo")
maven {
url = "file://tmp/mymavenrepo"
}
}
}

task publish(dependsOn: uploadArchives, type: Exec) {
task mypublish(dependsOn: publish, type: Exec) {
commandLine "rsync", "-av", "/tmp/mymavenrepo/", "[email protected]:/var/www/html/maven/"
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx2G
action.custom-1=publish
action.custom-1.args=--configure-on-demand -w -x check publish
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pluginManagement {
gradlePluginPortal()
}
}

rootProject.name = 'crowdin-translate'
57 changes: 32 additions & 25 deletions src/main/java/de/guntram/mcmod/crowdintranslate/CTResourcePack.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package de.guntram.mcmod.crowdintranslate;

import com.mojang.logging.LogUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;

import net.minecraft.resource.*;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;

/**
* Code taken from LambdAurora, oral permission on Discord on 2020-10-04
*/

public class CTResourcePack implements ResourcePack
{
private final List<String> namespaces = new ArrayList<>();
private final List<String> namespaces = new ArrayList<>();
private static final Logger LOGGER = LogUtils.getLogger();

public CTResourcePack() {
for (String s: CrowdinTranslate.registeredMods()) {
Expand All @@ -37,40 +39,40 @@ public boolean put(String resource)
}

@Override
public InputStream openRoot(String fileName) throws IOException
public InputSupplier<InputStream> openRoot(String ... fileName)
{
File file = new File(CrowdinTranslate.getRootDir(), fileName);
return new FileInputStream(file);
File file = new File(CrowdinTranslate.getRootDir(), fileName[0]);
if (file.exists()) {
return InputSupplier.create(file.toPath());
} else {
return null;
}
}

@Override
public InputStream open(ResourceType type, Identifier id) throws IOException
public InputSupplier<InputStream> open(ResourceType type, Identifier id)
{
if (type == ResourceType.SERVER_DATA) throw new IOException("Reading server data from MCPatcherPatcher client resource pack");
return this.openRoot(type.getDirectory() + "/" + id.getNamespace() + "/" + id.getPath());
}

@Override
public Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter)
{
if (type == ResourceType.SERVER_DATA) return Collections.emptyList();
public void findResources(ResourceType type, String namespace, String prefix, ResourcePack.ResultConsumer consumer) {
String start = CrowdinTranslate.getRootDir()+"/assets/" + namespace + "/" + prefix;
String[] files = new File(start).list();
//LOGGER.info("finding resources for {} {}", namespace, prefix);
if (files == null || files.length == 0) {
return Collections.EMPTY_LIST;
//LOGGER.info("found nothing");
return;
}
List<Identifier> result = Arrays.asList(files)
//LOGGER.info("found {} files, first is {}", files.length, files[0]);
List<Identifier> resultList = Arrays.asList(files)
.stream()
.map(CTResourcePack::fromPath)
.collect(Collectors.toList());
return result;
}

@Override
public boolean contains(ResourceType type, Identifier id)
{
String path = CrowdinTranslate.getRootDir() + "/" + type.getDirectory() + "/" + id.getNamespace() + "/" + id.getPath();
return new File(path).exists();
for(Identifier result: resultList) {
//LOGGER.info("sending {} to consumer", result.toString());
consumer.accept(result, open(type, result));
}
}

@Override
Expand All @@ -86,10 +88,15 @@ public <T> T parseMetadata(ResourceMetadataReader<T> metaReader) throws IOExcept
}

@Override
public ResourcePackInfo getInfo() {
return new ResourcePackInfo("CrowdinTranslate internal Resource Pack", Text.of("CrowdinTranslate internal Resource Pack"), ResourcePackSource.BUILTIN, Optional.empty());
}

/*@Override
public String getName()
{
return "CrowdinTranslate internal Resource Pack";
}
}*/

@Override
public void close()
Expand All @@ -101,6 +108,6 @@ private static Identifier fromPath(String path)
if (path.startsWith("assets/"))
path = path.substring("assets/".length());
String[] split = path.split("/", 2);
return new Identifier(split[0], split[1]);
return Identifier.of(split[0], split[1]);
}
}
Loading