parent
a3abce9814
commit
fe5367d647
@ -3,6 +3,9 @@
|
|||||||
# easy-i18n Changelog
|
# easy-i18n Changelog
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- Support for dots within key nodes in YAML files
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Key focus within tree or table view after translation change
|
- Key focus within tree or table view after translation change
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package de.marhali.easyi18n.io.yaml;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.model.Translation;
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import de.marhali.easyi18n.model.TranslationNode;
|
import de.marhali.easyi18n.model.TranslationNode;
|
||||||
|
import de.marhali.easyi18n.util.PathUtil;
|
||||||
import de.marhali.easyi18n.util.StringUtil;
|
import de.marhali.easyi18n.util.StringUtil;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
@ -23,6 +24,9 @@ public class YamlMapper {
|
|||||||
for(String key : section.getKeys()) {
|
for(String key : section.getKeys()) {
|
||||||
Object value = section.getInScope(key).get();
|
Object value = section.getInScope(key).get();
|
||||||
|
|
||||||
|
key = StringUtil.escapeControls(
|
||||||
|
key.replace(PathUtil.DELIMITER, "\\" + PathUtil.DELIMITER), true);
|
||||||
|
|
||||||
TranslationNode childNode = node.getOrCreateChildren(key);
|
TranslationNode childNode = node.getOrCreateChildren(key);
|
||||||
|
|
||||||
if(value instanceof MapSection) {
|
if(value instanceof MapSection) {
|
||||||
@ -43,7 +47,9 @@ public class YamlMapper {
|
|||||||
|
|
||||||
public static void write(String locale, Section section, TranslationNode node) {
|
public static void write(String locale, Section section, TranslationNode node) {
|
||||||
for(Map.Entry<String, TranslationNode> entry : node.getChildren().entrySet()) {
|
for(Map.Entry<String, TranslationNode> entry : node.getChildren().entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = StringEscapeUtils.unescapeJava(
|
||||||
|
entry.getKey().replace("\\" + PathUtil.DELIMITER, PathUtil.DELIMITER));
|
||||||
|
|
||||||
TranslationNode childNode = entry.getValue();
|
TranslationNode childNode = entry.getValue();
|
||||||
|
|
||||||
if(!childNode.isLeaf()) {
|
if(!childNode.isLeaf()) {
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility tool for split and merge translation key paths.
|
* Utility tool for split and merge translation key paths.
|
||||||
@ -18,7 +19,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class PathUtil {
|
public class PathUtil {
|
||||||
|
|
||||||
public static final char DELIMITER = '.';
|
public static final String DELIMITER = ".";
|
||||||
|
|
||||||
private final boolean nestKeys;
|
private final boolean nestKeys;
|
||||||
|
|
||||||
@ -32,11 +33,12 @@ public class PathUtil {
|
|||||||
|
|
||||||
public @NotNull List<String> split(@NotNull String path) {
|
public @NotNull List<String> split(@NotNull String path) {
|
||||||
// Does not contain any sections or key nesting is disabled
|
// Does not contain any sections or key nesting is disabled
|
||||||
if(!path.contains(String.valueOf(DELIMITER)) || !nestKeys) {
|
if(!path.contains(DELIMITER) || !nestKeys) {
|
||||||
return new ArrayList<>(Collections.singletonList(path));
|
return new ArrayList<>(Collections.singletonList(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<>(Arrays.asList(path.split("\\" + DELIMITER)));
|
return new ArrayList<>(Arrays.asList(
|
||||||
|
path.split("(?<!\\\\)" + Pattern.quote(DELIMITER))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String concat(@NotNull List<String> sections) {
|
public @NotNull String concat(@NotNull List<String> sections) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user