-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to do localization using the tr macros? #392
Comments
In general, functions in Godot classes (or the global namespace) are available in godot-rust, too. See let obj: Gd<Node> = ...;
obj.tr("message");
obj.tr_ex("message").context("ctx").done(); However, the GDScript syntax with We could probably create a Regarding templates themselves, could you elaborate where you see Rust's role in that process? |
I'll look into it, but it's gonna be kind of a hassle because the way GDScript works (every GDScript file is a resource and hence an object) you can call However this issue was aimed at implementing the ability of Godot to generate POT templates from I'm gonna try a first pass so at least manually created PO files can be used without much hassle |
Yeah, I don't think it's gdext's task to build elaborate tooling around these workflows (or maybe I'm overestimating how complex those can get). The primary scope of the library is to provide bindings to Godot functionality, and maybe pave the way for such integrations, e.g. as editor plugins. I was simply thinking about a |
@Soremwar are you interested in adding this feature? |
So I have a basic macro_rules! tr {
($string:literal$(, $arg:expr)*$(,)?) => {
Engine::singleton().tr(format!($string, $($arg)*).into())
};
($string:literal$(, $arg:expr)*; $cxt:literal$(,)?) => {
Engine::singleton()
.tr_ex(format!($string $(, $arg)*).into())
.context(format!("{}", $cxt).into())
.done()
};
}
// no context
tr!("I am {} years old", player_age);
// with context
tr!("{} and I are very close", player_name; "friendship"); Very quick and dirty, since Wanted to be able to support custom context since my first go required the
|
@vortexofdoom That looks great! Using a singleton is definitely a good idea -- I don't even know why this is a non-static method in the first place. The Godot implementation looks as follows. The only non-static access is String Object::tr(const StringName &p_message, const StringName &p_context) const {
if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
}
if (Engine::get_singleton()->is_editor_hint()) {
return TranslationServer::get_singleton()->tool_translate(p_message, p_context);
} else {
return TranslationServer::get_singleton()->translate(p_message, p_context);
}
} There is also |
The If semicolon is a good separator, I might be able to do I feel like the |
I think tr!("{} and I are very close", player_name in "friendship"); "in" because "in the context of..."; and there is similar syntax in
Would also be good to add links to the Godot docs in the Rustdoc for these macros. |
Godot has the
tr
andtr_n
functions which allow you to generate gettext templates for the dialogues in your game. This process is handled through the Godot project settings for easy managementIs this something that GDExtension exposes so it can be implemented on the Rust side? Or should the manual approach (creating the templates yourself) be considered instead
The text was updated successfully, but these errors were encountered: