From 2c61551e5cef9c8e6f111a036832494fbeb08375 Mon Sep 17 00:00:00 2001 From: Grishka Date: Mon, 21 Nov 2022 22:04:30 +0400 Subject: [PATCH] Add a tool to generate locales_config.xml --- mastodon/src/main/res/xml/locales_config.xml | 77 ++++++++++---------- tools/GenerateLocaleConfig.java | 44 +++++++++++ 2 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 tools/GenerateLocaleConfig.java diff --git a/mastodon/src/main/res/xml/locales_config.xml b/mastodon/src/main/res/xml/locales_config.xml index 7e50a26f1..29fcaf7e1 100644 --- a/mastodon/src/main/res/xml/locales_config.xml +++ b/mastodon/src/main/res/xml/locales_config.xml @@ -1,43 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/GenerateLocaleConfig.java b/tools/GenerateLocaleConfig.java new file mode 100644 index 000000000..fc585af02 --- /dev/null +++ b/tools/GenerateLocaleConfig.java @@ -0,0 +1,44 @@ +// Run: java tools/GenerateLocaleConfig.java +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; + + +public class GenerateLocaleConfig{ + public static void main(String[] args) throws IOException{ + File dir=new File("../mastodon/src/main/res/"); + if(!dir.exists()) + dir=new File("mastodon/src/main/res"); + if(!dir.exists()) + throw new RuntimeException("Please run from project directory (can't find mastodon/src/main/res)"); + + ArrayList locales=new ArrayList<>(); + locales.add("en"); + + for(File file:dir.listFiles()){ + String name=file.getName(); + if(file.isDirectory() && name.startsWith("values-")){ + if(new File(file, "strings.xml").exists()){ + locales.add(name.substring(name.indexOf('-')+1).replace("-r", "-")); + } + } + } + + locales.sort(String::compareTo); + try(OutputStreamWriter writer=new OutputStreamWriter(new FileOutputStream(new File(dir, "xml/locales_config.xml")), StandardCharsets.UTF_8)){ + writer.write(""" + + + """); + for(String locale : locales){ + writer.write("\t\n"); + } + writer.write(""); + } + } +} \ No newline at end of file