Skip to content

Commit

Permalink
HTMLTemplateMultilang now also tries to use the locale helper method …
Browse files Browse the repository at this point in the history
…in WebServerRequest.
  • Loading branch information
Relintai committed Dec 10, 2024
1 parent 7e67160 commit 9ee96b2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/web/html/html_template_multilang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "html_template_multilang.h"
#include "core/object/object.h"

#include "modules/web/http/web_server_request.h"

Ref<HTMLTemplate> HTMLTemplateMultilang::get_template_for_locale(const StringName &p_locale) {
Ref<HTMLTemplate> *t = _locales.getptr(p_locale);
Ref<HTMLTemplate> ht;
Expand Down Expand Up @@ -79,10 +81,28 @@ void HTMLTemplateMultilang::set_locales(const Dictionary &p_dict) {
}

String HTMLTemplateMultilang::_render(const Ref<WebServerRequest> &p_request, const Dictionary &p_data) {
if (p_request.is_valid()) {
StringName locale = p_request->get_locale();

if (locale == StringName()) {
return HTMLTemplate::_render(p_request, p_data);
}

Ref<HTMLTemplate> *tp = _locales.getptr(locale);

if (tp) {
return (*tp)->render(p_request, p_data);
}
}

const Variant *pp = p_data.getptr("locale");
if (pp) {
StringName locale = *pp;

if (locale == StringName()) {
return HTMLTemplate::_render(p_request, p_data);
}

Ref<HTMLTemplate> *tp = _locales.getptr(locale);

if (tp) {
Expand Down

0 comments on commit 9ee96b2

Please sign in to comment.