source: josm/trunk/scripts/I18nSimilarStrings.java@ 15383

Last change on this file since 15383 was 14637, checked in by simon04, 6 years ago

Run Checkstyle on scripts/ and apply fixes

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.List;
6
7import org.openstreetmap.josm.data.Preferences;
8import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
9import org.openstreetmap.josm.data.preferences.JosmUrls;
10import org.openstreetmap.josm.gui.MainApplicationTest;
11import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
12import org.openstreetmap.josm.spi.preferences.Config;
13import org.openstreetmap.josm.tools.I18n;
14import org.openstreetmap.josm.tools.Utils;
15
16// License: GPL. For details, see LICENSE file.
17
18/**
19 * Finds similar strings in lang files to find potential duplicates in order to reduce translation workload.
20 */
21public final class I18nSimilarStrings {
22
23 private I18nSimilarStrings() {
24 }
25
26 /**
27 * Main.
28 * @param args not used
29 */
30 public static void main(String[] args) {
31 I18n.init();
32 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
33 Config.setUrlsProvider(JosmUrls.getInstance());
34 Preferences pref = new Preferences();
35 Config.setPreferencesInstance(pref);
36 pref.init(false);
37 MainApplicationTest.initContentPane();
38 MainApplicationTest.initToolbar();
39 MainApplicationTest.initMainMenu();
40 PluginHandlerTestIT.loadAllPlugins();
41 List<String> strings = new ArrayList<>();
42 strings.addAll(I18n.getSingularTranslations().keySet());
43 strings.addAll(I18n.getPluralTranslations().keySet());
44 System.out.println("Loaded " + strings.size() + " strings");
45 strings.removeIf(s -> s.length() <= 5);
46 System.out.println("Kept " + strings.size() + " strings longer than 5 characters");
47 Collections.sort(strings);
48 for (int i = 0; i < strings.size(); i++) {
49 for (int j = i+1; j < strings.size(); j++) {
50 String a = strings.get(i);
51 String b = strings.get(j);
52 int d = Utils.getLevenshteinDistance(a, b);
53 if (d <= 2) {
54 System.err.println(": " + a + " <--> " + b);
55 }
56 }
57 }
58 System.out.println("Done!");
59 }
60}
Note: See TracBrowser for help on using the repository browser.