forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
75 lines (69 loc) · 3.08 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ResourceManager.Translation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace TranslationApp
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// required for translation
GitUI.PluginLoader.Load();
string[] args = Environment.GetCommandLineArgs();
if (args.Length == 1)
Application.Run(new FormTranslate());
else if (args.Length == 2 && args[1] == "update")
{
UpdateAllTranslations();
}
else if (args.Length == 2 && args[1] == "status")
ShowStatus();
}
private static void UpdateAllTranslations()
{
Cursor.Current = Cursors.WaitCursor;
var neutralItems = TranslationHelpers.LoadNeutralItems();
var translationsNames = Translator.GetAllTranslations();
foreach (var name in translationsNames)
{
Translation translation = Translator.GetTranslation(name);
List<TranslationItemWithCategory> translateItems = TranslationHelpers.LoadTranslation(translation, neutralItems);
string filename = Path.Combine(Translator.GetTranslationDir(), name + ".xml");
TranslationHelpers.SaveTranslation(translation.LanguageCode, translateItems, filename);
}
Cursor.Current = Cursors.Default;
}
private static void ShowStatus()
{
Cursor.Current = Cursors.WaitCursor;
var neutralItems = TranslationHelpers.LoadNeutralItems();
var translationsNames = Translator.GetAllTranslations();
var list = new List<KeyValuePair<string, int>>();
foreach (var name in translationsNames)
{
Translation translation = Translator.GetTranslation(name);
List<TranslationItemWithCategory> translateItems = TranslationHelpers.LoadTranslation(translation, neutralItems);
int translatedCount = translateItems.Count(translateItem => translateItem.Status != TranslationType.Obsolete &&
!string.IsNullOrEmpty(translateItem.TranslatedValue));
list.Add(new KeyValuePair<string, int>(name, translatedCount));
}
using (var stream = File.CreateText("statistic.csv"))
{
stream.WriteLine(string.Format("{0};{1};{2};{3}", "Language", "Percent", "TranslatedItems", "TotalItems"));
foreach (var item in list.OrderByDescending(item => item.Value))
stream.WriteLine(string.Format("{0};{1:F}%;{2};{3}", item.Key,
100.0f * item.Value / neutralItems.Count, item.Value, neutralItems.Count));
}
Cursor.Current = Cursors.Default;
}
}
}