Initial Commit

master
Harald Wolff 2018-06-12 12:26:30 +02:00
commit 271cecff5b
9 changed files with 373 additions and 0 deletions

7
.classpath 100644
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry combineaccessrules="false" kind="src" path="/bootstrapper"/>
<classpathentry kind="output" path="bin"/>
</classpath>

56
.gitignore vendored 100644
View File

@ -0,0 +1,56 @@
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
RemoteSystemsTempFiles
.DS_Store

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.hwo.i18n</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

3
MANIFEST.MF 100644
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Sealed: true

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="bootstrapper/lib/org.hwo.i18n.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/org.hwo.i18n/org.hwo.i18n.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="false" manifestLocation="/org.hwo.i18n/MANIFEST.MF" manifestVersion="1.0" reuseManifest="true" saveManifest="true" usesManifest="true">
<sealing sealJar="true">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=org.hwo.i18n/src"/>
</selectedElements>
</jardesc>

View File

@ -0,0 +1,256 @@
package org.hwo.i18n;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import static bootstrapper.logging.LogLevel.*;
import static bootstrapper.logging.Logging.*;
public class Messages {
protected static Messages pInstance;
protected static List<Messages> instanceList;
protected static Locale activeLocale;
protected static List<ResourceBundle>
resourceBundles;
protected static List<Properties>
properties;
protected String
BUNDLE_NAME = "org.hwo.i18n.messages";
protected Class<?>
BUNDLE_CLASS = null;
private ResourceBundle defaultResourceBundle;
private ResourceBundle localeResourceBundle;
private Properties missingKeys;
private String missingKeysFileName;
protected Messages() {
BUNDLE_NAME = String.format("%s", getClass().getCanonicalName());
initialize();
}
protected Messages(String bundleName)
{
BUNDLE_NAME = bundleName;
initialize();
}
public void saveMissingStrings() {
if (missingKeys != null)
{
FileOutputStream fos;
try {
fos = new FileOutputStream(missingKeysFileName);
log("Writing missing strings to %s",missingKeysFileName);
missingKeys.storeToXML(fos, "missing translations");
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void initialize()
{
log(DEBUG,this.getClass().getName() + ": Using Locale:" + activeLocale.getCountry() + " / " + activeLocale.getLanguage());
defaultResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
localeResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME,activeLocale);
instanceList.add(this);
}
public String getMissingKeysFileName()
{
return missingKeysFileName;
}
public void setMissingKeysFileName(String fileName)
{
if (missingKeys == null){
enableMissingKeys();
}
missingKeysFileName = fileName;
try {
missingKeys.loadFromXML(new FileInputStream(fileName));
} catch (Exception e){
log(e);
}
}
public void enableMissingKeys()
{
if (missingKeys == null)
missingKeys = new Properties();
}
public static String getString(String key) {
for (ResourceBundle bundle: resourceBundles){
if (bundle.containsKey(key))
return bundle.getString(key);
}
for (Messages messages: instanceList)
{
if (messages.hasKey(key))
return messages.getInstanceString(key);
}
for (Properties p: properties){
if (p.containsKey(key))
return p.getProperty(key);
}
if (getInstance().missingKeys != null)
{
if (getInstance().missingKeys.containsKey(key))
return getInstance().missingKeys.getProperty(key);
getInstance().missingKeys.setProperty(key, key);
}
return key;
}
public boolean hasKey(String key)
{
return localeResourceBundle.containsKey(key) | defaultResourceBundle.containsKey(key);
}
protected String getInstanceString(String key) throws MissingResourceException
{
if (localeResourceBundle.containsKey(key))
return localeResourceBundle.getString(key);
if (defaultResourceBundle.containsKey(key))
return defaultResourceBundle.getString(key);
throw new MissingResourceException(BUNDLE_NAME, key, "");
}
public static Messages getInstance()
{
return pInstance;
}
private static String[] generateFileNamesForBase(Class<?> clazz,Locale locale){
if (locale == null)
locale = activeLocale;
return new String[]{
String.format("%s.msg_%s_%s", clazz.getCanonicalName(), locale.getLanguage(), locale.getCountry()),
String.format("%s.msg_%s_%s", clazz.getSimpleName(), locale.getLanguage(), locale.getCountry()),
String.format("%s.msg_%s", clazz.getCanonicalName(), locale.getLanguage()),
String.format("%s.msg_%s", clazz.getSimpleName(), locale.getLanguage()),
String.format("%s.msg", clazz.getCanonicalName()),
String.format("%s.msg", clazz.getSimpleName())
};
}
private static File[] possibleFilesFor(Class<?> clazz){
LinkedList<File> files = new LinkedList<>();
for (String fn: generateFileNamesForBase(clazz, null)){
File f = new File(fn);
if (f.exists())
files.add(f);
}
return files.toArray(new File[0]);
}
private static ResourceBundle tryLoad(InputStream is){
try {
return new PropertyResourceBundle(is);
} catch (Exception e){
log(e);
}
return null;
}
public static boolean loadMessages(Class<?> clazz){
// boolean leastOne = false;
// String[] fileNames = generateFileNamesForBase(clazz, null);
try {
ResourceBundle bundle = ResourceBundle.getBundle(clazz.getCanonicalName(),activeLocale);
if (bundle != null) {
resourceBundles.add(bundle);
log(DEBUG,"ResourceBundle found for %s",clazz.getCanonicalName());
return true;
}
} catch (RuntimeException ex) {
log(ex);
}
return false;
// for (String fn: fileNames){
// InputStream is = clazz.getClassLoader().getResourceAsStream(fn);
// if (is == null){
// if (new File(fn).exists())
// try {
// is = new FileInputStream(fn);
// } catch (FileNotFoundException e) {
// log(e);
// }
// }
// if (is != null){
// ResourceBundle rb = tryLoad(is);
// if (rb != null){
// log(INFO,"I18N: loaded %s",fn);
// resourceBundles.add(rb);
// continue;
// }
// }
//
// Properties prop = new Properties();
// try {
// String xfn = String.format("%s.xml", fn);
// prop.loadFromXML(new FileInputStream(xfn));
// properties.add(prop);
// log(INFO,"I18N: loaded %s",xfn);
// continue;
// } catch (Exception e) {
// }
//
// log(INFO,"I18N: does not exist: %s",fn);
// }
//
// return leastOne;
}
static {
resourceBundles = new ArrayList<>();
properties = new ArrayList<>();
if (activeLocale == null)
activeLocale = Locale.getDefault();
if (instanceList == null)
instanceList = new LinkedList<Messages>();
if (pInstance == null)
pInstance = new Messages();
}
}

View File

@ -0,0 +1,6 @@
org.hwo=HWOs Java Framework
interface=Schnittstelle
ok=OK
cancel=abbrechen
SerialPortChooser.0=Schnittstelle w\u00E4hlen

View File

@ -0,0 +1,6 @@
org.hwo=HWOs Java Framework
interface=Interface
ok=OK
cancel=Cancel
SerialPortChooser.0=Select Interface

View File

@ -0,0 +1,6 @@
org.hwo=HWOs Java Framework
interface=Gränssnitt
ok=OK
cancel=avbryta
SerialPortChooser.0=Välj granssnitt: