cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
langselect.h
1/*
2 * SPDX-FileCopyrightText: (C) 2018-2022 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef C_UTILS_LANGSELECT_H
7#define C_UTILS_LANGSELECT_H
8
9#include <Cutelyst/cutelyst_global.h>
10#include <Cutelyst/plugin.h>
11
12#include <QLocale>
13#include <QVector>
14
15namespace Cutelyst {
16
17class Context;
18class LangSelectPrivate;
19
348class CUTELYST_PLUGIN_UTILS_LANGSELECT_EXPORT LangSelect
349 : public Plugin // clazy:exclude=ctor-missing-parent-argument
350{
351 Q_OBJECT
352 Q_DECLARE_PRIVATE(LangSelect) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
353 Q_DISABLE_COPY(LangSelect)
354public:
358 enum Source : quint8 {
359 URLQuery = 0,
361 Session = 1,
363 Cookie =
364 2,
365 SubDomain = 3,
367 Domain =
368 4,
369 AcceptHeader =
370 254,
371 Fallback = 255
372 };
373 Q_ENUM(Source)
374
375
385 LangSelect(Application *parent, Source source);
386
393 LangSelect(Application *parent);
394
398 ~LangSelect() override;
399
407 void setSupportedLocales(const QVector<QLocale> &locales);
408
415 void setSupportedLocales(const QStringList &locales);
416
421 void addSupportedLocale(const QLocale &locale);
422
428 void addSupportedLocale(const QString &locale);
429
456 void setLocalesFromDir(const QString &path,
457 const QString &name,
458 const QString &prefix = QStringLiteral("."),
459 const QString &suffix = QStringLiteral(".qm"));
460
485 void setLocalesFromDirs(const QString &path, const QString &name);
486
492 [[nodiscard]] QVector<QLocale> supportedLocales() const;
493
497 void setQueryKey(const QString &key);
498
502 void setSessionKey(const QString &key);
503
507 void setCookieName(const QByteArray &name);
508
514 void setSubDomainMap(const QMap<QString, QLocale> &map);
515
521 void setDomainMap(const QMap<QString, QLocale> &map);
522
526 void setFallbackLocale(const QLocale &fallback);
527
533 void setDetectFromHeader(bool enabled);
534
538 void setLanguageCodeStashKey(const QString &key = QStringLiteral("c_langselect_lang"));
539
544 void setLanguageDirStashKey(const QString &key = QStringLiteral("c_langselect_dir"));
545
550 static QVector<QLocale> getSupportedLocales();
551
572 static bool fromUrlQuery(Context *c, const QString &key = QString());
573
591 static bool fromSession(Context *c, const QString &key = QString());
592
610 static bool fromCookie(Context *c, const QByteArray &name = {});
611
628 static bool
629 fromSubDomain(Context *c,
630 const QMap<QString, QLocale> &subDomainMap = QMap<QString, QLocale>());
631
647 static bool fromDomain(Context *c,
649
665 static bool fromPath(Context *c, const QString &locale);
666
667protected:
674 bool setup(Application *app) override;
675
676private:
677 const std::unique_ptr<LangSelectPrivate> d_ptr;
678};
679
680} // namespace Cutelyst
681
682#endif // C_UTILS_LANGSELECT_H
The Cutelyst application.
Definition application.h:66
The Cutelyst Context.
Definition context.h:42
Detect and select locale based on different input parameters.
Definition langselect.h:350
~LangSelect() override
Base class for Cutelyst Plugins.
Definition plugin.h:25
Plugin providing methods for session management.
Definition session.h:161
The Cutelyst namespace holds all public Cutelyst API.