1/*
2 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
3 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KJSONUTILS_H
9#define KJSONUTILS_H
10
11#include "kcoreaddons_export.h"
12
13#include <QJsonValue>
14
15class QJsonObject;
16class QString;
17
18namespace KJsonUtils
19{
20/*!
21 * \namespace KJsonUtils
22 * \inmodule KCoreAddons
23 *
24 * Reads a value from \a jo but unlike QJsonObject::value() it allows different entries for each locale
25 *
26 * This is done by appending the locale identifier in brackets to the key (e.g. "[de_DE]" or "[es]")
27 *
28 * When looking for a key "foo" with German (Germany) locale we will first attempt to read "foo[de_DE]",
29 * if that does not exist "foo[de]", finally falling back to "foo" if that also doesn't exist.
30 *
31 * Returns the translated value for \a key from \a jo or \a defaultValue if \a key was not found
32 * \since 5.88
33 */
34KCOREADDONS_EXPORT QJsonValue readTranslatedValue(const QJsonObject &jo, const QString &key, const QJsonValue &defaultValue = QJsonValue());
35
36/*!
37 * Returns the translated value of \a key from \a jo as a string or \a defaultValue if \a key was not found
38 * or the value for \a key is not of type string
39 *
40 * \since 5.88
41 */
42KCOREADDONS_EXPORT QString readTranslatedString(const QJsonObject &jo, const QString &key, const QString &defaultValue = QString());
43}
44
45#endif // KJSONUTILS_H
46

source code of kcoreaddons/src/lib/text/kjsonutils.h