1 | import java.util.ArrayList;
|
---|
2 | import java.util.Collections;
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import org.openstreetmap.josm.Main;
|
---|
6 | import org.openstreetmap.josm.data.Preferences;
|
---|
7 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
8 | import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
|
---|
9 | import org.openstreetmap.josm.data.validation.tests.SimilarNamedWays;
|
---|
10 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
11 | import org.openstreetmap.josm.gui.MainApplicationTest;
|
---|
12 | import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
|
---|
13 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
14 | import org.openstreetmap.josm.tools.I18n;
|
---|
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 | */
|
---|
21 | public final class I18nSimilarStrings {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Main.
|
---|
25 | * @param args not used
|
---|
26 | */
|
---|
27 | public static void main(String[] args) {
|
---|
28 | I18n.init();
|
---|
29 | Main.determinePlatformHook();
|
---|
30 | Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
|
---|
31 | Preferences pref = new Preferences();
|
---|
32 | Config.setPreferencesInstance(pref);
|
---|
33 | pref.init(false);
|
---|
34 | MainApplication.undoRedo = new UndoRedoHandler();
|
---|
35 | MainApplicationTest.initContentPane();
|
---|
36 | MainApplicationTest.initToolbar();
|
---|
37 | MainApplicationTest.initMainMenu();
|
---|
38 | PluginHandlerTestIT.loadAllPlugins();
|
---|
39 | List<String> strings = new ArrayList<>();
|
---|
40 | strings.addAll(I18n.getSingularTranslations().keySet());
|
---|
41 | strings.addAll(I18n.getPluralTranslations().keySet());
|
---|
42 | System.out.println("Loaded " + strings.size() + " strings");
|
---|
43 | strings.removeIf(s -> s.length() <= 5);
|
---|
44 | System.out.println("Kept " + strings.size() + " strings longer than 5 characters");
|
---|
45 | Collections.sort(strings);
|
---|
46 | for (int i = 0; i < strings.size(); i++) {
|
---|
47 | for (int j = i+1; j < strings.size(); j++) {
|
---|
48 | String a = strings.get(i);
|
---|
49 | String b = strings.get(j);
|
---|
50 | int d = SimilarNamedWays.getLevenshteinDistance(a, b);
|
---|
51 | if (d <= 2) {
|
---|
52 | System.err.println(": " + a + " <--> " + b);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | System.out.println("Done!");
|
---|
57 | }
|
---|
58 | }
|
---|