mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 05:39:19 +01:00
Update locale files with utility
This commit is contained in:
parent
300c114f3e
commit
de0a5eb613
@ -28,6 +28,7 @@ import com.djrapitops.plan.settings.config.ConfigReader;
|
||||
import com.djrapitops.plan.settings.locale.LangCode;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
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.Resource;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -160,7 +161,17 @@ public class LocaleJSONResolver implements NoAuthResolver {
|
||||
|
||||
private Config loadLocale(Resource resource) throws IOException {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ public class LocaleFileWriter {
|
||||
|
||||
Config writing = new Config(file);
|
||||
locale.forEach((lang, message) -> writing.set(lang.getKey(), message.toString()));
|
||||
writing.dfs((node, result) -> node.sort());
|
||||
|
||||
new ConfigWriter(file.toPath()).write(writing);
|
||||
}
|
||||
|
@ -70,12 +70,22 @@ public class LocaleSystem implements SubSystem {
|
||||
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() {
|
||||
return Arrays.stream(getValuesArray())
|
||||
.flatMap(Arrays::stream)
|
||||
.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() {
|
||||
return Arrays.stream(getValuesArray())
|
||||
.flatMap(Arrays::stream)
|
||||
|
@ -35,6 +35,7 @@ public enum HtmlLang implements Lang {
|
||||
SIDE_GEOLOCATIONS("html.label.geolocations", "Geolocations"),
|
||||
SIDE_LINKS("html.label.links", "LINKS"),
|
||||
SIDE_PERFORMANCE("html.label.performance", "Performance"),
|
||||
SIDE_PLUGINS_OVERVIEW("html.label.pluginsOverview", "Plugins Overview"),
|
||||
QUERY_MAKE("html.label.query", "Make a query"),
|
||||
UNIT_NO_DATA("generic.noData", "No Data"), // Generic
|
||||
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user