Added UTF8 support for lang files (With or without BOM)

This commit is contained in:
Steven Scott 2011-09-10 17:31:33 -07:00
parent 7e3efe2924
commit 02f83cb19b
3 changed files with 16 additions and 2 deletions

2
README
View File

@ -191,6 +191,8 @@ createConflict=Gate conflicts with existing gate
============= =============
Changes Changes
============= =============
[Version 0.6.9]
- Added UTF8 support for lang files (With or without BOM)
[Version 0.6.8] [Version 0.6.8]
- Fixed unmanned carts losing velocity through gates - Fixed unmanned carts losing velocity through gates
- /sg reload now properly switches languages - /sg reload now properly switches languages

View File

@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.Set; import java.util.Set;
public class LangLoader { public class LangLoader {
private String UTF8_BOM = "\uFEFF";
// Variables // Variables
private String datFolder; private String datFolder;
private String lang; private String lang;
@ -83,10 +84,14 @@ public class LangLoader {
FileInputStream fis = null; FileInputStream fis = null;
try { try {
fis = new FileInputStream(datFolder + lang + ".txt"); fis = new FileInputStream(datFolder + lang + ".txt");
InputStreamReader isr = new InputStreamReader(fis); InputStreamReader isr = new InputStreamReader(fis, "UTF8");
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
String line = br.readLine(); String line = br.readLine();
boolean firstLine = true;
while (line != null) { while (line != null) {
// Strip UTF BOM
if (firstLine) line = removeUTF8BOM(line);
firstLine = false;
// Split at first "=" // Split at first "="
int eq = line.indexOf('='); int eq = line.indexOf('=');
if (eq == -1) { if (eq == -1) {
@ -115,4 +120,11 @@ public class LangLoader {
Stargate.debug("LangLoader::Debug", key + " => " + strList.get(key)); Stargate.debug("LangLoader::Debug", key + " => " + strList.get(key));
} }
} }
private String removeUTF8BOM(String s) {
if (s.startsWith(UTF8_BOM)) {
s = s.substring(1);
}
return s;
}
} }

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.6.7-dev version: 0.6.9
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net