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

Last change on this file since 14273 was 14138, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.platform and related methods - new class PlatformManager

  • 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.data.validation.tests.SimilarNamedWays;
9import org.openstreetmap.josm.gui.MainApplicationTest;
10import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
11import org.openstreetmap.josm.spi.preferences.Config;
12import 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 */
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 = SimilarNamedWays.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.