1 package com.calipso.reportgenerator.common; 2 3 import org.apache.commons.configuration.Configuration; 4 import org.apache.commons.configuration.PropertiesConfiguration; 5 6 import java.util.Locale ; 7 8 11 12 public class LanguageTraslator { 13 14 private static Locale locale; 15 private static ILanguageTraslator currentLanguage; 16 private static String path; 17 18 25 public static void newLocaleFrom(String language,String country, String languagePath){ 26 locale = new Locale (language,country); 27 path = languagePath; 28 } 29 30 public static Locale getLocale() { 31 return locale; 32 } 33 34 41 public static String traslate(String id) { 42 String s = ""; 43 try { 44 s = getInstance().getExceptionFromId(id); 45 } catch (Exception e) { 46 ReportManagerLogger.error("Traslate Error:"+id); 47 s = id; 48 } 49 return s; 50 } 51 52 59 private static ILanguageTraslator getInstance() { 60 Class languageTraslatorClass=null; 61 if((currentLanguage == null) && ((locale != null))){ 62 if(locale.getLanguage().toUpperCase().equals("ES")) { 63 try { 64 languageTraslatorClass = Class.forName("com.calipso.reportgenerator.common.LanguageTraslator" + locale.getLanguage().toUpperCase()); 65 }catch (Exception e){ 66 ReportManagerLogger.error("ERROR - LanguageTraslator" + locale.getLanguage().toUpperCase()); 67 languageTraslatorClass = new LanguageTraslatorES().getClass(); } 69 try { 70 currentLanguage = (ILanguageTraslator) languageTraslatorClass.newInstance(); 71 } 72 catch (Exception e) { 73 ReportManagerLogger.error("ERROR - LanguageTraslator" + locale.getLanguage().toUpperCase()); 74 currentLanguage = null; 75 } 76 } else { 77 try { 78 Configuration configuration = new PropertiesConfiguration(path +"/"+ locale.getLanguage()+".properties"); 79 currentLanguage = new LanguageTraslatorCustomizable(configuration); 80 } catch (Exception e) { 81 ReportManagerLogger.error("ERROR - LanguageTraslator" + locale.getLanguage().toUpperCase()); 82 currentLanguage = null; 83 } 84 } 85 } 86 return currentLanguage ; 87 } 88 } 89 | Popular Tags |