File size: 1,254 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
[WorkbenchPluginAttribute("Check localisation in UI", "Find non localised text in UI", "ctrl+l", "", {"ResourceManager"})]
class CheckLocalisationPlugin: WorkbenchPlugin
{
	ref array<string> m_results = new array<string>;
	WBModuleDef m_module;
	
	void FindTexts(WidgetSource src)
	{
		if (src)
		{
			int idx = src.VarIndex("text");
			
			if (idx != -1)
			{
				string text;
				if (src.Get(idx, text) && !text.Contains("#"))
				{
					m_results.Insert("Text = \"" + text + "\" in Widget: " + src.GetName());
				}
			}
			
			FindTexts(src.GetChildren());
			FindTexts(src.GetSibling());
		}
	}
	
	void CheckTextIDs(string file)
	{
		m_module.SetOpenedResource(file);	
		WidgetSource cont = m_module.GetContainer();
		int lastIndex = m_results.Count();
		FindTexts(cont);
		if (lastIndex != m_results.Count())
		{
			m_results.InsertAt(file + ":", lastIndex);
			m_results.Insert("");
		}
	}
	
	override void Run()
	{
		m_module = Workbench.GetModule("ResourceManager");
		Workbench.SearchResources(".layout", CheckTextIDs);
		
		if (m_results.Count())
		{
			string res;
			foreach(string file: m_results)
			{
				res += file;
				res += "\n";
			}
		}
		else
		{
			res = "All texts are localised.";
		}

		Workbench.Dialog("Results", res);
	}
};