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