source: josm/trunk/scripts/I18nSimilarStrings.java@ 14626

Last change on this file since 14626 was 14373, checked in by simon04, 6 years ago

see #15889 - deprecate SimilarNamedWays.getLevenshteinDistance

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1import java.util.ArrayList;
2import java.util.Collections;
3import java.util.List;
4
5import org.openstreetmap.josm.data.Preferences;
6import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
7import org.openstreetmap.josm.data.preferences.JosmUrls;
8import org.openstreetmap.josm.gui.MainApplicationTest;
9import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
10import org.openstreetmap.josm.spi.preferences.Config;
11import org.openstreetmap.josm.tools.I18n;
12import org.openstreetmap.josm.tools.Utils;
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 */
19public 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 = Utils.getLevenshteinDistance(a, b);
48 if (d <= 2) {
49 System.err.println(": " + a + " <--> " + b);
50 }
51 }
52 }
53 System.out.println("Done!");
54 }
55}
Note: See TracBrowser for help on using the repository browser.