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

Last change on this file since 13997 was 13793, checked in by Don-vip, 7 years ago

see #16288 - replace similar i18n strings (script update for plugins)

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1import java.util.ArrayList;
2import java.util.Collections;
3import java.util.List;
4
5import org.openstreetmap.josm.Main;
6import org.openstreetmap.josm.data.Preferences;
7import org.openstreetmap.josm.data.UndoRedoHandler;
8import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
9import org.openstreetmap.josm.data.validation.tests.SimilarNamedWays;
10import org.openstreetmap.josm.gui.MainApplication;
11import org.openstreetmap.josm.gui.MainApplicationTest;
12import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
13import org.openstreetmap.josm.spi.preferences.Config;
14import org.openstreetmap.josm.tools.I18n;
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 */
21public final class I18nSimilarStrings {
22
23 /**
24 * Main.
25 * @param args not used
26 */
27 public static void main(String[] args) {
28 I18n.init();
29 Main.determinePlatformHook();
30 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
31 Preferences pref = new Preferences();
32 Config.setPreferencesInstance(pref);
33 pref.init(false);
34 MainApplication.undoRedo = new UndoRedoHandler();
35 MainApplicationTest.initContentPane();
36 MainApplicationTest.initToolbar();
37 MainApplicationTest.initMainMenu();
38 PluginHandlerTestIT.loadAllPlugins();
39 List<String> strings = new ArrayList<>();
40 strings.addAll(I18n.getSingularTranslations().keySet());
41 strings.addAll(I18n.getPluralTranslations().keySet());
42 System.out.println("Loaded " + strings.size() + " strings");
43 strings.removeIf(s -> s.length() <= 5);
44 System.out.println("Kept " + strings.size() + " strings longer than 5 characters");
45 Collections.sort(strings);
46 for (int i = 0; i < strings.size(); i++) {
47 for (int j = i+1; j < strings.size(); j++) {
48 String a = strings.get(i);
49 String b = strings.get(j);
50 int d = SimilarNamedWays.getLevenshteinDistance(a, b);
51 if (d <= 2) {
52 System.err.println(": " + a + " <--> " + b);
53 }
54 }
55 }
56 System.out.println("Done!");
57 }
58}
Note: See TracBrowser for help on using the repository browser.