Skip to content
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

Make --doctool locale aware #55930

Merged
merged 1 commit into from
Dec 16, 2021
Merged

Conversation

timothyqiu
Copy link
Member

@timothyqiu timothyqiu commented Dec 14, 2021

This makes i18n of the online class reference easier. One can then generate RST based on the localized XML (although the generator script needs further tweaks in order to work with non-latin content).

  • Adds indent(str) to String:
    • Indents the (multiline) string with the given indentation.
    • This method is added in order to keep the translated XML correctly indented.
  • Moves the loading of tool/doc translation into editor/editor_translation.{h,cpp}.
    • This will be used from both EditorSettings and the doc tool from main.
  • Makes use of doc translation when generating XML class references, and setup the translation locale based on -l LOCALE CLI parameter.

The XML class reference won't be translated if -l LOCALE is not given, or when it's -l en. So it's backward compatible I think.

I'll backport this PR to 3.x if it is OK.

@timothyqiu
Copy link
Member Author

Updated the PR, and now it only translates the XMLs when -l LOCALE is given.

It seems that the clearing of static locale variable when exiting setup2() does not do anything expect preventing others from knowing if any thing is given as -l parameter. I removed it so that --doctool can only translate when the parameter is given.

return indent;
}

String String::indent(const String &p_indent) const {
Copy link
Member

@akien-mga akien-mga Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record we seem to have

core/io/json.h
72:     static String _make_indent(const String &p_indent, int p_size);

which could maybe be modified to use this instead if we're adding it to String.

And there's possibly more script editor code that might also reimplement indentation logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is just making the correct level of indent string instead of indenting. Can be probably replaced by p_indent.repeat(p_size) :)

@akien-mga
Copy link
Member

Looks good overall and seems to work well 👍

I'd split the XML fixes to a dedicated PR so that they can be merged now while we keep iterating on the core and translation API changes.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me for the editor/translation/main changes.

For the added String API, could use some additional review to make sure that it's a useful API to have here (and which should then likely be exposed to scripting). Otherwise it could be kept local to where it's needed since it's only needed by DocTools so far.

@timothyqiu
Copy link
Member Author

Rebased so CI won't complain about changed XMLs.

Also made get_indent() local to DocTool since it only returns the first valid indentation, which seems too limited. indent(str) is kept in String and exposed to scripting.

doc/classes/String.xml Outdated Show resolved Hide resolved
doc/classes/String.xml Outdated Show resolved Hide resolved
Comment on lines +68 to +74
static String _translate_doc_string(const String &p_text) {
const String indent = _get_indent(p_text);
const String message = p_text.dedent().strip_edges();
const String translated = TranslationServer::get_singleton()->doc_translate(message, "");
// No need to restore stripped edges because they'll be stripped again later.
return translated.indent(indent);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I feel like we could be doing a better job at handling the XML tab indentation of these strings. The only part which we need to preserve is the manual 4-space indentation in code blocks, but everything else should be something that we could simply ignore, and add manually in _write_string (as already done at least one the first line).

Currently we dedent, strip edges, indent again, strip edges again (so it removes indentation on the first line again?), and then escape. A lot of steps which could be done better IMO.

But that's not blocking for this PR.

core/string/ustring.cpp Outdated Show resolved Hide resolved
@akien-mga
Copy link
Member

I'll backport this PR to 3.x if it is OK.

This should be good to backport now 👍

* Adds `indent(str)` to `String`:
    * Indent the (multiline) string with the given indentation.
    * This method is added in order to keep the translated XML correctly
      indented.
* Moves the loading of tool/doc translation into
  `editor/editor_translation.{h,cpp}`.
    * This will be used from both `EditorSettings` and the doc tool from
      `main`.
* Makes use of doc translation when generating XML class references, and
  setup the translation locale based on `-l LOCALE` CLI parameter.

The XML class reference won't be translated if `-l LOCALE` parameter is
not given, or when it's `-l en`.
@akien-mga akien-mga merged commit 91c0529 into godotengine:master Dec 16, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants