checkloctool.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. [WorkbenchPluginAttribute("Check localisation in UI", "Find non localised text in UI", "ctrl+l", "", {"ResourceManager"})]
  2. class CheckLocalisationPlugin: WorkbenchPlugin
  3. {
  4. ref array<string> m_results = new array<string>;
  5. WBModuleDef m_module;
  6. void FindTexts(WidgetSource src)
  7. {
  8. if (src)
  9. {
  10. int idx = src.VarIndex("text");
  11. if (idx != -1)
  12. {
  13. string text;
  14. if (src.Get(idx, text) && !text.Contains("#"))
  15. {
  16. m_results.Insert("Text = \"" + text + "\" in Widget: " + src.GetName());
  17. }
  18. }
  19. FindTexts(src.GetChildren());
  20. FindTexts(src.GetSibling());
  21. }
  22. }
  23. void CheckTextIDs(string file)
  24. {
  25. m_module.SetOpenedResource(file);
  26. WidgetSource cont = m_module.GetContainer();
  27. int lastIndex = m_results.Count();
  28. FindTexts(cont);
  29. if (lastIndex != m_results.Count())
  30. {
  31. m_results.InsertAt(file + ":", lastIndex);
  32. m_results.Insert("");
  33. }
  34. }
  35. override void Run()
  36. {
  37. m_module = Workbench.GetModule("ResourceManager");
  38. Workbench.SearchResources(".layout", CheckTextIDs);
  39. if (m_results.Count())
  40. {
  41. string res;
  42. foreach(string file: m_results)
  43. {
  44. res += file;
  45. res += "\n";
  46. }
  47. }
  48. else
  49. {
  50. res = "All texts are localised.";
  51. }
  52. Workbench.Dialog("Results", res);
  53. }
  54. };