1 | // License: GPL. For details, see LICENSE file.
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.Preferences;
|
---|
8 | import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
|
---|
9 | import org.openstreetmap.josm.data.preferences.JosmUrls;
|
---|
10 | import org.openstreetmap.josm.gui.MainApplicationTest;
|
---|
11 | import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
|
---|
12 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
13 | import org.openstreetmap.josm.tools.I18n;
|
---|
14 | import 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 | */
|
---|
21 | public 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 | }
|
---|