Created
May 12, 2021 03:42
-
-
Save matarillo/590de6826ff9df03f6465d0cc9f2f268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length == 0) | |
{ | |
return; | |
} | |
var source = args[0]; | |
var mds = Directory.GetFiles(source, "*.md", SearchOption.AllDirectories); | |
var dict = new Dictionary<string, int>(); | |
foreach (var md in mds) | |
{ | |
var type = FindTranslationType(md); | |
int count; | |
if (!dict.TryGetValue(type, out count)) | |
{ | |
count = 0; | |
} | |
dict[type] = ++count; | |
} | |
foreach (var pair in dict) | |
{ | |
Console.WriteLine($"type={pair.Key}, count={pair.Value}"); | |
} | |
} | |
static string FindTranslationType(string md) | |
{ | |
const string translationHeader = "ms.translationtype: "; | |
using (var reader = File.OpenText(md)) | |
{ | |
string line; | |
while ((line = reader.ReadLine()) != null) | |
{ | |
if (line.StartsWith(translationHeader)) | |
{ | |
return line.Substring(translationHeader.Length); | |
} | |
} | |
} | |
Console.WriteLine(md); | |
return "N/A"; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment