Skip to content

Commit

Permalink
add translations
Browse files Browse the repository at this point in the history
bugfix in Translator.tr
  • Loading branch information
Marcel Hoppe committed Mar 28, 2017
1 parent 103c217 commit 0e866c2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.thm.mni.mote.mode</groupId>
<artifactId>MoDE</artifactId>
<version>0.6.7-SNAPSHOT</version>
<version>0.6.8-SNAPSHOT</version>

<packaging>jar</packaging>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/thm/mni/mote/mode/modelica/MoClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static MoClass parse(@NonNull OMCompiler omc, MoLater that) throws ParserExcepti
break;
}

if (tmp == null) throw new ParserException(tr("Error", "error.modelica.cant_parse", ci.getType()));
if (tmp == null) throw new ParserException(tr("Error", "error", "modelica.cant_parse", ci.getType()));

tmp.parseExtra(omc);
return tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public MoClass getElement() {
try {
this.element = MoClass.parse(omc, (MoLater) this.element);
} catch (ParserException e) {
MessageBus.getInstance().send(new ErrorMessage(MoContainer.class, omc.getGroup(), new ParserException(tr("Error", "error.modelica.error_in", getSimpleName()), e)));
MessageBus.getInstance().send(new ErrorMessage(MoContainer.class, omc.getGroup(), new ParserException(tr("Error", "error", "modelica.error_in", getSimpleName()), e)));
}
}
return this.element;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/de/thm/mni/mote/mode/omcactor/OMCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ void addSystemLibraries(List<String> libs) {

void clearProject() throws ParserException {
Result r = client.call("clear");
if (!Boolean.parseBoolean(r.result)) throw new ParserException(tr("Error", "error.omcactor.cant_unload_project"));
if (!Boolean.parseBoolean(r.result)) throw new ParserException(tr("Error", "error", "omcactor.cant_unload_project"));
this.getSystemLibraries().clear();
this.getProjectLibraries().clear();
project = null;
}


void setProject(Path f) throws ParserException {
if (project != null) throw new ParserException(tr("Error", "error.omcactor.project_already_set"));
if (project != null) throw new ParserException(tr("Error", "error", "omcactor.project_already_set"));
Pair<String, Path> lib = loadProject(f);
if (lib == null) throw new ParserException(tr("Error", "error.omcactor.cant_load_project", f.getFileName()));
if (lib == null) throw new ParserException(tr("Error", "error", "omcactor.cant_load_project", f.getFileName()));
this.project = lib;
}

Expand All @@ -125,7 +125,7 @@ void reloadProject() throws ParserException {
if (r.error.isPresent()) {
throw new ParserException(r.error.get());
}
throw new ParserException(tr("error", "error.omcactor.unknown_error"));
throw new ParserException(tr("Error", "error", "omcactor.unknown_error"));
}
}

Expand All @@ -137,7 +137,7 @@ private Pair<String, Path> loadProject(Path f) throws ParserException {
if (r.error.isPresent()) {
throw new ParserException(r.error.get());
}
throw new ParserException(tr("error", "error.omcactor.unknown_error"));
throw new ParserException(tr("Error", "error", "omcactor.unknown_error"));
}

r = client.call("getLoadedLibraries");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ManagedMoConnectorIconGroup(MoVariableIconGroup moParent, MoVariable vari
while (c.next()) {
c.getAddedSubList().forEach(str -> {
if (!entries.containsKey(str)) {
Label tmp = new Label(Translator.tr("Main", str));
Label tmp = new Label(Translator.tr("MoDE", "main", str));
entries.put(str, tmp);
((Pane) errorPopOver.getContentNode()).getChildren().add(tmp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private List<String> getConnectableToMessages(MoVariable from, MoVariable to) {

private List<String> getConnectableToMessages(MoVariable from, MoVariable to, boolean compare) {
if (compare) {
if (!from.getName().equals(to.getName())) return Collections.singletonList("editor.connectors.no_matching_name");
if (!from.getName().equals(to.getName())) return Collections.singletonList("editor.connectors.no_matching_name|" + from.getName());
if (from.getKind().equals(MoVariable.Specification.FLOW) && !from.getKind().equals(to.getKind())) return Collections.singletonList("editor.connectors.no_matching_modifier");
if (from.getKind().equals(MoVariable.Specification.INPUT) && !to.getKind().equals(MoVariable.Specification.OUTPUT)) return Collections.singletonList("editor.connectors.no_matching_modifier");
if (from.getKind().equals(MoVariable.Specification.OUTPUT) && !to.getKind().equals(MoVariable.Specification.INPUT)) return Collections.singletonList("editor.connectors.no_matching_modifier");
Expand Down
47 changes: 17 additions & 30 deletions src/main/java/de/thm/mni/mote/mode/util/Translator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.thm.mni.mote.mode.util;

import lombok.NonNull;

import java.text.MessageFormat;
import java.util.*;

Expand All @@ -19,47 +17,36 @@ public static ResourceBundle getBundle(String bundle) {
}

public static String tr(String bundle, String key) {
return tr(getBundle(bundle), key);
return tr(getBundle(bundle), "", key);
}

public static String tr(String bundle, String group, String key) {
if (bundle == null) bundle = "MoDE";
return tr(getBundle(bundle), group.toLowerCase() + "." + key);
}

public static String tr(@NonNull ResourceBundle bundle, String key) {
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
String[] keyWithParams = key.split("\\|");
key = keyWithParams[0];
Object[] params = new String[0];
if (keyWithParams.length > 1)
params = Arrays.copyOfRange(keyWithParams, 1, keyWithParams.length);
return tr(getBundle(bundle), group, key, params);

}


public static String tr(String bundle, String key, Object... params) {
return tr(getBundle(bundle), key, params);
public static String tr(String bundle, String group, String key, Object... params) {
return tr(getBundle(bundle), group, key, params);
}


public static String tr(ResourceBundle bundle, String key, Object... params) {
try {
return MessageFormat.format(bundle.getString(key), params);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}

public static String tr(String bundle, String key, Integer splitAt, Object... params) {
return tr(getBundle(bundle), key, splitAt, params);
return tr(bundle, "", key, params);
}

public static String tr(ResourceBundle bundle, String key, Integer splitAt, Object... params) {
public static String tr(ResourceBundle bundle, String group, String key, Object... params) {
if (!group.isEmpty()) key = group.toLowerCase() + "." + key;
try {
Object[] p1 = Arrays.copyOfRange(params, 0, splitAt);
Object[] p2 = Arrays.copyOfRange(params, splitAt, params.length);
String k1 = key.split("|")[0];
String k2 = key.split("|")[1];
return MessageFormat.format(bundle.getString(k1), p1) + "|" + MessageFormat.format(bundle.getString(k2), p2);
if (params.length == 0)
return bundle.getString(key);
else
return MessageFormat.format(bundle.getString(key), params);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/de/thm/mni/mote/mode/i18n/MoDE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ settings.logger.select_level=Loglevel:
file.all_supported=All Supported Files
file.mode_project=MoDE Project File
file.modelica=Modelica File
#main
main.editor.connectors.already_connected=Already Connected!
main.editor.connectors.no_matching_name=No Variable with name {0} found!
main.editor.connectors.no_matching_type=Type of variables {0} und {1} not matching!
main.editor.connectors.no_matching_variable_count=Count of variables not matching!
main.editor.connectors.no_matching_modifier=Variable modifier not matching!
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ settings.global.select_modelica_compiler.popover=Klicke hier um den OMC auszuwä
settings.notify.select_level=Benachrichtigungslevel:
settings.notify.select_seconds=Benachrichtigungsdauer:
settings.logger.select_level=Loglevel:
#main
main.editor.connectors.already_connected=Schon verbunden!
main.editor.connectors.no_matching_name=Keine Variable mit dem Namen {0} vorhanden!
main.editor.connectors.no_matching_type=Typen der Variablen {0} und {1} passen nicht!
main.editor.connectors.no_matching_variable_count=Anzahl der Variablen passen nicht!
main.editor.connectors.no_matching_modifier=Variablemodifizierer passen nicht!

0 comments on commit 0e866c2

Please sign in to comment.