Okay, pretty much figured out what I actually wanted to accomplish now. To help anyone who winds up finding these posts at a future date:
EditorTranslationParserPlugin seems to only be for generating translation templates, a simple C# stub for getting it to work requires two classes that look something like:
using Godot;
using Godot.Collections;
using System.Collections.Generic;
[Tool]
public partial class LangParser : EditorTranslationParserPlugin
{
public override Array<string[]> _ParseFile(string path)
{
string wholeFile = null;
using(FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Read))
{
wholeFile = file.GetAsText();
}
Array<string[]> ret = new Array<string[]>();
AddToDictionary(wholeFile, ref ret);
//AddToDictionary does the actual parsing of my language file,
//too long to include here but it fills ret with string arrays
//outlined as the EditorTranslationParserPlugin docs page instructs:
//[msgid, msgctxt, msgid_plural, comment, source_line]
//though typically with only the first two used
//ie: {"Button1", "First Button"}
//or: {"Button", "ボタン"}
return ret;
}
public override string[] _GetRecognizedExtensions()
{
return ["zio"]; //or whatever your file extension is
}
public static void AddToDictionary(string s, ref Array<string[]> ret)
{/* actually parse the file and fill ret */}
}
and
#if TOOLS
using Godot;
[Tool]
public partial class LanguagePlugin : EditorPlugin
{
EditorTranslationParserPlugin langParser = new LangParser();
public override void _EnterTree()
{
AddTranslationParserPlugin(langParser);
}
public override void _ExitTree()
{
RemoveTranslationParserPlugin(langParser);
}
}
#endif
What I actually wanted, to load my strings directly into the Translation server looks like this:
using Godot;
using Godot.Collections;
public partial class Main : Control
{
public override void _Ready()
{
base._Ready();
GD.Print(Tr("Button1")); //prints Button1
Translation en = new Translation();
en.Locale = "en";
string wholeFile = null;
string path = "res://Languages/en/English.zio";
//English.zio translates "Button1" as "First Button"
using(FileAccess file = FileAccess.Open(path, FileAccess.ModeFlags.Read))
{
wholeFile = file.GetAsText();
}
Array<string[]> ret = new Array<string[]>();
LangParser.AddToDictionary(wholeFile, ref ret);
//ret will now contain string arrays that match this layout:
//[msgid, msgctxt, msgid_plural, comment, source_line]
for(int iii = 0; iii < ret.Count; iii++)
{
en.AddMessage(ret[iii][0], ret[iii][1]);
}
TranslationServer.AddTranslation(en);
TranslationServer.SetLocale("en");
GD.Print(Tr("Button1")); //prints "First Button"
//And a button in the scene that had the text "Button1" will have the text "First Button"
}
}
This creates a Translation, fills it with strings from my file and tells Godot to use it. Which is what I was trying to accomplish.
I’m left with the very minor problem that my custom file types, .zio, don’t show up in Godot’s file explorer. I tried making a stub of a ResourceLoader in the hopes that it would make them show up, but that didn’t work. But I only wanted that so I could right-click on them and go “show in file explorer” or “copy path” so I can manage without it.