Skip to content

Commit

Permalink
feat: return caption from specific language
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 29, 2024
1 parent c94ff31 commit 4735c79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/API/knut/rcdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Knut
||**[convertAssets](#convertAssets)**(int flags)|
|string |**[convertLanguageToCode](#convertLanguageToCode)**(string language)|
|[Widget](../knut/widget.md) |**[dialog](#dialog)**(string id, int flags, real scaleX, real scaleY)|
|string |**[dialogTitleForLanguage](#dialogTitleForLanguage)**(string language, string dialogId)|
|[Menu](../knut/menu.md) |**[menu](#menu)**(string id)|
|bool |**[mergeAllLanguages](#mergeAllLanguages)**(string language = "[default]")|
|bool |**[mergeLanguages](#mergeLanguages)**()|
Expand Down Expand Up @@ -178,6 +179,10 @@ Flags could be:
- `RcDocument.UseIdForPixmap`: use the id as a resource value for the pixmaps in labels
- `RcDocument.AllFlags`: combination of all above

#### <a name="dialogTitleForLanguage"></a>string **dialogTitleForLanguage**(string language, string dialogId)

Returns the string with `id` for the given `language`.

#### <a name="menu"></a>[Menu](../knut/menu.md) **menu**(string id)

Returns the menu for the given `id`.
Expand Down
18 changes: 18 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,24 @@ bool RcDocument::isDataValid() const
{
return m_rcFile.isValid && m_rcFile.data.contains(m_language);
}

/*!
* \qmlmethod string RcDocument::dialogTitleForLanguage(string language, string dialogId)
* Returns the string with `id` for the given `language`.
*/
QString RcDocument::dialogTitleForLanguage(const QString &language, const QString &dialogId) const
{
LOG(language, dialogId);
if (m_rcFile.isValid && m_rcFile.data.contains(language)) {
const RcCore::Data data = const_cast<RcCore::RcFile *>(&m_rcFile)->data[language];
const auto dialog = data.dialog(dialogId);
return dialog->caption;
} else {
spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION_NAME, language);
return {};
}
}

} // namespace Core

#include "moc_rcdocument.cpp"
2 changes: 2 additions & 0 deletions src/core/rcdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class RcDocument : public Document
const QString &id) const;
Q_INVOKABLE QString stringForDialog(const QString &dialogId, const QString &id) const;

Q_INVOKABLE QString dialogTitleForLanguage(const QString &language, const QString &dialogId) const;

QString language() const;
void setLanguage(const QString &language);
QStringList languages() const;
Expand Down

0 comments on commit 4735c79

Please sign in to comment.