[14637] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 |
|
---|
[13761] | 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Collections;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
[13793] | 7 | import org.openstreetmap.josm.data.Preferences;
|
---|
| 8 | import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
|
---|
[14119] | 9 | import org.openstreetmap.josm.data.preferences.JosmUrls;
|
---|
[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;
|
---|
[14373] | 14 | import org.openstreetmap.josm.tools.Utils;
|
---|
[13761] | 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 |
|
---|
[14637] | 23 | private I18nSimilarStrings() {
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[13761] | 26 | /**
|
---|
| 27 | * Main.
|
---|
| 28 | * @param args not used
|
---|
| 29 | */
|
---|
| 30 | public static void main(String[] args) {
|
---|
| 31 | I18n.init();
|
---|
[13793] | 32 | Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
|
---|
[14119] | 33 | Config.setUrlsProvider(JosmUrls.getInstance());
|
---|
[13793] | 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();
|
---|
[13761] | 41 | List<String> strings = new ArrayList<>();
|
---|
| 42 | strings.addAll(I18n.getSingularTranslations().keySet());
|
---|
| 43 | strings.addAll(I18n.getPluralTranslations().keySet());
|
---|
[13793] | 44 | System.out.println("Loaded " + strings.size() + " strings");
|
---|
[13761] | 45 | strings.removeIf(s -> s.length() <= 5);
|
---|
[13793] | 46 | System.out.println("Kept " + strings.size() + " strings longer than 5 characters");
|
---|
[13761] | 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);
|
---|
[14373] | 52 | int d = Utils.getLevenshteinDistance(a, b);
|
---|
[13761] | 53 | if (d <= 2) {
|
---|
| 54 | System.err.println(": " + a + " <--> " + b);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | System.out.println("Done!");
|
---|
| 59 | }
|
---|
| 60 | }
|
---|