parent
a9748cdea7
commit
7559e4d1f7
@ -8,6 +8,7 @@
|
|||||||
- Support for dots within key nodes in YAML files
|
- Support for dots within key nodes in YAML files
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- Improve exception handling on IO operations
|
||||||
- Update Qodana to latest version
|
- Update Qodana to latest version
|
||||||
- Allow tool-window rendering in dumb mode
|
- Allow tool-window rendering in dumb mode
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
|||||||
import de.marhali.easyi18n.io.IOStrategy;
|
import de.marhali.easyi18n.io.IOStrategy;
|
||||||
import de.marhali.easyi18n.model.SettingsState;
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
|
import de.marhali.easyi18n.util.NotificationHelper;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -68,27 +69,28 @@ public class JsonIOStrategy implements IOStrategy {
|
|||||||
|
|
||||||
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
||||||
|
|
||||||
try {
|
for(VirtualFile file : directory.getChildren()) {
|
||||||
for(VirtualFile file : directory.getChildren()) {
|
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
||||||
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String locale = file.getNameWithoutExtension();
|
String locale = file.getNameWithoutExtension();
|
||||||
data.addLocale(locale);
|
data.addLocale(locale);
|
||||||
|
|
||||||
|
try {
|
||||||
JsonObject tree = GSON.fromJson(new InputStreamReader(file.getInputStream(), file.getCharset()),
|
JsonObject tree = GSON.fromJson(new InputStreamReader(file.getInputStream(), file.getCharset()),
|
||||||
JsonObject.class);
|
JsonObject.class);
|
||||||
|
|
||||||
JsonMapper.read(locale, tree, data.getRootNode());
|
JsonMapper.read(locale, tree, data.getRootNode());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
NotificationHelper.createIOError(file.getName(), this.getClass(), e);
|
||||||
|
result.accept(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.accept(data);
|
|
||||||
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result.accept(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.accept(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import de.marhali.easyi18n.io.IOStrategy;
|
|||||||
import de.marhali.easyi18n.model.SettingsState;
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
import de.marhali.easyi18n.model.TranslationNode;
|
import de.marhali.easyi18n.model.TranslationNode;
|
||||||
|
import de.marhali.easyi18n.util.NotificationHelper;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -82,38 +83,39 @@ public class ModularizedJsonIOStrategy implements IOStrategy {
|
|||||||
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
||||||
VirtualFile[] localeDirectories = directory.getChildren();
|
VirtualFile[] localeDirectories = directory.getChildren();
|
||||||
|
|
||||||
try {
|
for(VirtualFile localeDir : localeDirectories) {
|
||||||
for(VirtualFile localeDir : localeDirectories) {
|
String locale = localeDir.getNameWithoutExtension();
|
||||||
String locale = localeDir.getNameWithoutExtension();
|
data.addLocale(locale);
|
||||||
data.addLocale(locale);
|
|
||||||
|
|
||||||
// Read all underlying module files
|
// Read all underlying module files
|
||||||
for(VirtualFile module : localeDir.getChildren()) {
|
for(VirtualFile module : localeDir.getChildren()) {
|
||||||
if(module.isDirectory() || !isFileRelevant(state, module)) {
|
if(module.isDirectory() || !isFileRelevant(state, module)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String moduleName = module.getNameWithoutExtension();
|
String moduleName = module.getNameWithoutExtension();
|
||||||
|
|
||||||
TranslationNode moduleNode = data.getNode(moduleName) != null
|
TranslationNode moduleNode = data.getNode(moduleName) != null
|
||||||
? data.getNode(moduleName)
|
? data.getNode(moduleName)
|
||||||
: new TranslationNode(state.isSortKeys() ? new TreeMap<>() : new LinkedHashMap<>());
|
: new TranslationNode(state.isSortKeys() ? new TreeMap<>() : new LinkedHashMap<>());
|
||||||
|
|
||||||
|
try {
|
||||||
JsonObject tree = GSON.fromJson(new InputStreamReader(module.getInputStream(),
|
JsonObject tree = GSON.fromJson(new InputStreamReader(module.getInputStream(),
|
||||||
module.getCharset()), JsonObject.class);
|
module.getCharset()), JsonObject.class);
|
||||||
|
|
||||||
JsonMapper.read(locale, tree, moduleNode);
|
JsonMapper.read(locale, tree, moduleNode);
|
||||||
|
|
||||||
data.getRootNode().setChildren(moduleName, moduleNode);
|
data.getRootNode().setChildren(moduleName, moduleNode);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
NotificationHelper.createIOError(locale + " / " + moduleName, this.getClass(), e);
|
||||||
|
result.accept(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.accept(data);
|
|
||||||
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result.accept(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.accept(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
|||||||
import de.marhali.easyi18n.io.IOStrategy;
|
import de.marhali.easyi18n.io.IOStrategy;
|
||||||
import de.marhali.easyi18n.model.SettingsState;
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
|
import de.marhali.easyi18n.util.NotificationHelper;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -60,26 +61,27 @@ public class PropertiesIOStrategy implements IOStrategy {
|
|||||||
|
|
||||||
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
||||||
|
|
||||||
try {
|
for(VirtualFile file : directory.getChildren()) {
|
||||||
for(VirtualFile file : directory.getChildren()) {
|
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
||||||
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String locale = file.getNameWithoutExtension();
|
String locale = file.getNameWithoutExtension();
|
||||||
data.addLocale(locale);
|
data.addLocale(locale);
|
||||||
|
|
||||||
|
try {
|
||||||
SortableProperties properties = new SortableProperties(state.isSortKeys());
|
SortableProperties properties = new SortableProperties(state.isSortKeys());
|
||||||
properties.load(new InputStreamReader(file.getInputStream(), file.getCharset()));
|
properties.load(new InputStreamReader(file.getInputStream(), file.getCharset()));
|
||||||
PropertiesMapper.read(locale, properties, data);
|
PropertiesMapper.read(locale, properties, data);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
NotificationHelper.createIOError(file.getName(), this.getClass(), e);
|
||||||
|
result.accept(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.accept(data);
|
|
||||||
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result.accept(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.accept(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
|||||||
import de.marhali.easyi18n.io.IOStrategy;
|
import de.marhali.easyi18n.io.IOStrategy;
|
||||||
import de.marhali.easyi18n.model.SettingsState;
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
|
import de.marhali.easyi18n.util.NotificationHelper;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -67,27 +68,28 @@ public class YamlIOStrategy implements IOStrategy {
|
|||||||
|
|
||||||
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
TranslationData data = new TranslationData(state.isSortKeys(), state.isNestedKeys());
|
||||||
|
|
||||||
try {
|
for(VirtualFile file : directory.getChildren()) {
|
||||||
for(VirtualFile file : directory.getChildren()) {
|
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
||||||
if(file.isDirectory() || !isFileRelevant(state, file)) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String locale = file.getNameWithoutExtension();
|
String locale = file.getNameWithoutExtension();
|
||||||
data.addLocale(locale);
|
data.addLocale(locale);
|
||||||
|
|
||||||
|
try {
|
||||||
try(Reader reader = new InputStreamReader(file.getInputStream(), file.getCharset())) {
|
try(Reader reader = new InputStreamReader(file.getInputStream(), file.getCharset())) {
|
||||||
Section section = Section.parseToMap(reader);
|
Section section = Section.parseToMap(reader);
|
||||||
YamlMapper.read(locale, section, data.getRootNode());
|
YamlMapper.read(locale, section, data.getRootNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
NotificationHelper.createIOError(file.getName(), this.getClass(), e);
|
||||||
|
result.accept(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.accept(data);
|
|
||||||
|
|
||||||
} catch(IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result.accept(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.accept(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.marhali.easyi18n.util;
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility tool to support creating notifications with detailed information like exception traces.
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public class NotificationHelper {
|
||||||
|
public static void createIOError(String fileName, Class<?> ioStrategy, Exception ex) {
|
||||||
|
ResourceBundle bundle = ResourceBundle.getBundle("messages");
|
||||||
|
String message = MessageFormat.format(bundle.getString("error.io"), fileName, ioStrategy.getSimpleName());
|
||||||
|
Logger.getInstance(ioStrategy).error(message, ex.getCause());
|
||||||
|
}
|
||||||
|
}
|
@ -19,3 +19,4 @@ settings.preview=Preview locale
|
|||||||
settings.keys.sort=Sort translation keys alphabetically
|
settings.keys.sort=Sort translation keys alphabetically
|
||||||
settings.keys.nested=Nest translation keys if possible
|
settings.keys.nested=Nest translation keys if possible
|
||||||
settings.editor.assistance=I18n key completion, annotation and reference inside editor
|
settings.editor.assistance=I18n key completion, annotation and reference inside editor
|
||||||
|
error.io=Could not process file {0} with {1}. Unwanted files can be ignored via Translation file pattern option.
|
Loading…
x
Reference in New Issue
Block a user