Skip to content

Commit

Permalink
Added localization update from Github option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueyudiud committed Jan 7, 2018
1 parent 5c1c869 commit 17cf804
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ fle.group=com.ueyudiud.fle
fle.name=FarLandEra

# Version configuration.
fle.version=3.00.16-pre26
fle.version=3.00.16
2 changes: 2 additions & 0 deletions src/main/java/farcore/load/CommonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import farcore.lib.tile.instance.TECustomCarvedStone;
import farcore.lib.tile.instance.TEOre;
import farcore.lib.tile.instance.TESapling;
import nebula.common.LanguageManager;
import nebula.common.NebulaKeyHandler;
import nebula.common.NebulaWorldHandler;
import nebula.common.fluid.FluidBase;
Expand Down Expand Up @@ -200,6 +201,7 @@ public void load()
bar.step("Network Registring");
ContainerDataHandlerManager.registerSerializer(SolidStack.BS);
FarCoreIdSynchHandler.initialize();
LanguageManager.registerGitSource("fle", "ueyudiud", "FLE-Localization", "master");
pop(bar);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nebula/Nebula.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class Nebula extends DummyModContainer implements WorldAccessContainer

public static final String MODID = "nebula";
public static final String NAME = "Nebula";
public static final String VERSION = "2.3.2";
public static final String VERSION = "2.3.3";

/**
* The built-in render id, for prevent has location collide when naming
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/nebula/common/GitLocalizationEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* copyright© 2016-2018 ueyudiud
*/
package nebula.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;

import nebula.Log;

/**
* @author ueyudiud
*/
class GitLocalizationEntry implements INetworkLocalizationEntry
{
static final Gson GSON = new GsonBuilder().registerTypeAdapter(String.class, SHAAdapter.INSTANCE).create();

String key;
String path;
String branch;

GitLocalizationEntry(String key, String path, String branch)
{
this.key = key;
this.path = path;
this.branch = branch;
}

public void loadLocalization(LanguageManager manager, Map<String, String> properties,
String locale, Map<String, String> localization)
{
try
{
URL url;
url = new URL("https://api.github.com/repos/" + this.path + "/contens/lang?ref=" + this.branch);
SHAAdapter.INSTANCE.name = locale + ".lang";
String key;
try (JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"))))
{
key = GSON.fromJson(reader, String.class);
}
if (!properties.getOrDefault(this.key, "").equals(key))
{
url = new URL("https://raw.githubusercontent.com/" + this.path + "/" + this.branch + "/lang/" + locale + ".lang");
Log.info("Downloading localization file from {}", url);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")))
{
manager.read(reader, localization);
}
properties.put(locale, key);
}
}
catch (IOException exception)
{
Log.info("Failed to connect localization file '{}' from {}", locale, this.path);
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/nebula/common/INetworkLocalizationEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* copyright© 2016-2018 ueyudiud
*/
package nebula.common;

import java.util.Map;

/**
* @author ueyudiud
*/
public interface INetworkLocalizationEntry
{
void loadLocalization(LanguageManager manager, Map<String, String> properties,
String locale, Map<String, String> localization);
}
Loading

0 comments on commit 17cf804

Please sign in to comment.