-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Added Label3D auto localization #87599
Conversation
Thanks for the contribution! Did you test whether the changes work? I might be missing something, but the code doesn't look like it will actually do anything to enable translations. It's just the interface for it copied over from |
The code was tested and it works as it should, as far as I know.I have built it and both the matching and the ability to change language at runtime work, the label updates . Sorry but this is my first pull request ever. The code from |
Are you sure you committed all your local changes? In I would expect that it would need to be handled in |
I'm sorry, maybe I'm misunderstanding something, the code that handles the translation was copied directly from
|
Well the code in void Label::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
String new_text = atr(text);
if (new_text == xl_text) {
return; // Nothing new.
}
xl_text = new_text;
if (visible_ratio < 1) {
visible_chars = get_total_character_count() * visible_ratio;
}
dirty = true;
queue_redraw();
update_configuration_warnings();
} break; So I'm really puzzled it would work in |
Ah I see case NOTIFICATION_TRANSLATION_CHANGED: {
String new_text = tr(text);
if (new_text == xl_text) {
return; // Nothing new.
}
xl_text = new_text;
dirty_text = true;
_queue_update();
} break; So indeed what was missing was just the code to trigger this notification. Sorry for the noise :) |
Oh please don't worry it's ok, I hadn't seen it either, it just worked so i thought about pushing the repo '^^, I'm just inexperienced so I thought I had missed something |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, now I understand better why it seems to work, and my initial confusion.
The key thing which makes auto translation work is the atr()
method, which handles checking whether auto translation is enabled or not. You added the implementation in label_3d.h
, but you're not making use of it in label_3d.cpp
.
You need to change this for it to work like in label.cpp
:
diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp
index 3fb472335e..ff8bd32866 100644
--- a/scene/3d/label_3d.cpp
+++ b/scene/3d/label_3d.cpp
@@ -208,7 +208,7 @@ void Label3D::_notification(int p_what) {
viewport->disconnect("size_changed", callable_mp(this, &Label3D::_font_changed));
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- String new_text = tr(text);
+ String new_text = atr(text);
if (new_text == xl_text) {
return; // Nothing new.
}
@@ -635,8 +635,11 @@ void Label3D::_shape() {
}
void Label3D::set_text(const String &p_string) {
+ if (text == p_string) {
+ return;
+ }
text = p_string;
- xl_text = tr(p_string);
+ xl_text = atr(p_string);
dirty_text = true;
_queue_update();
}
If you test the current PR, turning off auto translation shouldn't work, it will keep translating.
Fixed the issues you pointed out and removed the unnecessary methods. Now the automatic translation indeed stops when it's disabled |
Looks good! Could you squash the commits? See PR workflow for instructions. Then from my perspective the PR looks ready. I'll still aim to actually test it tomorrow but the code makes sense to me. CC @YeldhamDev who's our auto translation expert now ;) |
Ah one more thing actually, you need to add documentation for the new property: diff --git a/doc/classes/Label3D.xml b/doc/classes/Label3D.xml
index 977fb00402..c4c9c58543 100644
--- a/doc/classes/Label3D.xml
+++ b/doc/classes/Label3D.xml
@@ -48,6 +48,10 @@
<member name="alpha_scissor_threshold" type="float" setter="set_alpha_scissor_threshold" getter="get_alpha_scissor_threshold" default="0.5">
Threshold at which the alpha scissor will discard values.
</member>
+ <member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true">
+ Toggles if any text should automatically change to its translated version depending on the current locale.
+ Also decides if the node's strings should be parsed for POT generation.
+ </member>
<member name="autowrap_mode" type="int" setter="set_autowrap_mode" getter="get_autowrap_mode" enum="TextServer.AutowrapMode" default="0">
If set to something other than [constant TextServer.AUTOWRAP_OFF], the text gets wrapped inside the node's bounding rectangle. If you resize the node, it will change its height automatically to show all the text. To see how each mode behaves, see [enum TextServer.AutowrapMode].
</member> Not sure if the part about POT generation is accurate (I copied the description from Control), Yeldham can maybe clarify. |
scene/3d/label_3d.h
Outdated
@@ -133,6 +133,9 @@ class Label3D : public GeometryInstance3D { | |||
TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT; | |||
Array st_args; | |||
|
|||
bool auto_translate = true; | |||
bool localize_numeral_system = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this one, should be removed too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean only localize_numeral_system
right? isn't auto_translate
is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes localize_numeral_system
is now unused and should be removed. The other one is needed.
This PR kinda came in a bad time right now, since I'm re-doing how auto translation works. To make matters worse, having yet another type of node requiring it makes the system even more convoluted, since both |
Of course, my perfect timing as always. Anyways, i've squashed the commits. It should be good for merging but at this point it's kinda useless i think, if there's a new system in development |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll approve from my side I think the implementation is straightforward and correct. Great work!
But before merging, let's see first how @YeldhamDev's refactor in #87530 goes, and how to include Label3D one way or another.
The same change can be done to the |
If there's more than one node that needs autotranslation maybe it's just better to wait for the general refractor, I don't think it's a good idea to have the same exact code just copied and pasted in multiple spaces |
This is great! Any idea what version we could expect to see this implemented? |
The implementation depends on #87530 (TL:DR Every Node having |
#87530 has been merged. This is the go. Time to rebase this to use the new |
You did not have to close this, but I have to assume you will open another PR from scratch, or have lost interest implementing this yourself? |
Wait, I thought there's no need for this with the new localization system? |
I believe the changes to |
A task for you @YeldhamDev ;) |
Done: #89056 |
Added support for automatic key-matched string localization directly from the inspector, like present in Label (2D)