-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added localization update from Github option.
- Loading branch information
Showing
8 changed files
with
312 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/main/java/nebula/common/INetworkLocalizationEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.