File indexing completed on 2024-04-28 03:53:48
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com> 0003 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KJSONUTILS_H 0009 #define KJSONUTILS_H 0010 0011 #include "kcoreaddons_export.h" 0012 0013 #include <QJsonValue> 0014 0015 class QJsonObject; 0016 class QString; 0017 0018 namespace KJsonUtils 0019 { 0020 /** 0021 * Reads a value from @p jo but unlike QJsonObject::value() it allows different entries for each locale 0022 * This is done by appending the locale identifier in brackets to the key (e.g. "[de_DE]" or "[es]") 0023 * When looking for a key "foo" with German (Germany) locale we will first attempt to read "foo[de_DE]", 0024 * if that does not exist "foo[de]", finally falling back to "foo" if that also doesn't exist. 0025 * @return the translated value for @p key from @p jo or @p defaultValue if @p key was not found 0026 * @since 5.88 0027 */ 0028 KCOREADDONS_EXPORT QJsonValue readTranslatedValue(const QJsonObject &jo, const QString &key, const QJsonValue &defaultValue = QJsonValue()); 0029 0030 /** 0031 * @return the translated value of @p key from @p jo as a string or @p defaultValue if @p key was not found 0032 * or the value for @p key is not of type string 0033 * @see KPluginMetaData::readTranslatedValue(const QJsonObject &jo, const QString &key) 0034 * @since 5.88 0035 */ 0036 KCOREADDONS_EXPORT QString readTranslatedString(const QJsonObject &jo, const QString &key, const QString &defaultValue = QString()); 0037 } 0038 0039 #endif // KJSONUTILS_H