use preferred language for config file retrieval
This commit is contained in:
@@ -1530,6 +1530,9 @@ void BusHandler::formatUpdateInfo(ostringstream* output) const {
|
||||
}
|
||||
*output << "],\"gu\":" << unknownCnt;
|
||||
}
|
||||
if (!m_messages->getPreferLanguage().empty()) {
|
||||
*output << ",\"lc\":\"" << m_messages->getPreferLanguage() << "\"";
|
||||
}
|
||||
unsigned char address = 0;
|
||||
for (int index = 0; index < 256; index++, address++) {
|
||||
bool ownAddress = !m_device->isReadOnly() && (address == m_ownMasterAddress || address == m_ownSlaveAddress);
|
||||
|
||||
+13
-3
@@ -151,6 +151,9 @@ static string s_configLocalPrefix = "";
|
||||
/** the URI prefix (including trailing "/") for retrieving configuration files from HTTPS (empty for local files). */
|
||||
static string s_configUriPrefix = "";
|
||||
|
||||
/** the optional language query part for retrieving configuration files from HTTPS (empty for local files). */
|
||||
static string s_configLangQuery = "";
|
||||
|
||||
/** the @a HttpClient for retrieving configuration files from HTTPS. */
|
||||
static HttpClient* s_configHttpClient = nullptr;
|
||||
|
||||
@@ -858,7 +861,8 @@ static result_t collectConfigFiles(const string& relPath, const string& prefix,
|
||||
vector<string>* dirs = nullptr, bool* hasTemplates = nullptr) {
|
||||
const string relPathWithSlash = relPath.empty() ? "" : relPath + "/";
|
||||
if (!s_configUriPrefix.empty()) {
|
||||
string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query;
|
||||
string uri = s_configUriPrefix + relPathWithSlash + s_configLangQuery + (s_configLangQuery.empty() ? "?" : "&")
|
||||
+ "t=" + extension.substr(1) + query;
|
||||
string names;
|
||||
if (!lazyHttpClient() || !s_configHttpClient->get(uri, "", &names)) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
@@ -1074,7 +1078,7 @@ result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filenam
|
||||
stream = FileReader::openFile(s_configLocalPrefix + filename, errorDescription, &mtime);
|
||||
} else {
|
||||
string content;
|
||||
if (lazyHttpClient() && s_configHttpClient->get(s_configUriPrefix + filename, "", &content, &mtime)) {
|
||||
if (lazyHttpClient() && s_configHttpClient->get(s_configUriPrefix + filename + s_configLangQuery, "", &content, &mtime)) {
|
||||
stream = new istringstream(content);
|
||||
}
|
||||
}
|
||||
@@ -1423,6 +1427,12 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
s_configHttpClient->disconnect();
|
||||
}
|
||||
const string lang = MappedFileReader::normalizeLanguage(
|
||||
s_opt.preferLanguage==nullptr || !s_opt.preferLanguage[0] ? "" : s_opt.preferLanguage
|
||||
);
|
||||
if (!lang.empty()) {
|
||||
s_configLangQuery = "?l=" + lang;
|
||||
}
|
||||
if (!s_opt.readOnly && s_opt.scanConfig && s_opt.initialScan == 0) {
|
||||
s_opt.initialScan = BROADCAST;
|
||||
}
|
||||
@@ -1431,7 +1441,7 @@ int main(int argc, char* argv[]) {
|
||||
setFacilitiesLogLevel(s_opt.logAreas, s_opt.logLevel);
|
||||
}
|
||||
|
||||
s_messageMap = new MessageMap(s_opt.checkConfig);
|
||||
s_messageMap = new MessageMap(s_opt.checkConfig, lang);
|
||||
if (s_opt.checkConfig) {
|
||||
logNotice(lf_main, PACKAGE_STRING "." REVISION " performing configuration check...");
|
||||
|
||||
|
||||
@@ -222,6 +222,11 @@ class MappedFileReader : public FileReader {
|
||||
*/
|
||||
static const string normalizeLanguage(const string& lang);
|
||||
|
||||
/**
|
||||
* @return the preferred language code (up to 2 characters), or empty.
|
||||
*/
|
||||
const string getPreferLanguage() const { return m_preferLanguage; }
|
||||
|
||||
// @copydoc
|
||||
result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose,
|
||||
map<string, string>* defaults, string* errorDescription, bool replace = false, size_t* hash = nullptr,
|
||||
|
||||
@@ -1267,7 +1267,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param deleteData whether to delete the scan message @a DataField during @a Message destruction.
|
||||
*/
|
||||
explicit MessageMap(bool addAll = false, const string& preferLanguage = "", bool deleteData = true)
|
||||
: MappedFileReader::MappedFileReader(true),
|
||||
: MappedFileReader::MappedFileReader(true, preferLanguage),
|
||||
m_addAll(addAll), m_additionalScanMessages(false), m_maxIdLength(0), m_maxBroadcastIdLength(0),
|
||||
m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) {
|
||||
m_scanMessage = Message::createScanMessage(false, deleteData);
|
||||
|
||||
Reference in New Issue
Block a user