cutelyst  3.9.1
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 
15 namespace Cutelyst {
16 
37 class Context;
38 class LangSelectPrivate;
39 
329 class CUTELYST_PLUGIN_UTILS_LANGSELECT_EXPORT LangSelect : public Plugin
330 {
331  Q_OBJECT
332  Q_DECLARE_PRIVATE(LangSelect)
333 public:
337  enum Source : quint8 {
338  URLQuery = 0,
340  Session = 1,
343  2,
344  SubDomain = 3,
346  Domain =
347  4,
348  AcceptHeader =
349  254,
350  Fallback = 255
351  };
352  Q_ENUM(Source)
353 
354 
364  LangSelect(Application *parent, Source source);
365 
372  LangSelect(Application *parent);
373 
377  virtual ~LangSelect() override;
378 
386  void setSupportedLocales(const QVector<QLocale> &locales);
387 
394  void setSupportedLocales(const QStringList &locales);
395 
400  void addSupportedLocale(const QLocale &locale);
401 
407  void addSupportedLocale(const QString &locale);
408 
435  void setLocalesFromDir(const QString &path,
436  const QString &name,
437  const QString &prefix = QStringLiteral("."),
438  const QString &suffix = QStringLiteral(".qm"));
439 
464  void setLocalesFromDirs(const QString &path, const QString &name);
465 
471  QVector<QLocale> supportedLocales() const;
472 
476  void setQueryKey(const QString &key);
477 
481  void setSessionKey(const QString &key);
482 
486  void setCookieName(const QString &name);
487 
493  void setSubDomainMap(const QMap<QString, QLocale> &map);
494 
500  void setDomainMap(const QMap<QString, QLocale> &map);
501 
505  void setFallbackLocale(const QLocale &fallback);
506 
512  void setDetectFromHeader(bool enabled);
513 
517  void setLanguageCodeStashKey(const QString &key = QStringLiteral("c_langselect_lang"));
518 
523  void setLanguageDirStashKey(const QString &key = QStringLiteral("c_langselect_dir"));
524 
529  static QVector<QLocale> getSupportedLocales();
530 
551  static bool fromUrlQuery(Context *c, const QString &key = QString());
552 
570  static bool fromSession(Context *c, const QString &key = QString());
571 
589  static bool fromCookie(Context *c, const QString &name = QString());
590 
607  static bool
608  fromSubDomain(Context *c,
609  const QMap<QString, QLocale> &subDomainMap = QMap<QString, QLocale>());
610 
626  static bool fromDomain(Context *c,
627  const QMap<QString, QLocale> &domainMap = QMap<QString, QLocale>());
628 
644  static bool fromPath(Context *c, const QString &locale);
645 
646 protected:
653  virtual bool setup(Application *app) override;
654 
655 private:
656  LangSelectPrivate *const d_ptr;
657 };
658 
659 } // namespace Cutelyst
660 
661 #endif // C_UTILS_LANGSELECT_H
The Cutelyst Context.
Definition: context.h:38
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Language selection plugin.
Definition: langselect.h:329
The Cutelyst Application.
Definition: application.h:42
The Cutelyst Cookie.
Definition: cookie.h:28