Skip to content

Instantly share code, notes, and snippets.

@matarillo
Created May 12, 2021 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matarillo/590de6826ff9df03f6465d0cc9f2f268 to your computer and use it in GitHub Desktop.
Save matarillo/590de6826ff9df03f6465d0cc9f2f268 to your computer and use it in GitHub Desktop.
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