Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Program.cs « StripMnemonics « po « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ed5fe115af0fb33ff210c915581b4be4ecfdabd5 (plain)
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
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace StripMnemonics
{
	class MainClass
	{
		static string[] langs = {
			"ja",
			"ko",
			"zh_CN",
			"zh_TW",
		};

		static Regex reg = new Regex(@"\(_\w\)$", RegexOptions.Compiled);

		static string StripMnemonics(string text)
		{
			if (reg.IsMatch(text)) {
				return text.Substring(0, text.Length - 4);
			}
			return text;
		}

		static void PostProcess(string file)
		{
			var poFile = POProcessor.Read(file);

			foreach (var block in poFile.Messages) {
				if (block.IdPlural == null) {
					block.TranslatedString = StripMnemonics(block.TranslatedString);
				} else {
					for (int i = 0; i < poFile.NPlurals; ++i)
						block.SetTranslatedPlural(i, StripMnemonics(block.GetTranslatedPlural(i)));
				}
			}

			POProcessor.Write(poFile, file);
		}

		public static void Main(string[] args)
		{
			if (args.Length != 1) {
				Console.WriteLine("Usage: StripMnemonics.exe <po_dir>");
				return;
			}

			foreach (var lang in langs)
				PostProcess(Path.Combine (args[0], lang + ".po"));
		}
	}
}