From 86f797cdbd2701b3d20e7e7c87bc40e025d370d8 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 24 Apr 2021 10:55:53 +0300 Subject: [PATCH] Function to get html element lang value --- code/nel/include/nel/gui/html_element.h | 3 +++ code/nel/src/gui/html_element.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/code/nel/include/nel/gui/html_element.h b/code/nel/include/nel/gui/html_element.h index b7bceb4ab..22f037cd4 100644 --- a/code/nel/include/nel/gui/html_element.h +++ b/code/nel/include/nel/gui/html_element.h @@ -84,6 +84,9 @@ namespace NLGUI TStyle getPseudo(const std::string &key) const; void setPseudo(const std::string &key, const TStyle &style); + // return lang property for css :lang() pseudo class + std::string getInheritedLanguage() const; + private: // pseudo elements like ":before" and ":after" std::map _Pseudo; diff --git a/code/nel/src/gui/html_element.cpp b/code/nel/src/gui/html_element.cpp index f0b764640..8735cc56e 100644 --- a/code/nel/src/gui/html_element.cpp +++ b/code/nel/src/gui/html_element.cpp @@ -122,6 +122,21 @@ namespace NLGUI } } + // *************************************************************************** + std::string CHtmlElement::getInheritedLanguage() const + { + const CHtmlElement *node = this; + while(node) + { + if (node->hasAttribute("lang")) + return node->getAttribute("lang"); + + node = node->parent; + } + + return ""; + } + // *************************************************************************** std::string CHtmlElement::toString(bool tree, uint depth) const {