private void searchZipForLanguages(File source, Side side) throws IOException { ZipFile zf = new ZipFile(source); List<String> added = Lists.newArrayList(); for (ZipEntry ze : Collections.list(zf.entries())) { Matcher matcher = assetENUSLang.matcher(ze.getName()); if (matcher.matches()) { String lang = matcher.group(2); //FMLLog.fine("Injecting found translation data for lang %s in zip file %s at %s into language system", lang, source.getName(), ze.getName()); added.add(lang); LanguageRegistry.instance().injectLanguage(lang, StringTranslate.parseLangFile(zf.getInputStream(ze))); // Ensure en_US is available to StringTranslate on the server if ("en_US".equals(lang) && side == Side.SERVER) { StringTranslate.inject(zf.getInputStream(ze)); } } } if (added.size() > 0) FMLLog.fine("Found translations in %s [%s]", source.getName(), Joiner.on(", ").join(added)); zf.close(); }
private void searchDirForLanguages(File source, String path, Side side) throws IOException { for (File file : source.listFiles()) { String currPath = path+file.getName(); if (file.isDirectory()) { searchDirForLanguages(file, currPath+'/', side); } Matcher matcher = assetENUSLang.matcher(currPath); if (matcher.matches()) { String lang = matcher.group(2); FMLLog.fine("Injecting found translation assets for lang %s at %s into language system", lang, currPath); LanguageRegistry.instance().injectLanguage(lang, StringTranslate.parseLangFile(new FileInputStream(file))); // Ensure en_US is available to StringTranslate on the server if ("en_US".equals(lang) && side == Side.SERVER) { StringTranslate.inject(new FileInputStream(file)); } } } }
private void searchZipForLanguages(File source, Side side) throws IOException { ZipFile zf = new ZipFile(source); for (ZipEntry ze : Collections.list(zf.entries())) { Matcher matcher = assetENUSLang.matcher(ze.getName()); if (matcher.matches()) { String lang = matcher.group(2); FMLLog.fine("Injecting found translation data for lang %s in zip file %s at %s into language system", lang, source.getName(), ze.getName()); LanguageRegistry.instance().injectLanguage(lang, StringTranslate.parseLangFile(zf.getInputStream(ze))); // Ensure en_US is available to StringTranslate on the server if ("en_US".equals(lang) && side == Side.SERVER) { StringTranslate.inject(zf.getInputStream(ze)); } } } zf.close(); }
public void postInit() { ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new IResourceManagerReloadListener() { private boolean ranOnce = false; public void onResourceManagerReload(IResourceManager resourcemanager) { if (!this.ranOnce) { this.ranOnce = true; return; } StructuralLevelClientData.loadBaseTextureData(); if (StructuralLevel.LEVELS != null) { for (StructuralLevel level : StructuralLevel.LEVELS) { if (level.levelNum != 0) { level.clientData.generateIcons(); StringTranslate.inject(new ByteArrayInputStream(("item.upgrade.structural." + String.valueOf(level.levelNum) + ".name=" + StatCollector.translateToLocal("item.upgrade.structural") + " " + Utils.romanNumeral(level.levelNum) + " (" + level.clientData.getMaterialName() + ")").getBytes())); } } } StructuralLevelClientData.unloadBaseTextureData(); } }); }
public static void injectLanguage(File source, Side side) { try { ZipFile zf = new ZipFile(source); for (ZipEntry ze : Collections.list(zf.entries())) { Matcher matcher = Pattern.compile("(?:.+/|)([\\w_-]+).lang").matcher(ze.getName()); if (matcher.matches()) { String lang = matcher.group(1); FMLLog.fine("Injecting found translation data for lang %s in zip file %s at %s into language system", lang, source.getName(), ze.getName()); LanguageRegistry.instance().injectLanguage(lang, StringTranslate.parseLangFile(zf.getInputStream(ze))); // Ensure en_US is available to StringTranslate on the server if ("en_US".equals(lang) && side == Side.SERVER) StringTranslate.inject(zf.getInputStream(ze)); } } zf.close(); } catch (Exception e) { Logger.logError("Could not inject language file!"); e.printStackTrace(); } }
private void searchDirForENUSLanguage(File source, String path) throws IOException { for (File file : source.listFiles()) { String currPath = path+file.getName(); if (file.isDirectory()) { searchDirForENUSLanguage(file, currPath+'/'); } Matcher matcher = assetENUSLang.matcher(currPath); if (matcher.matches()) { FMLLog.fine("Injecting found translation data at %s into language system", currPath); StringTranslate.inject(new FileInputStream(file)); } } }
public void onResourceManagerReload(IResourceManager resourceManager) { List<String> list = Lists.newArrayList(new String[] {"en_US"}); if (!"en_US".equals(this.currentLanguage)) { list.add(this.currentLanguage); } currentLocale.loadLocaleDataFiles(resourceManager, list); StringTranslate.replaceWith(currentLocale.properties); }
private static StringTranslate getFallback() throws IllegalAccessException, NoSuchFieldException { if (fallback == null) { fallback = StatCollector.class.getDeclaredField("fallbackTranslator"); fallback.setAccessible(true); } return (StringTranslate) fallback.get(null); }
public static StringTranslate getStringTranslateInstance() { try { Field field = getField(StringTranslate.class, ObfuscationConstants.STRINGTRANSLATE_INSTANCE); return (StringTranslate) field.get(null); } catch (IllegalAccessException ex) { Game.logger().error("could not get string translator"); return null; } }
public void onResourceManagerReload(IResourceManager par1ResourceManager) { ArrayList var2 = Lists.newArrayList(new String[] {"en_US"}); if (!"en_US".equals(this.currentLanguage)) { var2.add(this.currentLanguage); } currentLocale.loadLocaleDataFiles(par1ResourceManager, var2); StringTranslate.replaceWith(currentLocale.field_135032_a); }
public void initializeThread(Configuration configuration) { optout = configuration.get("optout", "localization_update", false, "Opt-out of localization updates, and only use lang files packaged with the JAR").getBoolean(false); if (!optout) { Thread thread = new Thread(new Runnable() { @Override public void run() { try { URL url = new URL(langUrl); InputStream con = url.openStream(); String data = new String(ByteStreams.toByteArray(con)); con.close(); Map<String, Object>[] json = new Gson().fromJson(data, Map[].class); for (Map<String, Object> aJson : json) { String name = ((String) aJson.get("name")); if (name.endsWith(".lang")) { LOGGER.info("Discovered remote " + name + ". Downloading..."); URL url1 = new URL(String.format(rawUrl, aJson.get("path"))); InputStream con1 = url1.openStream(); Map<String, String> map = StringTranslate.parseLangFile(con1); LocalizationUpdater.this.loadedLangFiles.put(name.substring(0, name.lastIndexOf(".lang")), map); con1.close(); } } } catch (Exception ex) { // Most likely due to the lack of an internet connection. No need to print if (ex instanceof UnknownHostException) optout = true; else LOGGER.warn("Failed to update localization!", ex); } } }); thread.start(); } }
public static void inject(HashMap<String, String> map) { try { Map<String, String> languageMap = ObfuscationReflectionHelper.getPrivateValue(StringTranslate.class, getInstance(), LANGUAGE_MAP); languageMap.putAll(map); ObfuscationReflectionHelper.setPrivateValue(StringTranslate.class, getInstance(), System.currentTimeMillis(), LAST_UPDATE); } catch (Exception ex) { ex.printStackTrace(); } }
public void initializeThread(Configuration configuration) { optout = configuration.get("optout", "localization_update", false, "Opt-out of localization updates, and only use lang files packaged with the JAR").getBoolean(false); if (!optout) { Thread thread = new Thread(new Runnable() { @Override public void run() { try { URL url = new URL(langUrl); InputStream con = url.openStream(); String data = new String(ByteStreams.toByteArray(con)); con.close(); Map<String, Object>[] json = new Gson().fromJson(data, Map[].class); for (Map<String, Object> aJson : json) { String name = ((String) aJson.get("name")); if (name.endsWith(".lang")) { LOGGER.info("Discovered " + name + ". Downloading..."); URL url1 = new URL(String.format(rawUrl, aJson.get("path"))); InputStream con1 = url1.openStream(); Map<String, String> map = StringTranslate.parseLangFile(con1); LocalizationUpdater.this.loadedLangFiles.put(name.substring(0, name.lastIndexOf(".lang")), map); con1.close(); } } } catch (Exception ex) { // Most likely due to the lack of an internet connection. No need to print if (ex instanceof UnknownHostException) optout = true; else LOGGER.warn("Failed to update localization!", ex); } } }); thread.start(); } }
public void onResourceManagerReload(IResourceManager p_110549_1_) { ArrayList arraylist = Lists.newArrayList(new String[] {"en_US"}); if (!"en_US".equals(this.currentLanguage)) { arraylist.add(this.currentLanguage); } currentLocale.loadLocaleDataFiles(p_110549_1_, arraylist); LanguageRegistry.instance().mergeLanguageTable(currentLocale.field_135032_a, this.currentLanguage); StringTranslate.replaceWith(currentLocale.field_135032_a); }
private void searchZipForENUSLanguage(File source) throws IOException { ZipFile zf = new ZipFile(source); for (ZipEntry ze : Collections.list(zf.entries())) { Matcher matcher = assetENUSLang.matcher(ze.getName()); if (matcher.matches()) { FMLLog.fine("Injecting found translation data in zip file %s at %s into language system", source.getName(), ze.getName()); StringTranslate.inject(zf.getInputStream(ze)); } } zf.close(); }
public void func_110549_a(ResourceManager p_110549_1_) { ArrayList var2 = Lists.newArrayList(new String[]{"en_US"}); if(!"en_US".equals(this.field_135048_c)) { var2.add(this.field_135048_c); } field_135049_a.func_135022_a(p_110549_1_, var2); StringTranslate.func_135063_a(field_135049_a.field_135032_a); }
public void onResourceManagerReload(ResourceManager par1ResourceManager) { ArrayList arraylist = Lists.newArrayList(new String[] {"en_US"}); if (!"en_US".equals(this.currentLanguage)) { arraylist.add(this.currentLanguage); } currentLocale.loadLocaleDataFiles(par1ResourceManager, arraylist); LanguageRegistry.instance().loadLanguageTable(currentLocale.field_135032_a, this.currentLanguage); StringTranslate.func_135063_a(currentLocale.field_135032_a); }
@Override @SideOnly(Side.CLIENT) /** * Gets the translated Label. */ public String getTranslatedTabLabel(){ return StringTranslate.getInstance().translateKey(this.getTabLabel()); }
@SuppressWarnings("unchecked") public void initGui() { super.initGui(); StringTranslate stringtranslate = StringTranslate.getInstance(); Keyboard.enableRepeatEvents(true); buttonList.clear(); buttonList.add(new GuiRenameButtons(0, width / 2 - 98, height / 4 + 80, stringtranslate.translateKey("selectWorld.renameButton"))); buttonList.add(new GuiRenameButtons(1, width / 2 + 48, height / 4 + 80, stringtranslate.translateKey("gui.cancel"))); buttonList.add(new GuiRenameButtons(2, width / 2 - 25, height / 4 + 80, stringtranslate.translateKey("Reset"))); theGuiTextField = new GuiTextFieldTransparent(fontRenderer, width / 2 - 68, height / 4 + 37, 140, 30); theGuiTextField.setFocused(true); theGuiTextField.setText(targetPacket.nickname); }
public void drawGuiContainerBackgroundLayer(float par3, int par1, int par2) { GL11.glNormal3f(0.0F, -1.0F, 0.0F); mc.renderEngine.bindTexture("/maemesoft/gui/rename.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); drawTexturedModalRect((width - xSize) / 2 - 40, height / 4, 0, 0, 256, 114); StringTranslate stringtranslate = StringTranslate.getInstance(); drawCenteredString(fontRenderer, stringtranslate.translateKey("Rename Pokemon"), width / 2, (height / 4 - 60) + 80, 0xffffff); theGuiTextField.drawTextBox(); }
private ResourceReloadListener() { Injector instance = new Injector(new Injector(StringTranslate.class) .getField(Injector.findField(StringTranslate.class, StringTranslate.class))); languageList = instance.getField(instance.findField(Map.class)); }
public void saveLanguageFile(String fileName) {// 输出语言文件 try { File testfile = new File(mc.mcDataDir, fileName + ".lang"); FileWriter fwriter = new FileWriter(testfile, true); fwriter.write("##############################################\n" + "# 感谢Markus \"Notch\" Persson开发的Minecraft #\n" + "# 感谢Forge团队 #\n" + "# 修改制作:Phany 特别鸣谢:推土君、风铃君 #\n" + "##############################################\n\n"); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(StringTranslate.class .getResourceAsStream("/assets/minecraft/lang/en_US.lang"), "UTF-8")); HashMap shieldString = new HashMap(1024); for (String s = bufferedreader.readLine(); s != null; s = bufferedreader .readLine()) { if (!s.startsWith("#")) { String[] as = s.split("="); if ((as != null) && (as.length == 2)) { shieldString.put(as[0], Integer.valueOf(1)); } } } // 屏蔽自身按钮文本 shieldString.put("textOperatorMainUI Key", Integer.valueOf(1)); Enumeration enu = properties.propertyNames(); ArrayList keyArrayList = Collections.list(enu); Collections.sort(keyArrayList); Iterator keyIterator = keyArrayList.iterator(); while (keyIterator.hasNext()) { String key = (String) keyIterator.next(); if (!shieldString.containsKey(key)) { fwriter.write(key + " = " + properties.getProperty(key) + "\n"); } } fwriter.close(); mc.ingameGUI.getChatGUI().printChatMessage( new ChatComponentText("导出" + fileName + ".lang文件成功")); } catch (Exception e) { mc.ingameGUI.getChatGUI().printChatMessage( new ChatComponentText("导出" + fileName + ".lang文件失败")); mc.ingameGUI.getChatGUI().printChatMessage( new ChatComponentText("原因" + e.getMessage())); } }
@Override public String getCurrentLanguage() { return StringTranslate.getInstance().getCurrentLanguage(); }