QtWebApp
|
Loads localized versions of template files. More...
#include <templateloader.h>
Public Member Functions | |
TemplateLoader (const QSettings *settings, QObject *parent=nullptr) | |
Constructor. More... | |
virtual | ~TemplateLoader () |
Destructor. | |
Template | getTemplate (const QString templateName, const QString locales=QString()) |
Get a template for a given locale. More... | |
Protected Member Functions | |
virtual QString | tryFile (const QString localizedName) |
Try to get a file from cache or filesystem. More... | |
Protected Attributes | |
QString | templatePath |
Directory where the templates are searched. | |
QString | fileNameSuffix |
Suffix to the filenames. | |
QTextCodec * | textCodec |
Codec for decoding the files. | |
Loads localized versions of template files.
If the caller requests a file with the name "index" and the suffix is ".tpl" and the requested locale is "de_DE, de, en-US", then files are searched in the following order:
The following settings are required:
path=../templates suffix=.tpl encoding=UTF-8
The path is relative to the directory of the config file. In case of windows, if the settings are in the registry, the path is relative to the current working directory.
Definition at line 40 of file templateloader.h.
TemplateLoader::TemplateLoader | ( | const QSettings * | settings, |
QObject * | parent = nullptr |
||
) |
Constructor.
settings | configurations settings |
parent | parent object |
Definition at line 21 of file templateloader.cpp.
Template TemplateLoader::getTemplate | ( | const QString | templateName, |
const QString | locales = QString() |
||
) |
Get a template for a given locale.
This method is thread safe.
templateName | base name of the template file, without suffix and without locale |
locales | Requested locale(s), e.g. "de_DE, en_EN". Strings in the format of the HTTP header Accept-Locale may be used. Badly formatted parts in the string are silently ignored. |
Definition at line 73 of file templateloader.cpp.
|
protectedvirtual |
Try to get a file from cache or filesystem.
localizedName | Name of the template with locale to find |
Reimplemented in stefanfrings::TemplateCache.
Definition at line 51 of file templateloader.cpp.