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

Last change on this file since 19228 was 14637, checked in by simon04, 6 years ago

Run Checkstyle on scripts/ and apply fixes

  • Property svn:eol-style set to native
File size: 2.2 KB
RevLine 
[14637]1// License: GPL. For details, see LICENSE file.
2
[13761]3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.List;
6
[13793]7import org.openstreetmap.josm.data.Preferences;
8import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
[14119]9import org.openstreetmap.josm.data.preferences.JosmUrls;
[13793]10import org.openstreetmap.josm.gui.MainApplicationTest;
11import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
12import org.openstreetmap.josm.spi.preferences.Config;
[13761]13import org.openstreetmap.josm.tools.I18n;
[14373]14import 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 */
21public 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}
Note: See TracBrowser for help on using the repository browser.