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