Update locale files with utility

This commit is contained in:
Aurora Lahtela 2022-08-28 10:11:37 +03:00
parent 300c114f3e
commit de0a5eb613
20 changed files with 9517 additions and 9059 deletions

View File

@ -28,6 +28,7 @@ import com.djrapitops.plan.settings.config.ConfigReader;
import com.djrapitops.plan.settings.locale.LangCode; import com.djrapitops.plan.settings.locale.LangCode;
import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.LocaleSystem; import com.djrapitops.plan.settings.locale.LocaleSystem;
import com.djrapitops.plan.settings.locale.lang.Lang;
import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource; import com.djrapitops.plan.storage.file.Resource;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -160,7 +161,17 @@ public class LocaleJSONResolver implements NoAuthResolver {
private Config loadLocale(Resource resource) throws IOException { private Config loadLocale(Resource resource) throws IOException {
try (ConfigReader reader = new ConfigReader(resource.asInputStream())) { try (ConfigReader reader = new ConfigReader(resource.asInputStream())) {
return reader.read(); Config config = reader.read();
addMissingKeys(config);
return config;
}
}
private void addMissingKeys(Config config) {
for (Map.Entry<String, Lang> entry : LocaleSystem.getKeys().entrySet()) {
String key = entry.getKey();
if (config.contains(key)) continue;
config.set(key, locale.getString(entry.getValue()));
} }
} }

View File

@ -41,6 +41,7 @@ public class LocaleFileWriter {
Config writing = new Config(file); Config writing = new Config(file);
locale.forEach((lang, message) -> writing.set(lang.getKey(), message.toString())); locale.forEach((lang, message) -> writing.set(lang.getKey(), message.toString()));
writing.dfs((node, result) -> node.sort());
new ConfigWriter(file.toPath()).write(writing); new ConfigWriter(file.toPath()).write(writing);
} }

View File

@ -70,12 +70,22 @@ public class LocaleSystem implements SubSystem {
this.locale = new Locale(); this.locale = new Locale();
} }
/**
* Get the txt keys of all Lang entries (legacy locale files that need yml conversion).
*
* @return Map of txt key (eg {@code "HTML - LOGIN_CREATE_ACCOUNT"}) - Lang (eg. {@link HtmlLang#LOGIN_CREATE_ACCOUNT})
*/
public static Map<String, Lang> getIdentifiers() { public static Map<String, Lang> getIdentifiers() {
return Arrays.stream(getValuesArray()) return Arrays.stream(getValuesArray())
.flatMap(Arrays::stream) .flatMap(Arrays::stream)
.collect(Collectors.toMap(Lang::getIdentifier, Function.identity())); .collect(Collectors.toMap(Lang::getIdentifier, Function.identity()));
} }
/**
* Get the yml keys of all Lang entries.
*
* @return Map of yml key (eg. {@code "html.login.register"}) - Lang (eg. {@link HtmlLang#LOGIN_CREATE_ACCOUNT})
*/
public static Map<String, Lang> getKeys() { public static Map<String, Lang> getKeys() {
return Arrays.stream(getValuesArray()) return Arrays.stream(getValuesArray())
.flatMap(Arrays::stream) .flatMap(Arrays::stream)

View File

@ -35,6 +35,7 @@ public enum HtmlLang implements Lang {
SIDE_GEOLOCATIONS("html.label.geolocations", "Geolocations"), SIDE_GEOLOCATIONS("html.label.geolocations", "Geolocations"),
SIDE_LINKS("html.label.links", "LINKS"), SIDE_LINKS("html.label.links", "LINKS"),
SIDE_PERFORMANCE("html.label.performance", "Performance"), SIDE_PERFORMANCE("html.label.performance", "Performance"),
SIDE_PLUGINS_OVERVIEW("html.label.pluginsOverview", "Plugins Overview"),
QUERY_MAKE("html.label.query", "Make a query"), QUERY_MAKE("html.label.query", "Make a query"),
UNIT_NO_DATA("generic.noData", "No Data"), // Generic UNIT_NO_DATA("generic.noData", "No Data"), // Generic
GRAPH_NO_DATA("html.label.noDataToDisplay", "No Data to Display"), GRAPH_NO_DATA("html.label.noDataToDisplay", "No Data to Display"),

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package utilities;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.PluginSettings;
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
import utilities.dagger.PlanPluginComponent;
import utilities.mocks.PluginMockComponent;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
/**
* @author AuroraLS3
*/
public class LocaleResourceUpdateUtility {
public static void main(String[] args) throws Exception {
PluginMockComponent mockComponent = new PluginMockComponent(Files.createTempDirectory("temp-plan-"));
PlanPluginComponent component = mockComponent.getComponent();
PlanConfig config = component.system().getConfigSystem().getConfig();
config.set(WebserverSettings.DISABLED, true);
config.set(PluginSettings.LOCALE, "write-all");
try {
component.system().enable();
Path localeResourceDirectory = new File("").toPath().resolve("common/src/main/resources/assets/plan/locale");
for (File file : Objects.requireNonNull(component.system().getPlanFiles().getDataFolder().listFiles())) {
if (file.getName().contains("locale_") && file.getName().endsWith(".yml")) {
Path overriding = localeResourceDirectory.resolve(file.getName());
Files.move(file.toPath(), overriding, StandardCopyOption.REPLACE_EXISTING);
}
}
} finally {
component.system().disable();
}
}
}