Skip to content

Commit

Permalink
MessageEngine: Select a fallback when language is missing from config
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed May 6, 2024
1 parent c98b6f0 commit 2bd57b2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Engine fixes:
* Fixed behavior of target_neighbor when a Power wasn't using 'starting_pos=source'.
* Fixed Power target validity not respecting the 'movement_type' property.
* Fixed a case where tooltip graphics showed an incorrect right border when the text area was too wide.
* A fallback language is now selected when the desired language is not available in engine/languages.txt.
* Fixed infinite INCLUDE recursion in FileParser.
* Android: Fix 'Flare' directory not being automatically created.
* Android: Added a dialog to direct the player to the wiki page for installing if no game data is found.
Expand Down
14 changes: 10 additions & 4 deletions src/MenuConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,12 +1494,11 @@ void MenuConfig::refreshLanguages() {
if (infile.open("engine/languages.txt", FileParser::MOD_FILE, FileParser::ERROR_NORMAL)) {
int i = 0;
while (infile.next()) {
std::string key = infile.key;
if (key != "") {
language_ISO.push_back(key);
if (!infile.key.empty()) {
language_ISO.push_back(infile.key);
language_lstb->append(infile.val, infile.val + " [" + infile.key + "]");

if (language_ISO.back() == settings->language) {
if (infile.key == settings->language) {
language_lstb->select(i);
}

Expand All @@ -1508,6 +1507,13 @@ void MenuConfig::refreshLanguages() {
}
infile.close();
}

// no languages found; include English by default
if (language_lstb->getSize() == 0) {
language_ISO.push_back("en");
language_lstb->append("English", "English [en]");
language_lstb->select(0);
}
}

void MenuConfig::refreshFont() {
Expand Down
28 changes: 28 additions & 0 deletions src/MessageEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,46 @@ FLARE. If not, see http://www.gnu.org/licenses/
*/

#include "CommonIncludes.h"
#include "FileParser.h"
#include "GetText.h"
#include "MessageEngine.h"
#include "ModManager.h"
#include "RenderDevice.h"
#include "SharedResources.h"
#include "Settings.h"
#include "Utils.h"

#include <stdarg.h>

MessageEngine::MessageEngine() {
Utils::logInfo("MessageEngine: Using language '%s'", settings->language.c_str());

// check to see if the language setting is available in engine/languages.txt
FileParser config_file;
bool found_language = false;
std::string fallback_language = "";

if (config_file.open("engine/languages.txt", FileParser::MOD_FILE, FileParser::ERROR_NORMAL)) {
while (config_file.next()) {
if (config_file.key == settings->language) {
found_language = true;
break;
}
if (fallback_language.empty() || config_file.key == "en")
fallback_language = config_file.key;
}
config_file.close();
}

if (fallback_language.empty())
fallback_language = "en";

if (!found_language && settings->language != fallback_language) {
Utils::logError("MessageEngine: Unable to find '%s' in engine/languages.txt. Falling back to '%s'.", settings->language.c_str(), fallback_language.c_str());
settings->language = fallback_language;
}


GetText infile;

std::vector<std::string> engineFiles = mods->list("languages/engine." + settings->language + ".po", ModManager::LIST_FULL_PATHS);
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 41);
Version VersionInfo::ENGINE(1, 14, 42);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit 2bd57b2

Please sign in to comment.